I am using 32-bit python with OpenCV 2.3.1. I am trying to write 2-dimensional numpy arrays to a opencv video writer. My code is similar to :
import cv2 as cv
import numpy as np
fourcc = cv.cv.CV_FOURCC('D', 'I', 'V', 'X')
writer = cv.cv.CreateVideoWriter("test.mpg", courcc, 10, (256,256))
if not writer:
print "Error"
sys.exit(1)
for ii in range(numberOfFrames):
numpy_image = GetFrame(ii) #Gets a random image
cv_image = cv.cv.CreateImage((256,256), cv.IPL_DEPTH_8U, 1)
cv.cv.SetData(cv_image, numpy_image.tostring(), numpy_array.dtype.itemsize*1*256)
cv.cv.WriteFrame(writer, cv_image)
del writer
I can see that I have the appropriate data in my numpy array. And if I try reading the data back from the iplImage I see it is still there. However, writing the frame does not appear to do anything. No file is being made or throwing any error. What could I be doing wrong? Thanks in advance.
GetFrame
come from (would it becv.cv.GetFrame
)? What are your imports for this code? – heltonbiker Oct 10 '11 at 16:58