Skip to content

Commit 73c3d14

Browse files
committed
akaze: fRound -> cvRound, fix bilinear interpolation
1 parent f6ceeaa commit 73c3d14

File tree

3 files changed

+48
-78
lines changed

3 files changed

+48
-78
lines changed

modules/features2d/src/kaze/AKAZEFeatures.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ void AKAZEFeatures::Allocate_Memory_Evolution(void) {
7474
Evolution step;
7575
step.size = Size(level_width, level_height);
7676
step.esigma = options_.soffset*pow(2.f, (float)(j) / (float)(options_.nsublevels) + i);
77-
step.sigma_size = fRound(step.esigma * options_.derivative_factor / power); // In fact sigma_size only depends on j
77+
step.sigma_size = cvRound(step.esigma * options_.derivative_factor / power); // In fact sigma_size only depends on j
7878
step.etime = 0.5f * (step.esigma * step.esigma);
7979
step.octave = i;
8080
step.sublevel = j;
8181
step.octave_ratio = (float)power;
82-
step.border = fRound(smax * step.sigma_size) + 1;
82+
step.border = cvRound(smax * step.sigma_size) + 1;
8383

8484
evolution_.push_back(step);
8585
}
@@ -1301,9 +1301,9 @@ void Compute_Main_Orientation(KeyPoint& kpt, const std::vector<Evolution>& evolu
13011301
// get the right evolution level for this keypoint
13021302
const Evolution& e = evolution[kpt.class_id];
13031303
// Get the information from the keypoint
1304-
int scale = fRound(0.5f * kpt.size / e.octave_ratio);
1305-
int x0 = fRound(kpt.pt.x / e.octave_ratio);
1306-
int y0 = fRound(kpt.pt.y / e.octave_ratio);
1304+
int scale = cvRound(0.5f * kpt.size / e.octave_ratio);
1305+
int x0 = cvRound(kpt.pt.x / e.octave_ratio);
1306+
int y0 = cvRound(kpt.pt.y / e.octave_ratio);
13071307

13081308
// Sample derivatives responses for the points within radius of 6*scale
13091309
const int ang_size = 109;
@@ -1443,7 +1443,7 @@ void MSURF_Upright_Descriptor_64_Invoker::Get_MSURF_Upright_Descriptor_64(const
14431443

14441444
// Get the information from the keypoint
14451445
ratio = (float)(1 << kpt.octave);
1446-
scale = fRound(0.5f*kpt.size / ratio);
1446+
scale = cvRound(0.5f*kpt.size / ratio);
14471447
const int level = kpt.class_id;
14481448
Mat Lx = evolution[level].Mx;
14491449
Mat Ly = evolution[level].My;
@@ -1572,8 +1572,8 @@ void MSURF_Descriptor_64_Invoker::Get_MSURF_Descriptor_64(const KeyPoint& kpt, f
15721572

15731573
// Get the information from the keypoint
15741574
ratio = (float)(1 << kpt.octave);
1575-
scale = fRound(0.5f*kpt.size / ratio);
1576-
angle = (kpt.angle * static_cast<float>(CV_PI)) / 180.f;
1575+
scale = cvRound(0.5f*kpt.size / ratio);
1576+
angle = kpt.angle * static_cast<float>(CV_PI / 180.f);
15771577
const int level = kpt.class_id;
15781578
Mat Lx = evolution[level].Mx;
15791579
Mat Ly = evolution[level].My;
@@ -1613,11 +1613,11 @@ void MSURF_Descriptor_64_Invoker::Get_MSURF_Descriptor_64(const KeyPoint& kpt, f
16131613
// Get the gaussian weighted x and y responses
16141614
gauss_s1 = gaussian(xs - sample_x, ys - sample_y, 2.5f*scale);
16151615

1616-
y1 = fRound(sample_y - 0.5f);
1617-
x1 = fRound(sample_x - 0.5f);
1616+
y1 = cvRound(sample_y - 0.5f);
1617+
x1 = cvRound(sample_x - 0.5f);
16181618

1619-
y2 = fRound(sample_y + 0.5f);
1620-
x2 = fRound(sample_x + 0.5f);
1619+
y2 = cvRound(sample_y + 0.5f);
1620+
x2 = cvRound(sample_x + 0.5f);
16211621

16221622
// fix crash: indexing with out-of-bounds index, this might happen near the edges of image
16231623
// clip values so they fit into the image
@@ -1706,7 +1706,7 @@ void Upright_MLDB_Full_Descriptor_Invoker::Get_Upright_MLDB_Full_Descriptor(cons
17061706

17071707
// Get the information from the keypoint
17081708
ratio = (float)(1 << kpt.octave);
1709-
scale = fRound(0.5f*kpt.size / ratio);
1709+
scale = cvRound(0.5f*kpt.size / ratio);
17101710
const int level = kpt.class_id;
17111711
Mat Lx = evolution[level].Mx;
17121712
Mat Ly = evolution[level].My;
@@ -1741,8 +1741,8 @@ void Upright_MLDB_Full_Descriptor_Invoker::Get_Upright_MLDB_Full_Descriptor(cons
17411741
sample_y = yf + l*scale;
17421742
sample_x = xf + k*scale;
17431743

1744-
y1 = fRound(sample_y);
1745-
x1 = fRound(sample_x);
1744+
y1 = cvRound(sample_y);
1745+
x1 = cvRound(sample_x);
17461746

17471747
ri = *(Lt.ptr<float>(y1)+x1);
17481748
rx = *(Lx.ptr<float>(y1)+x1);
@@ -1810,8 +1810,8 @@ void MLDB_Full_Descriptor_Invoker::MLDB_Fill_Values(float* values, int sample_st
18101810
float sample_y = yf + (l*co * scale + k*si*scale);
18111811
float sample_x = xf + (-l*si * scale + k*co*scale);
18121812

1813-
int y1 = fRound(sample_y);
1814-
int x1 = fRound(sample_x);
1813+
int y1 = cvRound(sample_y);
1814+
int x1 = cvRound(sample_x);
18151815

18161816
// fix crash: indexing with out-of-bounds index, this might happen near the edges of image
18171817
// clip values so they fit into the image
@@ -1900,10 +1900,10 @@ void MLDB_Full_Descriptor_Invoker::Get_MLDB_Full_Descriptor(const KeyPoint& kpt,
19001900
};
19011901

19021902
float ratio = (float)(1 << kpt.octave);
1903-
float scale = (float)fRound(0.5f*kpt.size / ratio);
1903+
float scale = (float)cvRound(0.5f*kpt.size / ratio);
19041904
float xf = kpt.pt.x / ratio;
19051905
float yf = kpt.pt.y / ratio;
1906-
float angle = (kpt.angle * static_cast<float>(CV_PI)) / 180.f;
1906+
float angle = kpt.angle * static_cast<float>(CV_PI / 180.f);
19071907
float co = cos(angle);
19081908
float si = sin(angle);
19091909

@@ -1941,8 +1941,8 @@ void MLDB_Descriptor_Subset_Invoker::Get_MLDB_Descriptor_Subset(const KeyPoint&
19411941

19421942
// Get the information from the keypoint
19431943
float ratio = (float)(1 << kpt.octave);
1944-
int scale = fRound(0.5f*kpt.size / ratio);
1945-
float angle = (kpt.angle * static_cast<float>(CV_PI)) / 180.f;
1944+
int scale = cvRound(0.5f*kpt.size / ratio);
1945+
float angle = kpt.angle * static_cast<float>(CV_PI / 180.f);
19461946
const int level = kpt.class_id;
19471947
Mat Lx = evolution[level].Mx;
19481948
Mat Ly = evolution[level].My;
@@ -1983,8 +1983,8 @@ void MLDB_Descriptor_Subset_Invoker::Get_MLDB_Descriptor_Subset(const KeyPoint&
19831983
sample_y = yf + (l*scale*co + k*scale*si);
19841984
sample_x = xf + (-l*scale*si + k*scale*co);
19851985

1986-
y1 = fRound(sample_y);
1987-
x1 = fRound(sample_x);
1986+
y1 = cvRound(sample_y);
1987+
x1 = cvRound(sample_x);
19881988

19891989
di += *(Lt.ptr<float>(y1)+x1);
19901990

@@ -2049,7 +2049,7 @@ void Upright_MLDB_Descriptor_Subset_Invoker::Get_Upright_MLDB_Descriptor_Subset(
20492049

20502050
// Get the information from the keypoint
20512051
float ratio = (float)(1 << kpt.octave);
2052-
int scale = fRound(0.5f*kpt.size / ratio);
2052+
int scale = cvRound(0.5f*kpt.size / ratio);
20532053
const int level = kpt.class_id;
20542054
Mat Lx = evolution[level].Mx;
20552055
Mat Ly = evolution[level].My;
@@ -2081,8 +2081,8 @@ void Upright_MLDB_Descriptor_Subset_Invoker::Get_Upright_MLDB_Descriptor_Subset(
20812081
sample_y = yf + l*scale;
20822082
sample_x = xf + k*scale;
20832083

2084-
y1 = fRound(sample_y);
2085-
x1 = fRound(sample_x);
2084+
y1 = cvRound(sample_y);
2085+
x1 = cvRound(sample_x);
20862086
di += *(Lt.ptr<float>(y1)+x1);
20872087

20882088
if (options.descriptor_channels > 1) {

modules/features2d/src/kaze/KAZEFeatures.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void KAZEFeatures::Allocate_Memory_Evolution(void) {
6868
aux.Ldet = Mat::zeros(options_.img_height, options_.img_width, CV_32F);
6969
aux.esigma = options_.soffset*pow((float)2.0f, (float)(j) / (float)(options_.nsublevels)+i);
7070
aux.etime = 0.5f*(aux.esigma*aux.esigma);
71-
aux.sigma_size = fRound(aux.esigma);
71+
aux.sigma_size = cvRound(aux.esigma);
7272
aux.octave = i;
7373
aux.sublevel = j;
7474
evolution_.push_back(aux);
@@ -363,10 +363,10 @@ void KAZEFeatures::Determinant_Hessian(std::vector<KeyPoint>& kpts)
363363

364364
if (is_extremum == true) {
365365
// Check that the point is under the image limits for the descriptor computation
366-
left_x = fRound(kpts_par_[i][j].pt.x - smax*kpts_par_[i][j].size);
367-
right_x = fRound(kpts_par_[i][j].pt.x + smax*kpts_par_[i][j].size);
368-
up_y = fRound(kpts_par_[i][j].pt.y - smax*kpts_par_[i][j].size);
369-
down_y = fRound(kpts_par_[i][j].pt.y + smax*kpts_par_[i][j].size);
366+
left_x = cvRound(kpts_par_[i][j].pt.x - smax*kpts_par_[i][j].size);
367+
right_x = cvRound(kpts_par_[i][j].pt.x + smax*kpts_par_[i][j].size);
368+
up_y = cvRound(kpts_par_[i][j].pt.y - smax*kpts_par_[i][j].size);
369+
down_y = cvRound(kpts_par_[i][j].pt.y + smax*kpts_par_[i][j].size);
370370

371371
if (left_x < 0 || right_x >= evolution_[level].Ldet.cols ||
372372
up_y < 0 || down_y >= evolution_[level].Ldet.rows) {
@@ -587,14 +587,14 @@ void KAZEFeatures::Compute_Main_Orientation(KeyPoint &kpt, const std::vector<TEv
587587
xf = kpt.pt.x;
588588
yf = kpt.pt.y;
589589
level = kpt.class_id;
590-
s = fRound(kpt.size / 2.0f);
590+
s = cvRound(kpt.size / 2.0f);
591591

592592
// Calculate derivatives responses for points within radius of 6*scale
593593
for (int i = -6; i <= 6; ++i) {
594594
for (int j = -6; j <= 6; ++j) {
595595
if (i*i + j*j < 36) {
596-
iy = fRound(yf + j*s);
597-
ix = fRound(xf + i*s);
596+
iy = cvRound(yf + j*s);
597+
ix = cvRound(xf + i*s);
598598

599599
if (iy >= 0 && iy < options.img_height && ix >= 0 && ix < options.img_width) {
600600
gweight = gaussian(iy - yf, ix - xf, 2.5f*s);
@@ -676,7 +676,7 @@ void KAZE_Descriptor_Invoker::Get_KAZE_Upright_Descriptor_64(const KeyPoint &kpt
676676
// Get the information from the keypoint
677677
yf = kpt.pt.y;
678678
xf = kpt.pt.x;
679-
scale = fRound(kpt.size / 2.0f);
679+
scale = cvRound(kpt.size / 2.0f);
680680
level = kpt.class_id;
681681

682682
i = -8;
@@ -804,8 +804,8 @@ void KAZE_Descriptor_Invoker::Get_KAZE_Descriptor_64(const KeyPoint &kpt, float
804804
// Get the information from the keypoint
805805
yf = kpt.pt.y;
806806
xf = kpt.pt.x;
807-
scale = fRound(kpt.size / 2.0f);
808-
angle = (kpt.angle * static_cast<float>(CV_PI)) / 180.f;
807+
scale = cvRound(kpt.size / 2.0f);
808+
angle = kpt.angle * static_cast<float>(CV_PI / 180.f);
809809
level = kpt.class_id;
810810
co = cos(angle);
811811
si = sin(angle);
@@ -843,13 +843,13 @@ void KAZE_Descriptor_Invoker::Get_KAZE_Descriptor_64(const KeyPoint &kpt, float
843843

844844
// Get the gaussian weighted x and y responses
845845
gauss_s1 = gaussian(xs - sample_x, ys - sample_y, 2.5f*scale);
846-
y1 = fRound(sample_y - 0.5f);
847-
x1 = fRound(sample_x - 0.5f);
846+
y1 = cvFloor(sample_y);
847+
x1 = cvFloor(sample_x);
848848

849849
checkDescriptorLimits(x1, y1, options_.img_width, options_.img_height);
850850

851-
y2 = (int)(sample_y + 0.5f);
852-
x2 = (int)(sample_x + 0.5f);
851+
y2 = y1 + 1;
852+
x2 = x1 + 1;
853853

854854
checkDescriptorLimits(x2, y2, options_.img_width, options_.img_height);
855855

@@ -935,7 +935,7 @@ void KAZE_Descriptor_Invoker::Get_KAZE_Upright_Descriptor_128(const KeyPoint &kp
935935
// Get the information from the keypoint
936936
yf = kpt.pt.y;
937937
xf = kpt.pt.x;
938-
scale = fRound(kpt.size / 2.0f);
938+
scale = cvRound(kpt.size / 2.0f);
939939
level = kpt.class_id;
940940

941941
i = -8;
@@ -1087,8 +1087,8 @@ void KAZE_Descriptor_Invoker::Get_KAZE_Descriptor_128(const KeyPoint &kpt, float
10871087
// Get the information from the keypoint
10881088
yf = kpt.pt.y;
10891089
xf = kpt.pt.x;
1090-
scale = fRound(kpt.size / 2.0f);
1091-
angle = (kpt.angle * static_cast<float>(CV_PI)) / 180.f;
1090+
scale = cvRound(kpt.size / 2.0f);
1091+
angle = kpt.angle * static_cast<float>(CV_PI / 180.f);
10921092
level = kpt.class_id;
10931093
co = cos(angle);
10941094
si = sin(angle);
@@ -1129,13 +1129,13 @@ void KAZE_Descriptor_Invoker::Get_KAZE_Descriptor_128(const KeyPoint &kpt, float
11291129
// Get the gaussian weighted x and y responses
11301130
gauss_s1 = gaussian(xs - sample_x, ys - sample_y, 2.5f*scale);
11311131

1132-
y1 = fRound(sample_y - 0.5f);
1133-
x1 = fRound(sample_x - 0.5f);
1132+
y1 = cvFloor(sample_y);
1133+
x1 = cvFloor(sample_x);
11341134

11351135
checkDescriptorLimits(x1, y1, options_.img_width, options_.img_height);
11361136

1137-
y2 = (int)(sample_y + 0.5f);
1138-
x2 = (int)(sample_x + 0.5f);
1137+
y2 = y1 + 1;
1138+
x2 = x1 + 1;
11391139

11401140
checkDescriptorLimits(x2, y2, options_.img_width, options_.img_height);
11411141

modules/features2d/src/kaze/utils.h

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,34 +39,4 @@ inline void checkDescriptorLimits(int &x, int &y, int width, int height) {
3939
}
4040
}
4141

42-
/* ************************************************************************* */
43-
/**
44-
* @brief This funtion rounds float to nearest integer
45-
* @param flt Input float
46-
* @return dst Nearest integer
47-
*/
48-
inline int fRound(float flt) {
49-
return (int)(flt + 0.5f);
50-
}
51-
52-
/* ************************************************************************* */
53-
/**
54-
* @brief Exponentiation by squaring
55-
* @param flt Exponentiation base
56-
* @return dst Exponentiation value
57-
*/
58-
inline int fastpow(int base, int exp) {
59-
int res = 1;
60-
while(exp > 0) {
61-
if(exp & 1) {
62-
exp--;
63-
res *= base;
64-
} else {
65-
exp /= 2;
66-
base *= base;
67-
}
68-
}
69-
return res;
70-
}
71-
7242
#endif

0 commit comments

Comments
 (0)