Save grayscale video in OpenCV?

后端 未结 3 1856
梦毁少年i
梦毁少年i 2021-01-17 19:55

I am trying to save a video as .avi format but i keep getting the error \"could not demultiplex stream\". I primarily want to save grayscale videos

相关标签:
3条回答
  • 2021-01-17 20:11

    It is possible that .DIVX is looking for a 3-channel BGR image to write, but you're only providing it a single channel image, since you're trying to write a grayscale image

    Try doing this:

    frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR)

    essentially this will try to convert your greyscale image to BGR image. While your pixel values will remain gray, this will change frame to a 3-channel image

    0 讨论(0)
  • 2021-01-17 20:20

    There are 3 things to keep in mind when you are trying to write Grayscale image in video writer. 1. while reading the image,keep 0 followed by ','

    image = cv2.imread("data/PCB.jpg",0)
    

    2&3. While creating the video writer, declare shape in opposite way and keep 0 followed by ',' as we did in step 1

    fourcc = cv2.VideoWriter_fourcc(*'XVID')
    out = cv2.VideoWriter('output.avi',fourcc, 20.0, (image.shape[1],image.shape[0]),0)
    
    0 讨论(0)
  • 2021-01-17 20:26

    For Windows OS try:

    out = cv2.VideoWriter(outfilename, fourcc, fps, (width, height), 0)
    
    0 讨论(0)
提交回复
热议问题