Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Technical Discussion (http://www.chiefdelphi.com/forums/forumdisplay.php?f=22)
-   -   Dual Cameras? (http://www.chiefdelphi.com/forums/showthread.php?t=133939)

taichichuan 02-03-2015 08:04 PM

Dual Cameras?
 
Hmm... OK, in looking through the WPILib sources (C++), it appears that the camera server is hard-coded to camera 0. Not only that, but the NI vision system remembers which cameras were enumerated as "cam0" and "cam1". In general, that's not necessarily a problem, unless one of your cameras gets trashed and you try to substitute another. The new camera will be enumerated as "camx" where x is > 0. This will cause the cameraserver to fail because it's hardcoded to only work with cam0.

So, short of porting mjpegserver over to the roboRIO, does anyone have an approach for using dual USB cameras?

TIA,

Mike

Adamz_ 02-03-2015 09:44 PM

Re: Dual Cameras?
 
I'm going off of memory here because i don't have a roboRio to test with, but I'm fairly certain that within the Rio's web interface you can change the names of cameras to satisfy having the name cam0 or cam1.

Another way around this is with the cameraServer class, wich allows you to specify what camera you want to get the feed one.

For the example below, you would be receiving data from cam3 on the rio dashboard.
Code:

void CameraServer::StartAutomaticCapture (cam3)
If the above code doesn't make much sense i apologize, but I'm a java programmer.

taichichuan 02-03-2015 10:35 PM

Re: Dual Cameras?
 
Quote:

Originally Posted by Adamz_ (Post 1437976)
I'm going off of memory here because i don't have a roboRio to test with, but I'm fairly certain that within the Rio's web interface you can change the names of cameras to satisfy having the name cam0 or cam1.

Another way around this is with the cameraServer class, wich allows you to specify what camera you want to get the feed one.

For the example below, you would be receiving data from cam3 on the rio dashboard.
Code:

void CameraServer::StartAutomaticCapture (cam3)
If the above code doesn't make much sense i apologize, but I'm a java programmer.

Thanks for the suggestion, but we already tried this. The camera server code does not have a stop method and trying to use a camera other than 0 results in lots of errors being displayed in the messages windows. In particular, failures in line 33 of the USBCamera class related to setting the jpeg compression ratio.

It would be nice if you could:

If (button1) {
CameraServer::GetInstance()->StartAutomaticCapture("cam0");
}
if (button2) {
CameraServer::GetInstance()->StartAutomaticCapture("cam1");
}

But, that fails miserably. This is due to several reasons. First, the StartAutomaticCapture ends up creating threads, opening sockets etc. for which there is no clean shutdown method in the class. Second, even if there were a clean shutdown method, there is an m_camera member in the class that is hard coded to camera 0.

So, there is no way to clean up if you shut could shut the class down. And, if you tried to force it in Linux by killing the thread manually, this will undoubtedly come back to haunt you toward the end of the match because the thread probably has resources tied up.

So, does anyone have any other ideas?

TIA,

Mike

Merfoo 02-04-2015 04:10 PM

Re: Dual Cameras?
 
The Intermediate Vision example project shows how to get an image from a camera and then sending it to the dashboard. So what you could do is have multiple camera objects and then choose which camera to get the image from and then send that image to the dashboard.

taichichuan 02-04-2015 06:16 PM

Re: Dual Cameras?
 
Quote:

Originally Posted by Merfoo (Post 1438329)
The Intermediate Vision example project shows how to get an image from a camera and then sending it to the dashboard. So what you could do is have multiple camera objects and then choose which camera to get the image from and then send that image to the dashboard.

I'll take a look at that sample.

Thanks,

Mike

taichichuan 02-07-2015 09:30 AM

Re: Dual Cameras?
 
Fixed! Thanks to the suggestion from the previous post, I've got two cameras working with C++. It's a bit klugey, but the NI code really isn't built to run more than one camera at a time. I'm cleaning the code up today and I'll post a copy for those who are interested.

Mike

vps 02-08-2015 11:41 PM

Re: Dual Cameras?
 
Can you please post/message me a copy? I've been unsuccessful doing that for a while.

taichichuan 02-10-2015 08:41 PM

Re: Dual Cameras?
 
1 Attachment(s)
Here is the code for dual cameras running on the RoboRio. The code is written in C/C++, but it should be readily adaptable to Java. The zip is in the form of an Eclipse project and should be able to be imported directly into Eclipse. This should be extensible to more than 2 cameras by modifying the teleop loop, startCamera and stopCamera code to handle the extra cameras. We hope this helps someone out there. If you've got any questions, feel free to ask.

HTH,

Mike

Merfoo 02-11-2015 12:59 AM

Re: Dual Cameras?
 
An example of this in Java can also be found here:

https://github.com/Merfoo/MultiCamera

taichichuan 02-17-2015 05:04 PM

Re: Dual Cameras? -- Updated C++ Class Code
 
1 Attachment(s)
Greetings!

I've cleaned up the dual camera code and created a class ala the Java example that was posted earlier. Essentially, add the CameraFeeds.cpp and CameraFeeds.h to your project and then instantiate as it is done in the robot.cpp example. I've included the class in a working Mecanum example just so people can see the ability to drive and the dual cameras at the same time.

Enjoy,

Mike


All times are GMT -5. The time now is 03:37 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi