在cap.release()
之后,唯一的相框已关闭,网络摄像头指示灯仍打开。
import cv2
cap = cv2.VideoCapture(0)
#cap = cv2.VideoCapture(-1) if i give '-1' instead of '0' then light is getting OFF
#but camera is not working because i don't have second camera to laptop.
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cap.isOpened() #returns False
cv2.destroyAllWindows()
通过按“ q ”,框架将关闭,但网络摄像头指示灯仍亮起。
如何关闭网络摄像头? (在关闭python shell之后,它就关闭了。)
如果可能,请告诉我cv2.VideoCapture()
类源代码的路径。