cap_msmf.cpp (435) [ WARN:0] on cv2.VideoCapture break
I wonder if anyone else has encountered this warning when breaking out of a VideoCapture read loop when reading an onboard (0) or USB web cam (1)? (Note: It does not issue this warning if breaking out of a read loop while playing back a video file AND THAT APPEARS to be a significant difference.)
Although not critical, the warning is distracting and untidy and I would like to know if there is a solution. Having said that, I note using VideoCapture(1, CAP_DSHOW) does avoid triggering the warning, but the point is the simple read loop in the code below is textbook and it should work. At first glance it looks like cap_msmf.cpp is throwing the warning because it sees the call to be destructive rather than releasing, notwithstanding the gracious break, and release code that is widely used for terminating VideoCapture routines such as this. On closer inspection, I think however it may have more to do with the call to terminate being anonymous when reading a web cam. Any suggestions?
I can't tell you when I first noticed this warning as I have been inactive lately, but it was only recently when this jumped up and since I updated everything to very recent release packages:
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32
opencv_version = "4.4.0.42"
IDE = PyCharm Community 2020.2
My py code block is:
import cv2
import numpy as np
###### READING A VIDEO ################
# cap = cv2.VideoCapture("Resources/00055a_01.mp4") # a short video
cap = cv2.VideoCapture(1) # a USB videocam
waitframe = 100 # frames per second
while True: # an infinite while loop til Esc key pressed
success, img = cap.read()
if not success:
break
cv2.imshow("Video", img)
ch = cv2.waitKey(waitframe)
if ch == 27 or ch == ord('q') or ch == ord('Q'):
cv2.waitKey(300)
print('Quitting')
break
# All done, release device
cap.release()
cv2.destroyAllWindows()
This returns the warning: [ WARN:0] global C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-cff9bdsm\opencv\modules\videoio\src\cap_msmf.cpp (435) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback
The relevant part of cap_msmf.cpp (435) is: 431 private: 432 // Destructor is private. Caller should call Release. 433 virtual ~SourceReaderCB() 434 { 435 CV_LOG_WARNING(NULL, "terminating async callback"); 436 }
When you googled the warning message, you must have noticed that LOTS of people have encountered that warning and discussed it on various sites
you need a number-id to open a webcam, not a string, like:
(and it should use cap_aravis.cpp, not cap_msmf.cpp)
also add a bit of debugging and
so you can see, which backend is atually tried for this