Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am trying to take a picture from the defualt carmera with python, to do this I am using openCV (import cv2 as cv 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 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

The code outputs the desired result, it takes and saves an image, but I do not understand why the error message occurs or how to remove it

like image 792
Elephant Avatar asked Dec 21 '18 17:12

Elephant


3 Answers

I had the same warning.

Just modify the line

camera = cv.VideoCapture(camera_port)

to

camera = cv.VideoCapture(camera_port, cv.CAP_DSHOW)
like image 197
Karl Djotchuang Tamo Avatar answered Nov 10 '22 00:11

Karl Djotchuang Tamo


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!

like image 7
Aprajita Verma Avatar answered Nov 10 '22 01:11

Aprajita Verma


camera = cv.VideoCapture(camera_port, cv.CAP_DSHOW)

cv.destroyAllWindows()
like image 7
Sumit kumar Avatar answered Nov 10 '22 01:11

Sumit kumar