Python 开闭式摄像机
我正在使用OpenCv从网络摄像头捕获图像 很好,我只是不知道怎么关上相机Python 开闭式摄像机,python,opencv,camera,Python,Opencv,Camera,我正在使用OpenCv从网络摄像头捕获图像 很好,我只是不知道怎么关上相机 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) imsh
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的末尾。释放将CV\u WINDOW\u AUTOSIZE
更改为WINDOW\u AUTOSIZE
你的代码工作正常。因为使用了waitKey(0),所以按下任意键后,相机将自动关闭。你能详细说明一下你的问题吗?谢谢,即使在文件被写入之后,相机的指示灯也在闪烁。它只有在python会话关闭时才会关闭。