akaze: fRound -> cvRound, fix bilinear interpolation

pull/9303/head
Alexander Alekhin 8 years ago
parent f6ceeaa2e5
commit 73c3d14a66
  1. 52
      modules/features2d/src/kaze/AKAZEFeatures.cpp
  2. 44
      modules/features2d/src/kaze/KAZEFeatures.cpp
  3. 30
      modules/features2d/src/kaze/utils.h

@ -74,12 +74,12 @@ void AKAZEFeatures::Allocate_Memory_Evolution(void) {
Evolution step;
step.size = Size(level_width, level_height);
step.esigma = options_.soffset*pow(2.f, (float)(j) / (float)(options_.nsublevels) + i);
step.sigma_size = fRound(step.esigma * options_.derivative_factor / power); // In fact sigma_size only depends on j
step.sigma_size = cvRound(step.esigma * options_.derivative_factor / power); // In fact sigma_size only depends on j
step.etime = 0.5f * (step.esigma * step.esigma);
step.octave = i;
step.sublevel = j;
step.octave_ratio = (float)power;
step.border = fRound(smax * step.sigma_size) + 1;
step.border = cvRound(smax * step.sigma_size) + 1;
evolution_.push_back(step);
}
@ -1301,9 +1301,9 @@ void Compute_Main_Orientation(KeyPoint& kpt, const std::vector<Evolution>& evolu
// get the right evolution level for this keypoint
const Evolution& e = evolution[kpt.class_id];
// Get the information from the keypoint
int scale = fRound(0.5f * kpt.size / e.octave_ratio);
int x0 = fRound(kpt.pt.x / e.octave_ratio);
int y0 = fRound(kpt.pt.y / e.octave_ratio);
int scale = cvRound(0.5f * kpt.size / e.octave_ratio);
int x0 = cvRound(kpt.pt.x / e.octave_ratio);
int y0 = cvRound(kpt.pt.y / e.octave_ratio);
// Sample derivatives responses for the points within radius of 6*scale
const int ang_size = 109;
@ -1443,7 +1443,7 @@ void MSURF_Upright_Descriptor_64_Invoker::Get_MSURF_Upright_Descriptor_64(const
// Get the information from the keypoint
ratio = (float)(1 << kpt.octave);
scale = fRound(0.5f*kpt.size / ratio);
scale = cvRound(0.5f*kpt.size / ratio);
const int level = kpt.class_id;
Mat Lx = evolution[level].Mx;
Mat Ly = evolution[level].My;
@ -1572,8 +1572,8 @@ void MSURF_Descriptor_64_Invoker::Get_MSURF_Descriptor_64(const KeyPoint& kpt, f
// Get the information from the keypoint
ratio = (float)(1 << kpt.octave);
scale = fRound(0.5f*kpt.size / ratio);
angle = (kpt.angle * static_cast<float>(CV_PI)) / 180.f;
scale = cvRound(0.5f*kpt.size / ratio);
angle = kpt.angle * static_cast<float>(CV_PI / 180.f);
const int level = kpt.class_id;
Mat Lx = evolution[level].Mx;
Mat Ly = evolution[level].My;
@ -1613,11 +1613,11 @@ void MSURF_Descriptor_64_Invoker::Get_MSURF_Descriptor_64(const KeyPoint& kpt, f
// Get the gaussian weighted x and y responses
gauss_s1 = gaussian(xs - sample_x, ys - sample_y, 2.5f*scale);
y1 = fRound(sample_y - 0.5f);
x1 = fRound(sample_x - 0.5f);
y1 = cvRound(sample_y - 0.5f);
x1 = cvRound(sample_x - 0.5f);
y2 = fRound(sample_y + 0.5f);
x2 = fRound(sample_x + 0.5f);
y2 = cvRound(sample_y + 0.5f);
x2 = cvRound(sample_x + 0.5f);
// fix crash: indexing with out-of-bounds index, this might happen near the edges of image
// clip values so they fit into the image
@ -1706,7 +1706,7 @@ void Upright_MLDB_Full_Descriptor_Invoker::Get_Upright_MLDB_Full_Descriptor(cons
// Get the information from the keypoint
ratio = (float)(1 << kpt.octave);
scale = fRound(0.5f*kpt.size / ratio);
scale = cvRound(0.5f*kpt.size / ratio);
const int level = kpt.class_id;
Mat Lx = evolution[level].Mx;
Mat Ly = evolution[level].My;
@ -1741,8 +1741,8 @@ void Upright_MLDB_Full_Descriptor_Invoker::Get_Upright_MLDB_Full_Descriptor(cons
sample_y = yf + l*scale;
sample_x = xf + k*scale;
y1 = fRound(sample_y);
x1 = fRound(sample_x);
y1 = cvRound(sample_y);
x1 = cvRound(sample_x);
ri = *(Lt.ptr<float>(y1)+x1);
rx = *(Lx.ptr<float>(y1)+x1);
@ -1810,8 +1810,8 @@ void MLDB_Full_Descriptor_Invoker::MLDB_Fill_Values(float* values, int sample_st
float sample_y = yf + (l*co * scale + k*si*scale);
float sample_x = xf + (-l*si * scale + k*co*scale);
int y1 = fRound(sample_y);
int x1 = fRound(sample_x);
int y1 = cvRound(sample_y);
int x1 = cvRound(sample_x);
// fix crash: indexing with out-of-bounds index, this might happen near the edges of image
// clip values so they fit into the image
@ -1900,10 +1900,10 @@ void MLDB_Full_Descriptor_Invoker::Get_MLDB_Full_Descriptor(const KeyPoint& kpt,
};
float ratio = (float)(1 << kpt.octave);
float scale = (float)fRound(0.5f*kpt.size / ratio);
float scale = (float)cvRound(0.5f*kpt.size / ratio);
float xf = kpt.pt.x / ratio;
float yf = kpt.pt.y / ratio;
float angle = (kpt.angle * static_cast<float>(CV_PI)) / 180.f;
float angle = kpt.angle * static_cast<float>(CV_PI / 180.f);
float co = cos(angle);
float si = sin(angle);
@ -1941,8 +1941,8 @@ void MLDB_Descriptor_Subset_Invoker::Get_MLDB_Descriptor_Subset(const KeyPoint&
// Get the information from the keypoint
float ratio = (float)(1 << kpt.octave);
int scale = fRound(0.5f*kpt.size / ratio);
float angle = (kpt.angle * static_cast<float>(CV_PI)) / 180.f;
int scale = cvRound(0.5f*kpt.size / ratio);
float angle = kpt.angle * static_cast<float>(CV_PI / 180.f);
const int level = kpt.class_id;
Mat Lx = evolution[level].Mx;
Mat Ly = evolution[level].My;
@ -1983,8 +1983,8 @@ void MLDB_Descriptor_Subset_Invoker::Get_MLDB_Descriptor_Subset(const KeyPoint&
sample_y = yf + (l*scale*co + k*scale*si);
sample_x = xf + (-l*scale*si + k*scale*co);
y1 = fRound(sample_y);
x1 = fRound(sample_x);
y1 = cvRound(sample_y);
x1 = cvRound(sample_x);
di += *(Lt.ptr<float>(y1)+x1);
@ -2049,7 +2049,7 @@ void Upright_MLDB_Descriptor_Subset_Invoker::Get_Upright_MLDB_Descriptor_Subset(
// Get the information from the keypoint
float ratio = (float)(1 << kpt.octave);
int scale = fRound(0.5f*kpt.size / ratio);
int scale = cvRound(0.5f*kpt.size / ratio);
const int level = kpt.class_id;
Mat Lx = evolution[level].Mx;
Mat Ly = evolution[level].My;
@ -2081,8 +2081,8 @@ void Upright_MLDB_Descriptor_Subset_Invoker::Get_Upright_MLDB_Descriptor_Subset(
sample_y = yf + l*scale;
sample_x = xf + k*scale;
y1 = fRound(sample_y);
x1 = fRound(sample_x);
y1 = cvRound(sample_y);
x1 = cvRound(sample_x);
di += *(Lt.ptr<float>(y1)+x1);
if (options.descriptor_channels > 1) {

@ -68,7 +68,7 @@ void KAZEFeatures::Allocate_Memory_Evolution(void) {
aux.Ldet = Mat::zeros(options_.img_height, options_.img_width, CV_32F);
aux.esigma = options_.soffset*pow((float)2.0f, (float)(j) / (float)(options_.nsublevels)+i);
aux.etime = 0.5f*(aux.esigma*aux.esigma);
aux.sigma_size = fRound(aux.esigma);
aux.sigma_size = cvRound(aux.esigma);
aux.octave = i;
aux.sublevel = j;
evolution_.push_back(aux);
@ -363,10 +363,10 @@ void KAZEFeatures::Determinant_Hessian(std::vector<KeyPoint>& kpts)
if (is_extremum == true) {
// Check that the point is under the image limits for the descriptor computation
left_x = fRound(kpts_par_[i][j].pt.x - smax*kpts_par_[i][j].size);
right_x = fRound(kpts_par_[i][j].pt.x + smax*kpts_par_[i][j].size);
up_y = fRound(kpts_par_[i][j].pt.y - smax*kpts_par_[i][j].size);
down_y = fRound(kpts_par_[i][j].pt.y + smax*kpts_par_[i][j].size);
left_x = cvRound(kpts_par_[i][j].pt.x - smax*kpts_par_[i][j].size);
right_x = cvRound(kpts_par_[i][j].pt.x + smax*kpts_par_[i][j].size);
up_y = cvRound(kpts_par_[i][j].pt.y - smax*kpts_par_[i][j].size);
down_y = cvRound(kpts_par_[i][j].pt.y + smax*kpts_par_[i][j].size);
if (left_x < 0 || right_x >= evolution_[level].Ldet.cols ||
up_y < 0 || down_y >= evolution_[level].Ldet.rows) {
@ -587,14 +587,14 @@ void KAZEFeatures::Compute_Main_Orientation(KeyPoint &kpt, const std::vector<TEv
xf = kpt.pt.x;
yf = kpt.pt.y;
level = kpt.class_id;
s = fRound(kpt.size / 2.0f);
s = cvRound(kpt.size / 2.0f);
// Calculate derivatives responses for points within radius of 6*scale
for (int i = -6; i <= 6; ++i) {
for (int j = -6; j <= 6; ++j) {
if (i*i + j*j < 36) {
iy = fRound(yf + j*s);
ix = fRound(xf + i*s);
iy = cvRound(yf + j*s);
ix = cvRound(xf + i*s);
if (iy >= 0 && iy < options.img_height && ix >= 0 && ix < options.img_width) {
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
// Get the information from the keypoint
yf = kpt.pt.y;
xf = kpt.pt.x;
scale = fRound(kpt.size / 2.0f);
scale = cvRound(kpt.size / 2.0f);
level = kpt.class_id;
i = -8;
@ -804,8 +804,8 @@ void KAZE_Descriptor_Invoker::Get_KAZE_Descriptor_64(const KeyPoint &kpt, float
// Get the information from the keypoint
yf = kpt.pt.y;
xf = kpt.pt.x;
scale = fRound(kpt.size / 2.0f);
angle = (kpt.angle * static_cast<float>(CV_PI)) / 180.f;
scale = cvRound(kpt.size / 2.0f);
angle = kpt.angle * static_cast<float>(CV_PI / 180.f);
level = kpt.class_id;
co = cos(angle);
si = sin(angle);
@ -843,13 +843,13 @@ void KAZE_Descriptor_Invoker::Get_KAZE_Descriptor_64(const KeyPoint &kpt, float
// Get the gaussian weighted x and y responses
gauss_s1 = gaussian(xs - sample_x, ys - sample_y, 2.5f*scale);
y1 = fRound(sample_y - 0.5f);
x1 = fRound(sample_x - 0.5f);
y1 = cvFloor(sample_y);
x1 = cvFloor(sample_x);
checkDescriptorLimits(x1, y1, options_.img_width, options_.img_height);
y2 = (int)(sample_y + 0.5f);
x2 = (int)(sample_x + 0.5f);
y2 = y1 + 1;
x2 = x1 + 1;
checkDescriptorLimits(x2, y2, options_.img_width, options_.img_height);
@ -935,7 +935,7 @@ void KAZE_Descriptor_Invoker::Get_KAZE_Upright_Descriptor_128(const KeyPoint &kp
// Get the information from the keypoint
yf = kpt.pt.y;
xf = kpt.pt.x;
scale = fRound(kpt.size / 2.0f);
scale = cvRound(kpt.size / 2.0f);
level = kpt.class_id;
i = -8;
@ -1087,8 +1087,8 @@ void KAZE_Descriptor_Invoker::Get_KAZE_Descriptor_128(const KeyPoint &kpt, float
// Get the information from the keypoint
yf = kpt.pt.y;
xf = kpt.pt.x;
scale = fRound(kpt.size / 2.0f);
angle = (kpt.angle * static_cast<float>(CV_PI)) / 180.f;
scale = cvRound(kpt.size / 2.0f);
angle = kpt.angle * static_cast<float>(CV_PI / 180.f);
level = kpt.class_id;
co = cos(angle);
si = sin(angle);
@ -1129,13 +1129,13 @@ void KAZE_Descriptor_Invoker::Get_KAZE_Descriptor_128(const KeyPoint &kpt, float
// Get the gaussian weighted x and y responses
gauss_s1 = gaussian(xs - sample_x, ys - sample_y, 2.5f*scale);
y1 = fRound(sample_y - 0.5f);
x1 = fRound(sample_x - 0.5f);
y1 = cvFloor(sample_y);
x1 = cvFloor(sample_x);
checkDescriptorLimits(x1, y1, options_.img_width, options_.img_height);
y2 = (int)(sample_y + 0.5f);
x2 = (int)(sample_x + 0.5f);
y2 = y1 + 1;
x2 = x1 + 1;
checkDescriptorLimits(x2, y2, options_.img_width, options_.img_height);

@ -39,34 +39,4 @@ inline void checkDescriptorLimits(int &x, int &y, int width, int height) {
}
}
/* ************************************************************************* */
/**
* @brief This funtion rounds float to nearest integer
* @param flt Input float
* @return dst Nearest integer
*/
inline int fRound(float flt) {
return (int)(flt + 0.5f);
}
/* ************************************************************************* */
/**
* @brief Exponentiation by squaring
* @param flt Exponentiation base
* @return dst Exponentiation value
*/
inline int fastpow(int base, int exp) {
int res = 1;
while(exp > 0) {
if(exp & 1) {
exp--;
res *= base;
} else {
exp /= 2;
base *= base;
}
}
return res;
}
#endif

Loading…
Cancel
Save