Vision Code HELP!!!!

Hello,
I am trying to get our vision code to count the pixels in a certain region to see if the goal is hot.

/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.                             */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project.                                                               */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.camera.AxisCamera;
import edu.wpi.first.wpilibj.camera.AxisCameraException;
import edu.wpi.first.wpilibj.image.ColorImage;
import edu.wpi.first.wpilibj.image.NIVisionException;
import edu.wpi.first.wpilibj.image.BinaryImage;
import edu.wpi.first.wpilibj.image.CriteriaCollection;
import edu.wpi.first.wpilibj.image.ParticleAnalysisReport;
import com.sun.squawk.util.MathUtils;

/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the SimpleRobot
 * documentation. If you change the name of this class or the package after
 * creating this project, you must also update the manifest file in the resource
 * directory.
 */
public class RobotTemplate extends SimpleRobot {

    AxisCamera camera;
    public ColorImage image;
    public BinaryImage threshold;
    private int imageState;
    private boolean busy;
    public static final int left = 402;
    public static final int right = 456;
    public static final int top = 75;
    public static final int bottom = 99;
    public int countHotPixels = 0;
    public int count = 0;

    public RobotTemplate() {
        camera = AxisCamera.getInstance("10.20.28.11");
        camera.writeResolution(AxisCamera.ResolutionT.k640x480);
        camera.writeExposurePriority(AxisCamera.ExposurePriorityT.imageQuality);
        camera.writeExposureControl(AxisCamera.ExposureT.hold);
        camera.writeWhiteBalance(AxisCamera.WhiteBalanceT.fixedIndoor);
    }

    public void autonomous() {
    }

    /**
     * This function is called once each time the robot enters operator control.
     */
    public void operatorControl() {
        while (isEnabled() && isOperatorControl()) {
            try {
                switch (imageState) {
                    case 0:
                        busy = true;
                        image = camera.getImage();
//                        System.out.println("Got image");
                        imageState++;
                        busy = false;
                        break;
                    case 1:
                        busy = true;
                        threshold = image.thresholdRGB(0, 70, 185, 255, 145, 225);  // green values
//                        thresholdImage = image.thresholdHSV(115, 125, 195, 255, 220, 255);
                        image.free();
                        image = null;
//                        System.out.println("Got threshold");
                        imageState++;
                        busy = false;
                        break;
                    case 2:
                        busy = true;
                        for(int x = left; x <= right; x++)
                        {
                            for(int y = top; y <= bottom; y++)
                            {
                                byte pixel = threshold.image.getByte(x);
                                System.out.println("	Checking (" + x + ", " + y + ": " + pixel);
                                if(pixel != 0)
                                {
                                    countHotPixels++;
                                    count++;
                                    break;
                                }
                            }
                        }
                        imageState++;
                        busy = false;
                        threshold.free();
                        threshold = null;
                        break;
                    case 3:
                        System.out.println("Number hot pixels : " + countHotPixels);
                        busy = false;
                        imageState = 0;
                        break;
                }
                
            } catch (AxisCameraException ex) {
                ex.printStackTrace();
            } catch (NIVisionException ex) {
                ex.printStackTrace();
            }
            Timer.delay(0.1);
            getWatchdog().feed();
        }

    }

    /**
     * This function is called once each time the robot enters test mode.
     */
    public void test() {
    }
}

Every time I run this, I either get a NoImageAvailable exception on the image = camera.getImage() or I get a OffsetOutOfBounds exception on the byte pixel = threshold.image.getByte(x); I apologize for the poor formatting of this message. Any suggestions would be greatly appreciated

You should just try to capture one image (not in a while loop) and verify that it is there using FTP. Every time you capture an image it gets saved to the cRIO Flash, so you will run out of memory quickly if you continue to capture images within your while loop (unless you deleted it and I didn’t see that in your code).

My guess is that your exception is coming from not being able to store the image because you are out of memory (from previous runs of the program) or something else unrelated to your code. FTP into the device to see if there are any images saved.

Try testing the vision code that was handed to us with the latest Netbeans plugin. There is a sample program included (you can get to it by creating a new project and choosing samples)

The robot only tries to get an image the first time through the loop due to the switch statement. Once it has an image, it then processes it based on color and then it goes to the for loop, with each action one pass through the loop.

Did you get his figured out?
If not, take a look at two classes in javadocs. BinaryImage and ParticleAnalysisReport. You can save yourself a lot of work with these.
Good luck!