Ask Your Question
0

VideoCapture - knowing the id parameter

asked 2016-10-14 09:54:11 -0600

alexandre98654 gravatar image

How can i know the camera whose the id parameter of VideoCapture function are pointing out? I need to find a default on the id, because I need know if the webcam is the default installed at windows or anyone plugged there.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-10-14 10:22:14 -0600

berak gravatar image

it works like this:

there is a list of devices, populated from your os, and invisible to you (sad as it is) , and your webcams appear there in the order you plugged them in.

so, if you're e.g on a laptop with a builtin camera, that will be id 0, if you plug in an additional one, that's id 1.

note, that in theory, you could also try -1 for id, which will fall back from default directshow code to arcane VFW(which is problematic on later win versions), and give you a box to choose from available devices.

edit flag offensive delete link more

Comments

I have try :

VideoCapture vid1(-1);
VideoCapture vid2(-1);
if (vid1.isOpened() && vid2.isOpened())
{
   for (char c=0;c!=27;)
   {
       Mat frame1,frame2;
       vid1 >> frame1;
       vid2 >> frame2;
       imshow("vid1", frame1);
       imshow("vid2", frame2);
       c=waitKey(1);
   }
}

and it is working now with win vs2015 and opencv 3.1-dev

LBerger gravatar imageLBerger ( 2016-10-15 04:07:38 -0600 )edit
1

About "in the order you plugged them in." I have tried with 3 cameras A B C. When i run my program A is 0 B 1 and C is 2. If I quit my program unplugged B I have got A=0 and C=1. If leave and plug B I have got again A=0, B=1 and C=2. Again it is windows10

LBerger gravatar imageLBerger ( 2016-10-15 04:21:26 -0600 )edit

@LBerger , makes sense. so we need a better (more detailed) formulation above, i guess

berak gravatar imageberak ( 2016-10-15 04:38:19 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-10-14 09:54:11 -0600

Seen: 2,545 times

Last updated: Oct 14 '16