code/PostSeason/Breakaway/Target.cpp
/**
 * Find the best circular target in the image.
 * The best target is the one with two concentric circles, largest size, and best score
 * @param image The image to examine.
 * @returns A target object with the parameters filled in.
 */
Find the best circular target in the image.
The best target is the one with two concentric circles, largest size, and best score
@param image The image to examine.
@returns A target object with the parameters filled in.
Find the best circular target in the image . The best target is the one with two concentric circles largest size and best score @param image The image to examine . @returns A target object with the parameters filled in .
vector<Target> Target::FindCircularTargets(HSLImage *image)
{
	int width = image->GetWidth();
	int height = image->GetHeight();
	vector<Target> sortedTargets;
	MonoImage  *luminancePlane = image->GetLuminancePlane();
	vector<EllipseMatch> *results = luminancePlane->DetectEllipses(&ellipseDescriptor, 
																	&curveOptions,
																	&shapeOptions,
																	NULL);
	delete luminancePlane;
	if (results->size() == 0)
	{
		return sortedTargets;
	}
	for (unsigned i = 0; i < results->size(); i++)
	{
		Target target;
		EllipseMatch e = results->at(i);
		target.m_rawScore = e.score;
		target.m_score = (e.majorRadius * e.minorRadius)
							/ (1001 - e.score)
							/ (height * width) * 100;
		target.m_majorRadius = e.majorRadius / height;
		target.m_minorRadius = e.minorRadius / height;
		target.m_xPos = (2.0 * e.position.x - width) / height;
		target.m_yPos = (2.0 * e.position.y - height) / height;
		target.m_rotation = e.rotation;
		target.m_xMax = (double)width / height;
		target.m_bothFound = false;
		sortedTargets.push_back(target);
	}
	delete results;
	sort(sortedTargets.begin(), sortedTargets.end(), compareTargets);
	vector<Target> combinedTargets;
	while (sortedTargets.size() > 0)
	{
		vector<Target>::iterator iter = sortedTargets.begin();
		Target t1 = *iter++;
		for (; iter < sortedTargets.end(); iter++)
		{
			Target t2 = *iter;
			if ((fabs(t1.m_xPos - t2.m_xPos) < min(t1.m_minorRadius, t2.m_minorRadius)) &&
					(fabs(t1.m_yPos - t2.m_yPos) < min(t1.m_majorRadius, t2.m_majorRadius)))
			{
				t1.m_xPos = (t1.m_xPos + t2.m_xPos) / 2;
				t1.m_yPos = (t1.m_yPos + t2.m_yPos) / 2;
				t1.m_rawScore += t2.m_rawScore;
				t1.m_score = (t1.m_score + t2.m_score) * 2.0;  
				t1.m_majorRadius = max(t1.m_majorRadius, t2.m_majorRadius);
				t1.m_minorRadius = max(t1.m_minorRadius, t2.m_minorRadius);
				t1.m_bothFound = true;
				sortedTargets.erase(iter); 
				break;
			}
		}
		sortedTargets.erase(sortedTargets.begin());
			combinedTargets.push_back(t1);
	}
	sort(combinedTargets.begin(), combinedTargets.end(), compareTargets);
	return combinedTargets;
}
vector < Target > Target :: FindCircularTargets ( HSLImage * image ) { int width = image -> GetWidth ( ) ; int height = image -> GetHeight ( ) ; vector < Target > sortedTargets ; MonoImage * luminancePlane = image -> GetLuminancePlane ( ) ; vector < EllipseMatch > * results = luminancePlane -> DetectEllipses ( & ellipseDescriptor , & curveOptions , & shapeOptions , NULL ) ; delete luminancePlane ; if ( results -> size ( ) == 0 ) { return sortedTargets ; } for ( unsigned i = 0 ; i < results -> size ( ) ; i ++ ) { Target target ; EllipseMatch e = results -> at ( i ) ; target . m_rawScore = e . score ; target . m_score = ( e . majorRadius * e . minorRadius ) / ( 1001 - e . score ) / ( height * width ) * 100 ; target . m_majorRadius = e . majorRadius / height ; target . m_minorRadius = e . minorRadius / height ; target . m_xPos = ( 2.0 * e . position . x - width ) / height ; target . m_yPos = ( 2.0 * e . position . y - height ) / height ; target . m_rotation = e . rotation ; target . m_xMax = ( double ) width / height ; target . m_bothFound = false ; sortedTargets . push_back ( target ) ; } delete results ; sort ( sortedTargets . begin ( ) , sortedTargets . end ( ) , compareTargets ) ; vector < Target > combinedTargets ; while ( sortedTargets . size ( ) > 0 ) { vector < Target > :: iterator iter = sortedTargets . begin ( ) ; Target t1 = * iter ++ ; for ( ; iter < sortedTargets . end ( ) ; iter ++ ) { Target t2 = * iter ; if ( ( fabs ( t1 . m_xPos - t2 . m_xPos ) < min ( t1 . m_minorRadius , t2 . m_minorRadius ) ) && ( fabs ( t1 . m_yPos - t2 . m_yPos ) < min ( t1 . m_majorRadius , t2 . m_majorRadius ) ) ) { t1 . m_xPos = ( t1 . m_xPos + t2 . m_xPos ) / 2 ; t1 . m_yPos = ( t1 . m_yPos + t2 . m_yPos ) / 2 ; t1 . m_rawScore += t2 . m_rawScore ; t1 . m_score = ( t1 . m_score + t2 . m_score ) * 2.0 ; t1 . m_majorRadius = max ( t1 . m_majorRadius , t2 . m_majorRadius ) ; t1 . m_minorRadius = max ( t1 . m_minorRadius , t2 . m_minorRadius ) ; t1 . m_bothFound = true ; sortedTargets . erase ( iter ) ; break ; } } sortedTargets . erase ( sortedTargets . begin ( ) ) ; combinedTargets . push_back ( t1 ) ; } sort ( combinedTargets . begin ( ) , combinedTargets . end ( ) , compareTargets ) ; return combinedTargets ; }
Find the best circular target in the image.
Find the best circular target in the image .
// get the luminance plane only for the image to make the code // insensitive to lighting conditions. // create a list of targets corresponding to each ellipse found // in the image. //always divide by height so that x and y are same units // sort the list of targets by score // go through each target found in descending score order and look // for another target whose center is contained inside of this target // Those concentric targets get a score which is the sum of both targets // check if the two are concentric // create the information for the combined target // (the 2 concentric ellipses) // add a 2x bonus for concentric // loop needs to be an interator //		if (t1.m_bothFound) // sort the combined targets so the highest scoring one is first