I'm using the Python interface for OpenCV 2.2.0. The following code works correctly for grabbing frames from a video file:
for f in range(1, frameCount):
# grab the left and right frames
frameL = cv.QueryFrame(videoL)
frameR = cv.QueryFrame(videoR)
# create the image for the first frame
if f==1:
imageL = cv.CreateImage(cv.GetSize(frameL), frameL.depth, frameL.channels)
imageR = cv.CreateImage(cv.GetSize(frameR), frameR.depth, frameR.channels)
# update the images
cv.Copy(frameL, imageL)
cv.Copy(frameR, imageR)
However, as I process more video frames, the memory consumption keeps increasing. According to the OpenCV documentation, we don't need to release the memory for the image data obtained by cv.QueryFrame. Is this still correct? I tried "del frameL" and "del frameR", but it didn't solve the problem. Is there a bug in the Python wrapper for OpenCV in this particular function?
Thanks.
You should allocate memory for both images once: imageL = cv.CreateImageHeader(cv.GetSize(frameL), frameL.depth, frameL.channels) imageR = cv.CreateImageHeader(cv.GetSize(frameR), frameR.depth, frameR.channels)
then begin your loop and set the data:
cv.SetData(frameL, imageL)
cv.SetData(frameR, imageR)
so something like
for f in range(1, frameCount):
# grab the left and right frames
frameL = cv.QueryFrame(videoL)
frameR = cv.QueryFrame(videoR)
# create the image for the first frame
if f==1:
imageL = cv.CreateImageHeader(cv.GetSize(frameL), frameL.depth, frameL.channels)
imageR = cv.CreateImageHeader(cv.GetSize(frameR), frameR.depth, frameR.channels)
# update the images
cv.SetData(frameL, imageL)
cv.SetData(frameR, imageR)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With