本文介绍了CV2:“ [WARN:0]终止异步回调”尝试拍照时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用python从defualt carmera拍摄一张照片,为此,我正在使用openCV(从python shell中导入 )。但是,当我尝试禁用相机时,它会关闭,但出现错误 [WARN:0]终止异步回调。

I am trying to take a picture from the defualt carmera with python, to do this I am using openCV (import cv2 from python shell). However, when I attempt to disable the camera it closes but with the error [ 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

代码输出所需的结果-需要保存图像,但我不明白为什么会出现错误消息或如何将其删除

The code outputs the desired result- it takes a saves an image but I do not understand why the error message occures or how to remove it

推荐答案

我有同样的警告。
只需将 camera = cv2.VideoCapture(camera_port)行修改为 camera = cv2.VideoCapture(camera_port,cv2.CAP_DSHOW)并添加 cv2.destroyAllWindows()作为代码的最后一行。

I had the same warning. Just modify the line camera = cv2.VideoCapture(camera_port) to camera = cv2.VideoCapture(camera_port, cv2.CAP_DSHOW) and add cv2.destroyAllWindows() as the last line of your code.

这篇关于CV2:“ [WARN:0]终止异步回调”尝试拍照时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 05:58