View Single Post
  #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