I can't comment on the specifics of how to make your algorithm work (2702's is in a similar state of "nearly works"), but one way to test would be to save a bunch of JPGs from the camera, and then you can use them as test images or debug them intensively. We always found the most difficult part of testing the camera was reproducing what went wrong, and only this year at our last competition figured out how to get a good debugging going on.
Basically, you do something like this:
if(stick1.GetRawButton(1))
{
image->Write("savedimage.jpg");
}
To save your images. When the robot starts acting up, save the images to the cRio's internal storage with the button and retrieve them by FTP. Then, you can take a look in image-editing software to figure out the thresholds you need.
Then, modify the code so that instead of doing
Code:
ColorImage* image = new RGBImage;
camera.GetImage(image);
You do
Code:
ColorImage* image = new RGBImage("savedimage.jpg");
This way, your code will run on the saved test image and you'll be able to deduce precisely what went wrong.