Skip to content

USB Webcam does not work in the newer version: 4.7.0.72 #834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
gunarakulangunaretnam opened this issue Apr 17, 2023 · 8 comments
Open

Comments

@gunarakulangunaretnam
Copy link

USB Webcam does not work in the newer version: 4.7.0.72

I wrote a simple script to read frames from a webcam, it works fine with laptop-attached webcams. When I try to use with the USB-based webcam (not-branded webcam), it returns the following error.

[ WARN:1@2.601] global cap_msmf.cpp:1759 CvCapture_MSMF::grabFrame videoio(MSMF): can't grab frame. Error: -2147024809

My Code:

import cv2


cap = cv2.VideoCapture(2)

while True:

    
    ret, frame = cap.read()
    

    if ret:

        cv2.imshow('Input', frame)
    else:
        print("dsd")

    c = cv2.waitKey(1)
    if c == 27:
        break

When I install the older version of OpenCV-python: 4.5.5.62, it works fine, I think the issue is with the newer release.

Please take a consideration on it.

@asmorkalov
Copy link
Collaborator

could you run the same code with old and new OpenCV versions with debug options and collect logs. To enable debug logging you need to set the following environment variables OPENCV_LOG_LEVEL=DEBUG, OPENCV_VIDEOIO_DEBUG=1

@harshkasat
Copy link

I'm also getting this error with the USB webcam. Does anyone have a solution regarding this?

@asmorkalov
Copy link
Collaborator

Please try the previous recommendation to give us information for debugging.

1 similar comment
@asmorkalov
Copy link
Collaborator

Please try the previous recommendation to give us information for debugging.

@Maculapse
Copy link

Hi! I can confirm the same problem with 4.8.x version using usb cam. Had to downgrade to 4.5 to get it working, as mentioned by the author.

@asmorkalov
Copy link
Collaborator

@Maculapse could you run the same code with old and new OpenCV versions with debug options and collect logs. To enable debug logging you need to set the following environment variables OPENCV_LOG_LEVEL=DEBUG, OPENCV_VIDEOIO_DEBUG=1

@ArptPlank
Copy link

我也是4.8版本也遇到这个问题,自己的电脑上没问题,在客户的电脑上死活不行

@polar147
Copy link

polar147 commented Apr 30, 2025

@asmorkalov i have the same issue. this is the output with debug env var:

[DEBUG:0@0.021] global videoio_registry.cpp:225 cv::`anonymous-namespace'::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Builtin backends(10): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); MSMF(960); DSHOW(950); CV_IMAGES(940); CV_MJPEG(930); UEYE(920); OBSENSOR(910)
[DEBUG:0@0.028] global videoio_registry.cpp:249 cv::`anonymous-namespace'::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Available backends(10): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); MSMF(960); DSHOW(950); CV_IMAGES(940); CV_MJPEG(930); UEYE(920); OBSENSOR(910)
[ INFO:0@0.039] global videoio_registry.cpp:251 cv::`anonymous-namespace'::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Enabled backends(10, sorted by priority): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); MSMF(960); DSHOW(950); CV_IMAGES(940); CV_MJPEG(930); UEYE(920); OBSENSOR(910)
[ WARN:0@0.045] global cap.cpp:406 cv::VideoCapture::open VIDEOIO(GSTREAMER): trying capture cameraNum=0 ...
[ INFO:0@0.050] global backend_plugin.cpp:382 cv::impl::getPluginCandidates Found 2 plugin(s) for GSTREAMER
[ INFO:0@0.058] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:\Users\andrei\Desktop\Parachoque\.env\Lib\site-packages\cv2\opencv_videoio_gstreamer4110_64.dll => FAILED
[ INFO:0@0.061] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_videoio_gstreamer4110_64.dll => FAILED
[ WARN:0@0.064] global cap.cpp:468 cv::VideoCapture::open VIDEOIO(GSTREAMER): backend is not available (plugin is missing, or can't be loaded due dependencies or it is not compatible)
[ WARN:0@0.068] global cap.cpp:406 cv::VideoCapture::open VIDEOIO(MSMF): trying capture cameraNum=0 ...
[ INFO:0@0.089] global cap_msmf.cpp:1033 CvCapture_MSMF::configureHW MSMF: Using D3D11 video acceleration on GPU device: Intel(R) HD Graphics 4600
[DEBUG:0@0.213] global cap_msmf.cpp:916 CvCapture_MSMF::initStream Init stream 0 with MediaType (640x480 @ 30) YUY2
[DEBUG:0@0.216] global cap_msmf.cpp:916 CvCapture_MSMF::initStream Init stream 0 with MediaType (640x480 @ 30) MFVideoFormat_RGB32
[ WARN:0@28.224] global cap.cpp:418 cv::VideoCapture::open VIDEOIO(MSMF): created, isOpened=1
[DEBUG:0@28.227] global cap_msmf.cpp:534 `anonymous-namespace'::SourceReaderCB::Wait videoio(MSMF): waiting for frame...
[ WARN:0@38.236] global cap_msmf.cpp:1795 CvCapture_MSMF::grabFrame videoio(MSMF): can't grab frame. Error: -2147483638
Traceback (most recent call last):
  File "C:\Users\andrei\Desktop\Parachoque\parachoque.py", line 8, in <module>
    hsv = cv2.cvtColor(frame,cv2.COLOR_BGR2HSV)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cv2.error: OpenCV(4.11.0) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\color.cpp:199: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants