Fix fixed-point arithmetics in FREAK::meanIntensity

This commit is contained in:
Corentin Wallez 2012-08-21 23:45:12 +02:00 committed by Vadim Pisarevsky
parent dc6fa94118
commit 18fc11bc04

View File

@ -455,7 +455,6 @@ uchar FREAK::meanIntensity( const cv::Mat& image, const cv::Mat& integral,
const float radius = FreakPoint.sigma; const float radius = FreakPoint.sigma;
// calculate output: // calculate output:
int ret_val;
if( radius < 0.5 ) { if( radius < 0.5 ) {
// interpolation multipliers: // interpolation multipliers:
const int r_x = static_cast<int>((xf-x)*1024); const int r_x = static_cast<int>((xf-x)*1024);
@ -463,6 +462,7 @@ uchar FREAK::meanIntensity( const cv::Mat& image, const cv::Mat& integral,
const int r_x_1 = (1024-r_x); const int r_x_1 = (1024-r_x);
const int r_y_1 = (1024-r_y); const int r_y_1 = (1024-r_y);
uchar* ptr = image.data+x+y*imagecols; uchar* ptr = image.data+x+y*imagecols;
unsigned int ret_val;
// linear interpolation: // linear interpolation:
ret_val = (r_x_1*r_y_1*int(*ptr)); ret_val = (r_x_1*r_y_1*int(*ptr));
ptr++; ptr++;
@ -471,7 +471,9 @@ uchar FREAK::meanIntensity( const cv::Mat& image, const cv::Mat& integral,
ret_val += (r_x*r_y*int(*ptr)); ret_val += (r_x*r_y*int(*ptr));
ptr--; ptr--;
ret_val += (r_x_1*r_y*int(*ptr)); ret_val += (r_x_1*r_y*int(*ptr));
return static_cast<uchar>((ret_val+512)/1024); //return the rounded mean
ret_val += 2 * 1024 * 1024;
return static_cast<uchar>(ret_val / (4 * 1024 * 1024));
} }
// expected case: // expected case:
@ -481,6 +483,7 @@ uchar FREAK::meanIntensity( const cv::Mat& image, const cv::Mat& integral,
const int y_top = int(yf-radius+0.5); const int y_top = int(yf-radius+0.5);
const int x_right = int(xf+radius+1.5);//integral image is 1px wider const int x_right = int(xf+radius+1.5);//integral image is 1px wider
const int y_bottom = int(yf+radius+1.5);//integral image is 1px higher const int y_bottom = int(yf+radius+1.5);//integral image is 1px higher
int ret_val;
ret_val = integral.at<int>(y_bottom,x_right);//bottom right corner ret_val = integral.at<int>(y_bottom,x_right);//bottom right corner
ret_val -= integral.at<int>(y_bottom,x_left); ret_val -= integral.at<int>(y_bottom,x_left);