简体   繁体   中英

Can not make a video from images using opencv

I'm facing a problem here while trying to create a video from a sequence of images. This is the code:

video_name='resultvid10.avi'
video = cv2.VideoWriter(video_name,cv2.VideoWriter_fourcc('M','J','P','G'),1,(336,256))
for i in range(0,100):
    img = cv2.imread('./Project/data/image/video10/frame'+str(i)+'.jpg')
    result = solarPanelDetection(img)
    video.write(result)
video.release()

So, the video 10 has 100 frames, I extracted those frames into a folder as you can see in the code. I passed each of every frames in this folder to a function called solarPanelDetection , and the output is another image called result , then I write this result to the output video. But I couldn't open the video, I check the size of the video and seems like video.write didn't write the result to the video.

I think it's not about the size of the frame and the video, the size of each frame and the video are the same, I did check carefully.

What is the problem? Can anyone help me please!

There are two main issues, I would like to address:

  • Issue #1: Does result variable is a color image? since you have an initialized the video variable for creating a color-video.

    • video = cv2.VideoWriter(video_name,cv2.VideoWriter_fourcc('M','J','P','G'),1,(336,256)) is same as

    • video = cv2.VideoWriter(video_name,cv2.VideoWriter_fourcc('M','J','P','G'),1,(336,256), isColor=True)

    • If the result variable is an gray image then please initialize the video variable as:

      video = cv2.VideoWriter(video_name,cv2.VideoWriter_fourcc('M','J','P','G'),1,(336,256), isColor=False)

  • Issue #2: Does result variable size == (336, 256, 3)?

    • You need to be sure: assert (result.shape[0], result.shape[1]) == (336, 256) . The statement also works, if result is gray-image.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM