Basically, you want to look at the ratio of width (x2-x1) to height (y2-y1). This will tell you if there are two lights.
Something else you can look at as well is the number of pixels (the variable is called "pixels")... and it's ratio to the area width*height... unfortunately keep in mind that these are all unsigned chars, so it means that the limit is 255 for all values.
I'm pasting the EasyC example code segment about how the demo determined if it was one or two lights:
Code:
#define MIN_REGION 0
#define WIDEST_ONE_LIGHT 30
#define HALF_LIGHT_WIDTH 3
...
// get data from camera
CaptureTrackingData ( ¢roid_x , ¢roid_y , &upleft_x , &upleft_y , &lowright_x , &lowright_y , ®ion_size , &confidence , 0 , 0 ) ;
targets = 0;
if ( region_size > MIN_REGION ) { // Check if we're locked
icentroid_x = (int)centroid_x ; // move into integer variable
int target_width = lowright_x - upleft_x ; // Horizontal extents of bounding box
if ( target_width > WIDEST_ONE_LIGHT ) { // looking at two lights?
targets = 2;
// pick the closer one of the two lights.
if ( ( lowright_x - centroid_x) < (centroid_x - upleft_x) ) {
// the centroid is nearer the right
target_x = lowright_x- HALF_LIGHT_WIDTH ;
} else {
// the centroid is nearer the left
target_x = upleft_x + HALF_LIGHT_WIDTH ;
}
} else { // the target is NOT wide, it's one light
targets = 1;
target_x = icentroid_x; // target that light
}
That code basically checked if the width was greater than a constant, and then decided it was two targets instead of one.
Now, I would suggest aiming for the *opposite side* of the median, which, when you are exactly at the middle, will be the same as the center coordinate:
(lowright_x + upleft_x - icentroid_x) -- that is... the flip image of the centroid...
or in normal C, it would be (x2 + x1 - mx)
__________________
-Patrick Horn,
Paly Robotics
Check out the space simulator called
Vega Strike, modelled after the space simulator games Elite and Wing Commander. It's Open Source too!
If you have ever played
Wing Commander, or especially
Privateer, and had a feeling of nostalga derived from the you will enjoy these two Vega Strike mods:
Privateer Gemini Gold and
Privateer Remake!
I'm working on adding multiplayer support this year...