Quote:
|
Originally Posted by nm4
I am having trouble caleberating the camera. The vision is working perfectly fine, but it doesnt detect colors. If I try to search for a color it says ERROR. please try to get back to me if u can?
THANK YOU
|
We wrote our own calibration routines that increment the exposure values and print out the TC packets. Then we set our exposure based on the maximum confidence. It works a lot better than the java GUI. Below is the routine although it's only been coded for GREEN. We also got much better results when we debounced the tracking flag to drop out on 3 consecutive packets that didn't meet the minimum pixel (AKA cam.count ) criteria. Cam is working super for us here on team 11. (M.O.R.T.) We're using the camera servo position and a multiplier for active feedback to the drive train and have multiple virtual windows ("VW") and multiple servo pan settings from coarse to superfine( "SP");
void find_exposure( int color )
{
if(calibrate_running == 0) {
camera_stop(); // Stop the camera if it is already tracking
camera_reset(); // Reset the camera, and make sure it reset (actually check for true return)
camera_const_cmd(noise_filter); // Enable the same noise filter for all tracking
camera_const_cmd(raw_mode); // Put into raw mode, this makes it send output numbers as bytes instead
camera_const_cmd(virtual_window);
calibrate_running = 1;
printf("Calibrating for ");
switch(color) {
case GREEN:
printf("GREEN\r");
camera_const_cmd(aec_disable ); // Disable AEC
camera_const_cmd(manual_agc ); // Enable manual AEC and AGC
camera_const_cmd(noise_filter ); // Set noise filter to 6 pixels
camera_const_cmd(raw_mode ); // Set camera output to BINARY
camera_const_cmd(virtual_window); // Set virtual window
camera_const_cmd(yCrCb_mode); // Set yCrCb mode
camera_set_exposure(0); // Set manual exposure value
camera_const_cmd(track_green);
best_confidence = 0;
best_exposure = 0;
one_second_delay = 0;
break;
default:
return;
}
return;
}
if(exposure_val == 255) {
printf("Best Exposure is %d, Best Confidence is %d\r", best_exposure, best_confidence);
camera_stop();
camera_set_exposure( best_exposure );
camera_auto_servo(SUPERFINE_TRACKING, SUPERFINE_TRACKING); // Pan.servo = COARSE, Tilt still COARSE
camera_const_cmd("TC");
parse_mode = 1;
while(1);
}
if(camera_track_update( )) // If we have a new frame
{
num_of_frames++;
// printf("Exposure= %03d Pixel Count = %03d, Confidence = %03d\r", exposure_val, cam.count, cam.conf);
if( cam.count > 1 ) {
num_of_samples++;
confidence_average += cam.conf;
pixel_average += cam.count;
}
}
if(one_second_delay++ >= 9) {
one_second_delay = 0;
pixel_average = pixel_average/num_of_samples;
if(pixel_average < 0 ) pixel_average = 0;
confidence_average = confidence_average/num_of_samples;
if(confidence_average < 0 ) confidence_average = 0;
printf("FPS= %03d Exposure = %03d, Pixel Average = %03d, Conf Average = %03d\r", num_of_frames * 4, exposure_val, pixel_average, confidence_average);
if ((confidence_average/num_of_samples) > best_confidence ) {
best_confidence = confidence_average/num_of_samples;
best_exposure = exposure_val;
}
exposure_val++;
num_of_samples = 0;
num_of_frames= 0;
confidence_average = 0;
pixel_average = 0;
camera_stop();
camera_set_exposure( exposure_val );
camera_const_cmd("TC");
parse_mode = 1;
}
}