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

Elephant picture Elephant · Dec 21, 2018 · Viewed 40.8k times · Source

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.

This is code I am trying to run:

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

Answer

Djotchuang Tamo picture Djotchuang Tamo · Jul 1, 2019

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.