#include "fast/fast.h"
#include <stdlib.h>
#include "FASTCornerDetector.h"

void FASTCornerDetector::detect( const unsigned char* img, int w, int h )
{
	int numCorners;
	FastCorner* corners = fast_corner_detect_9( img, w, h, _threshold, &numCorners );

	FastCorner* detectedCorners = fast_nonmax( img, w, h, corners, numCorners, _threshold, &_numDetectedCorners );

	if( !detectedCorners )
	{
		_numDetectedCorners = 0;
	}

	_numDetectedCorners = _numDetectedCorners>_maxCorners?_maxCorners:_numDetectedCorners;
	for( int i = 0 ; i < _numDetectedCorners ; i ++ )
	{
		_detectedCorners[2*i]		= detectedCorners[i].x;
		_detectedCorners[2*i + 1]	= detectedCorners[i].y;
	}
	if( detectedCorners )
		free( detectedCorners );
	if( corners )
		free( corners );
}