Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   [Snippet] Using 2+ Cameras with minimal bandwidth usage (http://www.chiefdelphi.com/forums/showthread.php?t=141904)

kmodos 01-16-2016 06:05 PM

[Snippet] Using 2+ Cameras with minimal bandwidth usage
 
After messing around with cameras today, I was able to figure out how to use multiple cameras while only using the bandwidth of one. To do such, you simply switch between which feed you are sending back to the driver station with the touch of a button. See the code down below to see how to do this.

Variables needed:
Code:

int currSession;
int sessionfront;
int sessionback;
Image frame;

Init code:
Code:

frame = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_RGB, 0);

sessionfront = NIVision.IMAQdxOpenCamera("cam1", NIVision.IMAQdxCameraControlMode.CameraControlModeController);
       
sessionback = NIVision.IMAQdxOpenCamera("cam2", NIVision.IMAQdxCameraControlMode.CameraControlModeController);

currSession = sessionfront;

NIVision.IMAQdxConfigureGrab(currSession);

Switch between views:
Code:

if(/*button pressing code*/){
        if(currSession == sessionfront){
                        NIVision.IMAQdxStopAcquisition(currSession);
                  currSession = sessionback;
                  NIVision.IMAQdxConfigureGrab(currSession);
        } else if(currSession == sessionback){
                        NIVision.IMAQdxStopAcquisition(currSession);
                        currSession = sessionfront;
                        NIVision.IMAQdxConfigureGrab(currSession);
        }
}

Sending the images to the DS:
Code:

NIVision.IMAQdxGrab(currSession, frame, 1);
CameraServer.getInstance().setImage(frame);

This code can easily be extended to include more than two cameras, if you wish. If anyone needs help implementing this, feel free to PM me/post below.

bbjdt2224 01-19-2016 07:43 PM

Re: [Snippet] Using 2+ Cameras with minimal bandwidth usage
 
When I put this in my code and deployed it to the robot several errors showed up and the dashboard indicated there was no code.
Where did you put all of these pieces of code in your project?

fovea1959 01-21-2016 08:19 AM

Re: [Snippet] Using 2+ Cameras with minimal bandwidth usage
 
kmodos: thank you very much. works perfectly for us.

has anyone figured out how to open both cameras at once? we would like to open both camera, grab a frame from each, lay them down side by side in a double size frame, and send *that* to the DS. The problem is that IMAQdxConfigureGrab throws an exception if you already have called it with*out* an intervening MAQdxStopAcquisition.

kmodos 01-21-2016 12:55 PM

Re: [Snippet] Using 2+ Cameras with minimal bandwidth usage
 
Quote:

Originally Posted by bbjdt2224 (Post 1526875)
When I put this in my code and deployed it to the robot several errors showed up and the dashboard indicated there was no code.
Where did you put all of these pieces of code in your project?

Did you remember to import all of the required packages? The code under init code needs to be run one time when the robot is powered on. The switching code and sending the frame back to the driver station should be placed in some sort of loop, it can be in periodic, or a custom loop you write.

Quote:

Originally Posted by fovea1959 (Post 1527696)
kmodos: thank you very much. works perfectly for us.

has anyone figured out how to open both cameras at once? we would like to open both camera, grab a frame from each, lay them down side by side in a double size frame, and send *that* to the DS. The problem is that IMAQdxConfigureGrab throws an exception if you already have called it with*out* an intervening MAQdxStopAcquisition.


I might look into doing something like this. I have to talk with our drivers to see if this would be something that they want. If I get it working I will post it publicly.

Firebirds433 02-06-2016 03:31 PM

Re: [Snippet] Using 2+ Cameras with minimal bandwidth usage
 
Worked like a charm, thanks! For anyone who's having trouble, make sure that all other camera code is removed. We accidentally left some in at first, and the code didn't work correctly.

Justin Buist 02-06-2016 10:53 PM

Re: [Snippet] Using 2+ Cameras with minimal bandwidth usage
 
Quote:

Originally Posted by fovea1959 (Post 1527696)
kmodos: thank you very much. works perfectly for us.

has anyone figured out how to open both cameras at once? we would like to open both camera, grab a frame from each, lay them down side by side in a double size frame, and send *that* to the DS. The problem is that IMAQdxConfigureGrab throws an exception if you already have called it with*out* an intervening MAQdxStopAcquisition.

It's possible, but you'd have to roll your own version of CameraServer. It's not terribly hard. I put one together last week so we can publish OpenCV Mat images back to the dashboard. The protocol for getting stuff back to the dashboard is pretty simple. Just take a peek at the GRIP code for doing it (https://github.com/WPIRoboticsProjec...Operation.java) ... basically everything in that main while() loop is the important stuff. CameraServer from WPIlibj works much the same way but utilizes NIVision.Image objects instead.

How you mash the two images together I don't know as I have basically zero experience with the NIVision libs. But, roll your own CameraServer, solve the issue of mashing images together into a single JPEG and there you go.

Ozuru 02-07-2016 03:46 PM

Re: [Snippet] Using 2+ Cameras with minimal bandwidth usage
 
Awesome code, this snippet will surely be helpful in the future. Thanks for sharing.

RamTech 59 02-15-2016 05:30 PM

Re: [Snippet] Using 2+ Cameras with minimal bandwidth usage
 
When I use this code my cameras seem to lag, does anyone have complete code that I can use as reference?

kmodos 02-15-2016 07:06 PM

Re: [Snippet] Using 2+ Cameras with minimal bandwidth usage
 
Quote:

Originally Posted by RamTech 59 (Post 1540764)
When I use this code my cameras seem to lag, does anyone have complete code that I can use as reference?

Does the lag occur when you switch between the two? Switching will always lag a bit as well as all feeds will lag a tiny bit. Try to lower the quality of the returned image or lower the resolution.


All times are GMT -5. The time now is 08:06 AM.

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