QueryFrame memory leak function in OpenCV Python

I use the interface Pythonfor OpenCV 2.2.0. The following code works correctly to capture 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, when I process more video frames, memory consumption increases. According to the OpenCV documentation, we don’t need to allocate memory for image data obtained with cv.QueryFrame. Is this still correct? I tried "del frameL" and "del frameR", but this did not solve the problem. Is there a bug in the Python shell for OpenCV in this particular function?

Thank.

+3
source share
1 answer

:  imageL = cv.CreateImageHeader(cv.GetSize(frameL), frameL.depth, frameL.channels)  imageR = cv.CreateImageHeader(cv.GetSize(frameR), frameR.depth, frameR.channels)

:

cv.SetData(frameL, imageL)
cv.SetData(frameR, imageR)

-

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)
+1

All Articles