Image tracking code: colors off? (Lighting)

Hi all,
I’m writing code to lock onto targets, based off of the example two-color tracking code which used servos (but our robot uses a turret instead). It is very intermittent in finding the two colors, except when someone shines a bright light on it. Has anyone had any similar troubles/have any proposed solutions? Here’s a bit of our code which I think is relevant:


	// Initialize particle analysis report
	memset(&par, 0, sizeof(par));
	
	// Image data for tracking - override default parameters if needed:
	// Make PINK the first color because GREEN is more susceptible to
	// hue variations due to lighting so may result in false positives
	
	// PINK
	sprintf(td1.name, "PINK");
	td1.hue.minValue = 220;
	td1.hue.maxValue = 255;
	td1.saturation.minValue = 75;
	td1.saturation.maxValue = 255;
	td1.luminance.minValue = 85;
	td1.luminance.maxValue = 255;
	
	// GREEN
	sprintf(td2.name, "GREEN");
	td2.hue.minValue = 55;
	td2.hue.maxValue = 125;
	td2.saturation.minValue = 58;
	td2.saturation.maxValue = 255;
	td2.luminance.minValue = 92;
	td2.luminance.maxValue = 255;
	
	// Set up debug output: 
	// DEBUG_OFF, DEBUG_MOSTLY_OFF, DEBUG_SCREEN_ONLY, DEBUG_FILE_ONLY, DEBUG_SCREEN_AND_FILE
	SetDebugFlag(DEBUG_SCREEN_ONLY);
	
	// Start the CameraTask
	// Possible values for resolution: k640x480, k320x240, k160x120
	if(StartCameraTask(framesPerSecond, 0, k160x120, ROT_0) == -1)
	{
		printf("Failed to spawn camera task; exiting. Error code %s", 
				GetVisionErrorText(GetLastVisionError()));
	}

The default color thresholds were selected to fit many lighting conditions, but some conditions are harder than others. Here is what I’d do to troubleshoot this.

Use the Vision Assistant or Web Config tool to take some images in locations and conditions which have problems.

Load the images into the Vision Assistant.
Double click on the line profile step.
In the image display, click twice to draw a line through the target. If you miss, click away and do it again.
Once you have a line through the image, go to the configuration RGB ring above the graph and change it to HSL.

You have to watch the legend pretty closely, but this is a really good way for getting a feel of what the light is doing on the target. Anyway, this will indicate which of the numbers are missing the threshold.

Finally, I’ll mention some camera stuff that can help with those difficult conditions. If the room is a bit dark, especially if there is backlighting, you may want to raise the Brightness value on the camera. This will overexpose the lights but will increase the light on the targets, and that is what you care about.

Feel free to post the images if you have problems. And by the way, the events are really bright. So be sure to put it back when the light gets brighter.

Greg McKaskle