打开cv关闭相机
问题描述:
我使用OpenCv从网络摄像头捕捉图像。打开cv关闭相机
它工作正常我只是不知道如何关闭相机。
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
答
我认为你只是在cam.release
答
变化CV_WINDOW_AUTOSIZE
末WINDOW_AUTOSIZE
失踪()
。
你的代码工作正常。一旦您按任意键,相机会自动关闭,因为您使用了waitKey(0)。你能详细说明你的问题吗? – Jazz
谢谢,即使在写入文件后,相机指示灯仍然闪烁。它只会在python会话关闭时关闭。 – akshay