OpenCV webcam error

Hello! I’ve been using OpenCV for a few weeks now, but I am new to this community. If this question was asked before, apologies in advance. Here goes:

Whenever I try to open the webcam with

video = cv2.VideoCapture(1),

I get these errors:

[ WARN:1@165.321] global D:\a\opencv-python\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (464) `anonymous-namespace'::SourceReaderCB::OnReadSample videoio(MSMF): OnReadSample() is called with error status: -1072873821
[ WARN:1@165.321] global D:\a\opencv-python\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (476) `anonymous-namespace'::SourceReaderCB::OnReadSample videoio(MSMF): async ReadSample() call is failed with error status: -1072873821

Mind you, using video = cv2.VideoCapture(video_path) works perfectly, but now I have to use the webcam. However, I cannot do anything with these errors persisting. Any help is appreciated. Can post the code if needed. Thanks in advance!

try the DSHOW backend:

video = cv2.VideoCapture(1, CAP_DSHOW)

(by default on win, it is choosing the MSMF backend, which does not seem to work nicely for you)

video = cv2.VideoCapture(1, CAP_DSHOW)

This fixed my problem, thanks. The thread can be locked.

About msmf you can try :

On C++

#include
putenv(“OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS=0”);

Or on Python

import os
os.environ[“OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS”] = “0”

1 Like