Running on Windows 10, 'can't open camera by index' on Windows 11

I am using See3CAM_CU135. On Windows 10, the following program works:

camera = cv2.VideoCapture(0,cv2.CAP_DSHOW)
fps = 30
camera.set(cv2.CAP_PROP_FPS,fps)
while True:
hasFrame, frame = camera.read()
cv2.imshow(‘camera’,frame)
cv2.waitKey(10)

But on Windows 11, I get the error: “can’t open camera by index”

Any advice?

1 Like

camera = cv2.VideoCapture(0,cv2.CAP_DSHOW)

please try, if the MSMF backend works better for you:

camera = cv2.VideoCapture(0,cv2.CAP_MSMF)

please also enable debug logging
(on the console. before starting your script):

SET OPENCV_LOG_LEVEL=debug
SET OPENCV_VIDEOIO_DEBUG=1
1 Like

Thank you for your response.
CAP_MSMF is working fine on Windows10, but on windows 11 we have got:

[DEBUG:0@1.322] global videoio_registry.cpp:218 cv::anonymous-namespace'::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Builtin backends(9): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930); OBSENSOR(920) [DEBUG:0@1.327] global videoio_registry.cpp:242 cv::anonymous-namespace’::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Available backends(9): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930); OBSENSOR(920)
[ INFO:0@1.332] global videoio_registry.cpp:244 cv::`anonymous-namespace’::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Enabled backends(9, sorted by priority): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930); OBSENSOR(920)
[DEBUG:0@1.340] global cap.cpp:363 cv::VideoCapture::open VIDEOIO: choosen backend does not work or wrong.Please make sure that your computer support chosen backend and OpenCV built with right flags.

cv config:
Video I/O:
DC1394: NO
FFMPEG: YES (prebuilt binaries)
avcodec: YES (58.134.100)
avformat: YES (58.76.100)
avutil: YES (56.70.100)
swscale: YES (5.9.100)
avresample: YES (4.0.0)
GStreamer: NO
DirectShow: YES
Media Foundation: YES
DXVA: YES