auraham
auraham

Reputation: 1739

how to correctly use webcam in opencv using python wrappers?

Currently, I have this working example:

import cv

capture = cv.CaptureFromCAM(0)

cv.NamedWindow('image')

while True:

    frame = cv.QueryFrame(capture)
    cv.ShowImage('image', frame)

    k = cv.WaitKey(10)

    if k % 256 == 27:
        break

cv.DestroyWindow('image');

But, the resource is not properly release. This post suggests using del(capture) but, in this other recommends using cvReleaseCapute (but I can't find that function ).

Which is the correct way to release the capture?

This is my opencv version:

In [4]: from cv2 import __version__
In [5]: __version__
Out[5]: '$Rev: 4557 $'

Upvotes: 0

Views: 5749

Answers (1)

auraham
auraham

Reputation: 1739

Use cv2.VideoCapture and capture.release() (cv2 instead of cv)

import cv2, cv

capture = cv2.VideoCapture(0)   

flag, im_array = capture.read()

image = cv.fromarray(im_array)

cv.SaveImage('output.jpeg', image)

capture.release()                   # release it

Upvotes: 3

Related Questions