Go to Post We can sit here and engineer this all day but I think untill one of us gets off our chair and starts making it we'll never know if its possible. - sanddrag [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 01-16-2016, 06:05 PM
kmodos kmodos is offline
Registered User
AKA: Alex
FRC #1126 (SparX)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: New York
Posts: 57
kmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to behold
Post [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.

Last edited by kmodos : 01-16-2016 at 06:07 PM. Reason: Spacing
Reply With Quote
  #2   Spotlight this post!  
Unread 01-19-2016, 07:43 PM
bbjdt2224 bbjdt2224 is offline
Registered User
FRC #3098
 
Join Date: Jan 2016
Location: Waterford
Posts: 1
bbjdt2224 is an unknown quantity at this point
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?
Reply With Quote
  #3   Spotlight this post!  
Unread 01-21-2016, 08:19 AM
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 325
fovea1959 will become famous soon enough
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.

Last edited by fovea1959 : 01-21-2016 at 12:35 PM. Reason: "with" is not the same as "without"
Reply With Quote
  #4   Spotlight this post!  
Unread 01-21-2016, 12:55 PM
kmodos kmodos is offline
Registered User
AKA: Alex
FRC #1126 (SparX)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: New York
Posts: 57
kmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to behold
Re: [Snippet] Using 2+ Cameras with minimal bandwidth usage

Quote:
Originally Posted by bbjdt2224 View Post
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 View Post
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.
Reply With Quote
  #5   Spotlight this post!  
Unread 02-06-2016, 03:31 PM
Firebirds433's Avatar
Firebirds433 Firebirds433 is offline
Registered User
FRC #0433
 
Join Date: Feb 2016
Location: Flourtown
Posts: 1
Firebirds433 is an unknown quantity at this point
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.
Reply With Quote
  #6   Spotlight this post!  
Unread 02-06-2016, 10:53 PM
Justin Buist Justin Buist is offline
Registered User
FRC #4003 (TriSonics)
Team Role: Mentor
 
Join Date: Feb 2015
Rookie Year: 2015
Location: Allendale, MI
Posts: 18
Justin Buist is an unknown quantity at this point
Re: [Snippet] Using 2+ Cameras with minimal bandwidth usage

Quote:
Originally Posted by fovea1959 View Post
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.
Reply With Quote
  #7   Spotlight this post!  
Unread 02-07-2016, 03:46 PM
Ozuru's Avatar
Ozuru Ozuru is offline
It's always the programmer's fault.
no team
 
Join Date: May 2013
Rookie Year: 2010
Location: Earth
Posts: 268
Ozuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to behold
Re: [Snippet] Using 2+ Cameras with minimal bandwidth usage

Awesome code, this snippet will surely be helpful in the future. Thanks for sharing.
Reply With Quote
  #8   Spotlight this post!  
Unread 02-15-2016, 05:30 PM
RamTech 59 RamTech 59 is offline
RamTech 59
FRC #0059 (RamTech 59)
Team Role: Coach
 
Join Date: Jan 2016
Rookie Year: 1997
Location: Miami, FL
Posts: 9
RamTech 59 is an unknown quantity at this point
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?
Reply With Quote
  #9   Spotlight this post!  
Unread 02-15-2016, 07:06 PM
kmodos kmodos is offline
Registered User
AKA: Alex
FRC #1126 (SparX)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: New York
Posts: 57
kmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to beholdkmodos is a splendid one to behold
Re: [Snippet] Using 2+ Cameras with minimal bandwidth usage

Quote:
Originally Posted by RamTech 59 View Post
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.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


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

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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