First time here? Check out the FAQ!

Ask Your Question
0

How do I choose which camera I am accessing?

asked May 2 '18

Marko5280 gravatar image

I have a 4-way USB splitter and am trying to develop the ability to access any one of four webcams. So far, I have not been able to do this. I am using C++ code samples to develop my java code. That might be some of the difficulty. The code I am using to do this follows . . .

Does anyone know how this should be done?

int camera = 0;   //   C++ VideoCapture cap(0); // open the default camera
//int camera = 1; //  Insten
//int camera = 2; //  logitech279 
//int camera = 3; //  logitech920 
//int camera = 4; //  logitechxxx
VideoCapture vid = new VideoCapture(camera);                             
vid.open(camera);
Preview: (hide)

1 answer

Sort by » oldest newest most voted
2

answered May 2 '18

kbarni gravatar image

updated May 2 '18

If you are using Linux, you can access cameras directly using the V4L path:

vid.open("/dev/v4l/by-id/...");

Each camera should have its own identifier (like usb-Logitech_920...).

You can also access the camera directly using the USB port identifier: vid.open("/dev/v4l/by-path/...");

Preview: (hide)

Comments

Then what is the meaning of: VideoCapture vid = new VideoCapture(camera); is camera a real variable?

Marko5280 gravatar imageMarko5280 (May 2 '18)edit
1

You either create a VideoCapture object with no parameters and call open, or, if the constructor has a parameter, you don't have to call open again.

The parameter can be an integer (the camera number) or a string representing the path to a camera or a video file.

int camnum=0;
string campath="/dev/video0";
VideoCapture cap1; //no parameter, must call open()
cap1.open(camnum); //open camera 0
VideoCapture cap2(campath); //has parameter, no need to call open()
kbarni gravatar imagekbarni (May 3 '18)edit

Windows 7 Eclipse

Great. But, how do I get the camera number and path?

Marko5280 gravatar imageMarko5280 (May 3 '18)edit

Question Tools

1 follower

Stats

Asked: May 2 '18

Seen: 16,173 times

Last updated: May 02 '18