我试图用python从defualt carmera拍张照片,为此我正在使用openCV(import cv2来自python shell)。但是,当我尝试禁用相机时,它会关闭但出现错误[ WARN:0] terminating async callback。
import cv2
[ WARN:0] terminating async callback
这是我要运行的代码:
import cv2 camera_port = 0 camera = cv2.VideoCapture(camera_port) return_value, image = camera.read() cv2.imwrite("image.png", image) camera.release() # Error is here
代码输出所需的结果-需要保存图像,但我不明白为什么会出现错误消息或如何删除它
我也有同样的警告。只需将行修改camera = cv2.VideoCapture(camera_port)为camera = cv2.VideoCapture(camera_port,cv2.CAP_DSHOW)并添加cv2.destroyAllWindows()为代码的最后一行。
camera = cv2.VideoCapture(camera_port)
camera = cv2.VideoCapture(camera_port,cv2.CAP_DSHOW)
cv2.destroyAllWindows()