Search code examples
pythonopencvcamera

open cv close camera


I am using OpenCv to capture image from webcam.

It works fine I just don't know how to close the camera.

from cv2 import *
# initialize the camera
cam = VideoCapture(0)   # 0 -> index of camera
s, img = cam.read()
if s:    # frame captured without any errors
    namedWindow("cam-test",CV_WINDOW_AUTOSIZE)
    imshow("cam-test",img)`
    waitKey(0)
    destroyWindow("cam-test")
    imwrite("testfilename.jpg",img) #save image
    cam.release

Solution

  • I think you're just missing () at the end of cam.release