问题
Full warning message:
[ WARN:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (674) SourceReaderCB::~SourceReaderCB terminating async callback
Code:
import numpy as np
import cv2
captureDevice = cv2.VideoCapture(0) #captureDevice = camera
while True:
ret, frame = captureDevice.read()
cv2.imshow('my frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
captureDevice.release()
cv2.destroyAllWindows()
Description:
When it runs, the my frame
windows appear and when I terminate the code, it gives me that warning message.
Python: 3.7.4
OpenCV (cv2): 4.1.2
OS: Windows 10
I don't know to fix this warning and why it gets me. Hope you help me in fixing and understanding that.
In addition, answers of this link didn't help me anyway.
Thanks in advance.
回答1:
This seems to be a bug in MSMF backend of opencv. You can see more details in this issue.
I don't think this problem exists on Linux platforms. So I am providing the solution for windows.
Windows only solution
For windows platform, you can change the backend to something else (most preferably DirectShow backend. For this, add to your VideoCapture
like below:
captureDevice = cv2.VideoCapture(0, cv2.CAP_DSHOW) #captureDevice = camera
This works for OpenCV>=3.4
.
回答2:
A warning message is not an error!
But if that bothers you so much, you might try to disable MSMF by setting the following Environment Variable to 0
on Windows:
OPENCV_VIDEOIO_PRIORITY_MSMF
How to set the path and environment variables in Windows
回答3:
I've solved, the problem was that i had open my code executing already, make sure you have closed all your builds
来源:https://stackoverflow.com/questions/60007427/cv2-warn0-global-cap-msmf-cpp-674-sourcereadercbsourcereadercb-termina