Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write_videofile writes blank black when writing grayscale #973

Closed
ROZBEH opened this issue Jun 15, 2019 · 1 comment
Closed

write_videofile writes blank black when writing grayscale #973

ROZBEH opened this issue Jun 15, 2019 · 1 comment

Comments

@ROZBEH
Copy link

ROZBEH commented Jun 15, 2019

Hi there,

I am trying to use moviepy's fl_image functionality and apply a function to each image frame and then save it back. The whole process finishes successfully but the output video is just pure black. Does anyone know why does this happen? I here post part of the code.

def processing(input_frame):
    image = input_frame
    gradx = abs_sobel_thresh(image, orient='x', sobel_kernel=ksize, thresh=(20, 100))
    grady = abs_sobel_thresh(image, orient='y', sobel_kernel=ksize, thresh=(20, 100))
    mag_binary = mag_thresh(image, sobel_kernel=ksize, mag_thresh=(30, 100))
    dir_binary = dir_threshold(image, sobel_kernel=ksize, thresh=(0.6, 1.3))
    color_binary = color_channel(image)
    combined_grad = np.zeros_like(dir_binary)
    combined_grad[((gradx == 1) & (grady == 1)) | ((mag_binary == 1) & (dir_binary == 1))] = 1
    combined_binary = np.zeros_like(dir_binary)
    combined_binary[(combined_grad == 1) | (color_binary == 1)] = 1
    combined_binaries.append(combined_binary)
    kernel = np.ones((3,3),np.uint8)
    opening = cv2.morphologyEx(combined_binary, cv2.MORPH_OPEN, kernel)
    opening = cv2.morphologyEx(opening, cv2.MORPH_CLOSE, kernel)
    return opening


write_output = 'project_video_out.mp4'
clip = VideoFileClip("project_video.mp4")
video_clip = clip.fl_image(processing)
video_clip.write_videofile(write_output)

Specifications

  • Python Version: 3.5
  • Moviepy Version: '0.2.3.2'
  • Platform Name: Mac OSX
  • Platform Version: 10.14
@ROZBEH ROZBEH closed this as completed Jun 15, 2019
@ROZBEH
Copy link
Author

ROZBEH commented Jun 15, 2019

The problem was solving by converting the image back to the Image format with the following commands.

opening = Image.fromarray(opening * 255)
opening = np.asarray(opening)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant