Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cv2: [ WARN:0] global cap_msmf.cpp (674) SourceReaderCB::~SourceReaderCB terminating async callback [duplicate]

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.

like image 894
M. Rostami Avatar asked Jan 31 '20 16:01

M. Rostami


2 Answers

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.

like image 75
Rahat Zaman Avatar answered Sep 22 '22 03:09

Rahat Zaman


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

like image 38
karlphillip Avatar answered Sep 22 '22 03:09

karlphillip