Ask Your Question
0

How do I choose which camera I am accessing?

asked 2018-05-02 13:08:20 -0600

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);
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2018-05-02 13:52:38 -0600

kbarni gravatar image

updated 2018-05-02 14:57:37 -0600

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/...");

edit flag offensive delete link more

Comments

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

Marko5280 gravatar imageMarko5280 ( 2018-05-02 15:45:53 -0600 )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 ( 2018-05-03 08:35:54 -0600 )edit

Windows 7 Eclipse

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

Marko5280 gravatar imageMarko5280 ( 2018-05-03 16:04:03 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-05-02 13:08:20 -0600

Seen: 15,628 times

Last updated: May 02 '18