Hi, I am new to opencv and I had the same problem. It seems like writer.write (x) requires x to be an array with RGB values, not scalars. I solved the problem by following these steps:
import cv2 import cv2.cv as cv import numpy as np writer = cv2.VideoWriter('test1.avi',cv.CV_FOURCC('P','I','M','1'),25,(640,480)) for i in range(1000): x = np.random.randint(255,size=(480,640)).astype('uint8') x = np.repeat(x,3,axis=1) x = x.reshape(480, 640, 3) writer.write(x)
I guess there are cleaner ways to do this, but I have not found them.
source share