I have a sequence of grayscale images. using python code of opencv, I made a video out of these grayscale images.
import cv2
import numpy as np
A = readimages(img_path) # A is a list of uint8 images of size similar to framesize
framesize = (480,640)
out = cv2.VideoWriter('output_video.avi',cv2.VideoWriter_fourcc('M','J','P','G'), 30.0, framesize, isColor = False)
for img in A:
out.write(cv2.flip(img,0))
out.release()
the resultant video as shown in the image below (left part) just shows a fraction of the input images along with multiple lines. any help please.
CodePudding user response:
In this case, the images dtype must uint8, before writing into video file. The new code works fine.
import cv2
import numpy as np
A = readimages(img_path) # A is a list of uint8 images of size similar to framesize
framesize = (480,640)
out = cv2.VideoWriter('output_video.avi',cv2.VideoWriter_fourcc('M','J','P','G'), 30.0, framesize, isColor = False)
for img in A:
out.write(img.astype('uint8'))
out.release()