[英]OpenCV: "[ WARN:0] terminating async callback" when attempting to take a picture
我正在尝试使用 python 从 defualt carmera 拍照,为此我正在使用 openCV(从 python shell import cv2 as cv
)。 但是,当我尝试禁用相机时,它会关闭但出现错误[ WARN:0] terminating async callback
。
这是我要运行的代码:
import cv2 as cv
camera_port = 0
camera = cv.VideoCapture(camera_port)
return_value, image = camera.read()
cv.imwrite("image.png", image)
camera.release() # Error is here
该代码输出所需的结果,它拍摄并保存图像,但我不明白为什么会出现错误消息或如何删除它
我有同样的警告。
只需修改行
camera = cv.VideoCapture(camera_port)
到
camera = cv.VideoCapture(camera_port, cv.CAP_DSHOW)
它可能会显示警告,因为您没有释放网络摄像头的句柄。
尝试将此添加到代码的末尾
camera.release()
cv2.destroyAllWindows()
我希望这有帮助!
camera = cv.VideoCapture(camera_port, cv.CAP_DSHOW)
cv.destroyAllWindows()
我这样做了,之后我没有看到那个警告。(仅适用于 Windows 操作系统)
打开cmd并输入:
setx OPENCV_VIDEOIO_PRIORITY_MSMF 0
这似乎是 opencv 的 MSMF 后端中的一个错误。
如果您使用的是 Windows,则可以将后端更改为DirectShow
后端。
因此,像这样更改VideoCapture
:
captureDevice = cv.VideoCapture(0, cv.CAP_DSHOW)
如所示,它对我有用
camera_port = 0
#camera = cv2.VideoCapture(camera_port)
camera = cv2.VideoCapture(camera_port,cv2.CAP_DSHOW)
# Check if the webcam is opened correctly
if not camera.isOpened():
raise IOError("Cannot open webcam")
return_value, image = camera.read()
print("We take a picture of you, check the folder")
cv2.imwrite("image.png", image)
camera.release() # Error is here
cv2.destroyAllWindows()
我试图用python从defualt carmera拍张照片,要做到这一点,我使用的是openCV(从python shell 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
代码输出所需的结果-需要保存图像,但我不明白为什么会出现错误消息或如何将其删除
cv.destroyAllWindows()
camera = cv.VideoCapture(camera_port, cv.CAP_DSHOW) # Added cv.CAP_DSHOW
return_value, image = camera.read()
cv.imwrite("image.png", image)
camera.release()
cv.destroyAllWindows() # Handles the releasing of the camera accordingly
嘿伙计们找到了解决方案 pip install opencv-contrib-python==3.4.7.28 像这样尝试我们必须特别说明版本 try lesser version 我的是 4.x 所以我做了并且没有弹出错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.