Skip to content

FREAK : better rounding off for weighted dx and dy of orientation pairs #2440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions modules/xfeatures2d/src/freak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ void FREAK_Impl::buildPattern()
const float dx = patternLookup[orientationPairs[m].i].x-patternLookup[orientationPairs[m].j].x;
const float dy = patternLookup[orientationPairs[m].i].y-patternLookup[orientationPairs[m].j].y;
const float norm_sq = (dx*dx+dy*dy);
orientationPairs[m].weight_dx = int((dx/(norm_sq))*4096.0+0.5);
orientationPairs[m].weight_dy = int((dy/(norm_sq))*4096.0+0.5);
orientationPairs[m].weight_dx = cvRound((dx/(norm_sq))*4096.0);
orientationPairs[m].weight_dy = cvRound((dy/(norm_sq))*4096.0);
}

// build the list of description pairs
Expand Down Expand Up @@ -486,7 +486,7 @@ void FREAK_Impl::computeDescriptors( InputArray _image, std::vector<KeyPoint>& k
}
else
{
const int scIdx = std::max( (int)(1.0986122886681*sizeCst+0.5) ,0);
const int scIdx = std::max( cvRound(1.0986122886681*sizeCst) ,0);
for( size_t k = keypoints.size(); k--; )
{
kpScaleIdx[k] = scIdx; // equivalent to the formule when the scale is normalized with a constant size of keypoints[k].size=3*SMALLEST_KP_SIZE
Expand Down Expand Up @@ -543,10 +543,7 @@ void FREAK_Impl::computeDescriptors( InputArray _image, std::vector<KeyPoint>& k

keypoints[k].angle = static_cast<float>(atan2((float)direction1,(float)direction0)*(180.0/CV_PI));//estimate orientation

if(keypoints[k].angle < 0.f)
thetaIdx = int(FREAK_NB_ORIENTATION*keypoints[k].angle*(1/360.0)-0.5);
else
thetaIdx = int(FREAK_NB_ORIENTATION*keypoints[k].angle*(1/360.0)+0.5);
thetaIdx = cvRound(FREAK_NB_ORIENTATION*keypoints[k].angle*(1/360.0));

if( thetaIdx < 0 )
thetaIdx += FREAK_NB_ORIENTATION;
Expand Down Expand Up @@ -600,10 +597,7 @@ void FREAK_Impl::computeDescriptors( InputArray _image, std::vector<KeyPoint>& k

keypoints[k].angle = static_cast<float>(atan2((float)direction1,(float)direction0)*(180.0/CV_PI)); //estimate orientation

if(keypoints[k].angle < 0.f)
thetaIdx = int(FREAK_NB_ORIENTATION*keypoints[k].angle*(1/360.0)-0.5);
else
thetaIdx = int(FREAK_NB_ORIENTATION*keypoints[k].angle*(1/360.0)+0.5);
thetaIdx = cvRound(FREAK_NB_ORIENTATION*keypoints[k].angle*(1/360.0));

if( thetaIdx < 0 )
thetaIdx += FREAK_NB_ORIENTATION;
Expand Down Expand Up @@ -675,10 +669,10 @@ imgType FREAK_Impl::meanIntensity( InputArray _image, InputArray _integral,
// expected case:

// calculate borders
const int x_left = int(xf-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 y_bottom = int(yf+radius+1.5);//integral image is 1px higher
const int x_left = cvRound(xf-radius);
const int y_top = cvRound(yf-radius);
const int x_right = cvRound(xf+radius+1);//integral image is 1px wider
const int y_bottom = cvRound(yf+radius+1);//integral image is 1px higher
Comment on lines +672 to +675
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just cvFloor() / cvCeil()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suppose when xf-radius is 2.9 and 2.1, it will be more sensible to assign 3 and 2 respectively in x_left.

iiType ret_val;

ret_val = integral.at<iiType>(y_bottom,x_right);//bottom right corner
Expand Down