Skip to content

Commit 9c0ae27

Browse files
authored
Merge pull request #2440 from raanyild:freak_rounding_bug
* FREAK : better rounding off for weighted dx and dy of orientation pairs * updated using cvRound * cvRound modified
1 parent f220e98 commit 9c0ae27

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

modules/xfeatures2d/src/freak.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ void FREAK_Impl::buildPattern()
287287
const float dx = patternLookup[orientationPairs[m].i].x-patternLookup[orientationPairs[m].j].x;
288288
const float dy = patternLookup[orientationPairs[m].i].y-patternLookup[orientationPairs[m].j].y;
289289
const float norm_sq = (dx*dx+dy*dy);
290-
orientationPairs[m].weight_dx = int((dx/(norm_sq))*4096.0+0.5);
291-
orientationPairs[m].weight_dy = int((dy/(norm_sq))*4096.0+0.5);
290+
orientationPairs[m].weight_dx = cvRound((dx/(norm_sq))*4096.0);
291+
orientationPairs[m].weight_dy = cvRound((dy/(norm_sq))*4096.0);
292292
}
293293

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

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

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

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

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

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

608602
if( thetaIdx < 0 )
609603
thetaIdx += FREAK_NB_ORIENTATION;
@@ -675,10 +669,10 @@ imgType FREAK_Impl::meanIntensity( InputArray _image, InputArray _integral,
675669
// expected case:
676670

677671
// calculate borders
678-
const int x_left = int(xf-radius+0.5);
679-
const int y_top = int(yf-radius+0.5);
680-
const int x_right = int(xf+radius+1.5);//integral image is 1px wider
681-
const int y_bottom = int(yf+radius+1.5);//integral image is 1px higher
672+
const int x_left = cvRound(xf-radius);
673+
const int y_top = cvRound(yf-radius);
674+
const int x_right = cvRound(xf+radius+1);//integral image is 1px wider
675+
const int y_bottom = cvRound(yf+radius+1);//integral image is 1px higher
682676
iiType ret_val;
683677

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

0 commit comments

Comments
 (0)