【发布时间】:2018-03-31 00:31:21
【问题描述】:
我正在使用 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)
imshow("cam-test",img)`
waitKey(0)
destroyWindow("cam-test")
imwrite("testfilename.jpg",img) #save image
cam.release
【问题讨论】:
-
您的代码运行良好。一旦你按下任何键,相机就会自动关闭,因为你使用了 waitKey(0)。你能详细说明你的问题吗?
-
谢谢,文件写入后相机灯还在闪烁。它只会在 python 会话关闭时才会熄灭。