我想关闭网络摄像头,在使用cap.release()后,它没有在捕获图像后关闭网络摄像头。以下是我的代码:
import cv2
import matplotlib.pyplot as plt
def main():
cap=cv2.VideoCapture(0)
if cap.isOpened():
ret, frame = cap.read()
print(ret)
print(frame)
else:
ret=False
img1= cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
plt.imshow(img1)
plt.title('Color Image RGB')
plt.xticks([])
plt.yticks([])
plt.show()
cap.release()
if __name__=='__main__':
main()
cap.release()
出现在您的示例中的最后一条语句时,您如何知道它没有被释放? - Dan Mašek