Skip to content
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

The camera index isn't match with the real devices #7

Open
Sleepy-11 opened this issue Sep 5, 2022 · 3 comments
Open

The camera index isn't match with the real devices #7

Sleepy-11 opened this issue Sep 5, 2022 · 3 comments

Comments

@Sleepy-11
Copy link

I tried to build and installed on my laptop. And it seems that the listed camera isn't match the real devices, or at least the index which opencv uses. Below is the output:

Before inserting the USB camera:
❯ python .\test.py
OpenCV version: 4.5.5
0: HP HD Camera [(640, 480), (320, 180), (320, 240), (424, 240), (640, 360), (640, 480), (320, 180), (320, 240), (424, 240), (640, 360), (848, 480), (960, 540), (1280, 720)]
Select a camera (0 to 0): 0
Default width: 640.0, height: 480.0
[ WARN:0@16.323] global D:\a\opencv-python\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (539) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback

After inserting the USB camera:

❯ python .\test.py
OpenCV version: 4.5.5
0: USB Camera [(1280, 720), (800, 600), (640, 480), (352, 288), (320, 240), (176, 144), (160, 120), (1280, 720), (800, 600), (640, 480), (352, 288), (320, 240), (176, 144), (160, 120), (1280, 720), (800, 600), (640, 480), (352, 288), (320, 240), (176, 144), (160, 120), (1280, 720), (800, 600), (640, 480), (352, 288), (320, 240), (176, 144), (160, 120)]
1: HP HD Camera [(640, 480), (320, 180), (320, 240), (424, 240), (640, 360), (640, 480), (320, 180), (320, 240), (424, 240), (640, 360), (848, 480), (960, 540), (1280, 720)]
Select a camera (0 to 1): 0
Default width: 640.0, height: 480.0
[ WARN:0@25.521] global D:\a\opencv-python\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (539) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback

the test.py is the sample code in the repo README file.
After inserting the USB Camera, it seems the second webcam took the "0" index, and the integrated one became "1". But actually, the programs calls the integrated cam(i.e. HP HD Camera) when I input "0", and calls USB Camera when i input "1".

python version is 3.10.4, windows-capture-device-list is 1.1.0 and OS is windows 10.

Is there any idea how I can fix it?

@yushulx
Copy link
Owner

yushulx commented Sep 6, 2022

@Sleepy-11 I've never tested the API on a laptop. Probably the built-in camera always takes the 0 position. If you have two USB cameras, you can check whether USB cameras are listed in order. If you only have one USB camera, you can just reverse their order. Note: the index is determined by the camera list returned by DirectShow API. It may not be 100% equal to the index used by OpenCV.

@Sleepy-11
Copy link
Author

@yushulx Thanks for the reply.
From my laptop view, the built-in camera could be placed on index "1" after the USB camera is inserted. And the DirectShow and OpenCV use different webcam sequence. :(

@Avasam
Copy link

Avasam commented Jun 21, 2023

@Sleepy-11 Consider upvoting and commenting on issues like opencv/opencv#4269 for OpenCV to expose their device sequence.

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

No branches or pull requests

3 participants