CV2: “[ WARN:0] terminating async callback” when attempting to take a picture

老子叫甜甜 提交于 2019-12-01 21:40:14

It's probably showing a warning because you're not releasing the handle to the webcam.

try adding this to the end of the code

camera.release()
cv2.destroyAllWindows()

I hope this helps!

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.

Sumit kumar
camera = cv2.VideoCapture(camera_port,cv2.CAP_DSHOW)

cv2.destroyAllWindows()

It works for me as indicated Sumit Kumar


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()
  1. first:add cv2.destroyAllWindows()
  2. second:the camera permission you have banned,and then check it.
Little_being

I did this & I don't see that warning there after.(only for Windows OS)

Open cmd and type:

setx OPENCV_VIDEOIO_PRIORITY_MSMF 0
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!