How to lower image pixels in straight NIVision code.

Okay we have had camera working at our tournaments, and have added laptop side processing in the Labview dashboard of the image to get the alignment to the goal, which is sent back to the roborio.

At first we were using the following code to send the image.
camera = CameraServer.getInstance();
camera.setSize(2/camera.kSize320x240/);
camera.setImage(Image.SCALE_FAST);
camera.setQuality(100);
camera.startAutomaticCapture(“cam0”);

But we were running 90% to 100% pegged CPU.

By changing to the following code it now is running a more reasonable 40% to 60% CPU. But we are only getting 1.9 frame per second. I would like to lower the pixels in the picture, but don’t know the how to in straight NIVision code. Any pointers in the right direction would be appreciated.

public class Robot extends IterativeRobot {


int countToTakePicture = 20;
int currentCountToTakePicture = 0;


public void teleopPeriodic() {
Scheduler.getInstance().run();
boolean takePicture = false;
if(currentCountToTakePicture == countToTakePicture){
takePicture = true;
}
else if(currentCountToTakePicture <= countToTakePicture){
currentCountToTakePicture++;
} else {
currentCountToTakePicture = 0;
}

    if (takePicture){
    	int session;
    	session = NIVision.IMAQdxOpenCamera("cam0",NIVision.IMAQdxCameraControlMode.CameraControlModeController);
    	NIVision.IMAQdxStartAcquisition(session);
    	Image frame = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_RGB, 0);
    	NIVision.IMAQdxGrab(session, frame, 10);
    	cameraServer.getInstance().setImage(frame);
    	NIVision.IMAQdxStopAcquisition(session);
    	NIVision.IMAQdxCloseCamera(session);

    	// from cheifdelphi Program crashes with out of memory issue if we remove this line
    	frame.free();
    }

Lower priority items:
Also should probably do a more controlled way on when to take the picture.

Also thinking about copying it into auton so can autoalign for our low goal, I dont anticipate any problems but, my lack of full understanding of NIVision makes me worry, should I?

What I would recommend is decreasing camera.setQuality(100) to camera.setQuality(50). In my opinion, 100 is too much for the CPU to handle, plus, this is what our team’s code has in terms of the quality.

You can use imaqScale or imaqResize. imaqScale will change your image width and height to a factor or multiple of the original width and height, while imaqResize will change it to any arbitrary size. I would recommend imaqScale because I’d assume it’s faster.

Also, you don’t need to keep deleting and recreating Image objects (as in your second code snippet). You can use the same image object multiple times for camera capture with IMAQdx