Let's analyze step-by-step:
-
size = (600,650)
Does the size of the image is 600, 650
?
If I were you, I would initialize as
image = cv2.imread('1.png')
(height, width) = image.shape[:2]
size = (width, height)
or if you want the output as (600, 650)
, then resize the image:
image = cv2.imread('1.png')
image = cv2.resize(image, (600, 650))
-
fps = 2
Why? you set frame-per-second to 2, why not 10?, 15? source
-
fourcc = cv2.VideoWriter_fourcc('I', '4', '2', '0')
Why I420
? You want to create .avi
file, then set to MJPG
source
If I were you, I would initialize as:
fourcc = cv2.VideoWriter_fourcc(*'MJPG')
-
video = cv2.VideoWriter("1.avi", fourcc, fps, size)
What type of images are you working with? color, gray?. You need to initialize as a parameter in the VideoWriter
For color image:
video = cv2.VideoWriter("1.avi", fourcc, fps, size, isColor=True)
For gray images:
video = cv2.VideoWriter("1.avi", fourcc, fps, size, isColor=False)
An example code:
import cv2
img = cv2.imread("1.png")
(h, w) = img.shape[:2]
size = (w, h)
fps = 20
fourcc = cv2.VideoWriter_fourcc(*'MJPG')
video = cv2.VideoWriter("1.avi", fourcc, fps, size, isColor=True)
video.write(img)
video.release()
Also know that cv2.imread
reads the image in BGR
fashion. If you want your images as RGB
you need to convert it like:
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)