提交 8aca8d90 编写于 作者: A Alexander Alekhin

akaze: replace ceil()

- integer division => divUp()
- cast to 'int' => cvCeil()
上级 9ca39821
...@@ -113,12 +113,12 @@ namespace cv ...@@ -113,12 +113,12 @@ namespace cv
if (descriptor_size == 0) if (descriptor_size == 0)
{ {
int t = (6 + 36 + 120) * descriptor_channels; int t = (6 + 36 + 120) * descriptor_channels;
return (int)ceil(t / 8.); return divUp(t, 8);
} }
else else
{ {
// We use the random bit selection length binary descriptor // We use the random bit selection length binary descriptor
return (int)ceil(descriptor_size / 8.); return divUp(descriptor_size, 8);
} }
default: default:
......
...@@ -106,7 +106,7 @@ void AKAZEFeatures::Allocate_Memory_Evolution(void) { ...@@ -106,7 +106,7 @@ void AKAZEFeatures::Allocate_Memory_Evolution(void) {
*/ */
static inline int getGaussianKernelSize(float sigma) { static inline int getGaussianKernelSize(float sigma) {
// Compute an appropriate kernel size according to the specified sigma // Compute an appropriate kernel size according to the specified sigma
int ksize = (int)ceil(2.0f*(1.0f + (sigma - 0.8f) / (0.3f))); int ksize = (int)cvCeil(2.0f*(1.0f + (sigma - 0.8f) / (0.3f)));
ksize |= 1; // kernel should be odd ksize |= 1; // kernel should be odd
return ksize; return ksize;
} }
...@@ -1131,20 +1131,17 @@ void AKAZEFeatures::Compute_Descriptors(std::vector<KeyPoint>& kpts, OutputArray ...@@ -1131,20 +1131,17 @@ void AKAZEFeatures::Compute_Descriptors(std::vector<KeyPoint>& kpts, OutputArray
} }
// Allocate memory for the matrix with the descriptors // Allocate memory for the matrix with the descriptors
if (options_.descriptor < AKAZE::DESCRIPTOR_MLDB_UPRIGHT) { int descriptor_size = 64;
descriptors.create((int)kpts.size(), 64, CV_32FC1); int descriptor_type = CV_32FC1;
} if (options_.descriptor >= AKAZE::DESCRIPTOR_MLDB_UPRIGHT)
else { {
// We use the full length binary descriptor -> 486 bits int descriptor_bits = (options_.descriptor_size == 0)
if (options_.descriptor_size == 0) { ? (6 + 36 + 120)*options_.descriptor_channels // the full length binary descriptor -> 486 bits
int t = (6 + 36 + 120)*options_.descriptor_channels; : options_.descriptor_size; // the random bit selection length binary descriptor
descriptors.create((int)kpts.size(), (int)ceil(t / 8.), CV_8UC1); descriptor_size = divUp(descriptor_bits, 8);
} descriptor_type = CV_8UC1;
else {
// We use the random bit selection length binary descriptor
descriptors.create((int)kpts.size(), (int)ceil(options_.descriptor_size / 8.), CV_8UC1);
}
} }
descriptors.create((int)kpts.size(), descriptor_size, descriptor_type);
Mat desc = descriptors.getMat(); Mat desc = descriptors.getMat();
...@@ -1701,10 +1698,11 @@ void Upright_MLDB_Full_Descriptor_Invoker::Get_Upright_MLDB_Full_Descriptor(cons ...@@ -1701,10 +1698,11 @@ void Upright_MLDB_Full_Descriptor_Invoker::Get_Upright_MLDB_Full_Descriptor(cons
// For 2x2 grid, 3x3 grid and 4x4 grid // For 2x2 grid, 3x3 grid and 4x4 grid
const int pattern_size = options_->descriptor_pattern_size; const int pattern_size = options_->descriptor_pattern_size;
int sample_step[3] = { CV_Assert((pattern_size & 1) == 0);
const int sample_step[3] = {
pattern_size, pattern_size,
static_cast<int>(ceil(pattern_size*2./3.)), divUp(pattern_size * 2, 3),
pattern_size / 2 divUp(pattern_size, 2)
}; };
// For the three grids // For the three grids
...@@ -1873,8 +1871,16 @@ void MLDB_Full_Descriptor_Invoker::Get_MLDB_Full_Descriptor(const KeyPoint& kpt, ...@@ -1873,8 +1871,16 @@ void MLDB_Full_Descriptor_Invoker::Get_MLDB_Full_Descriptor(const KeyPoint& kpt,
const int max_channels = 3; const int max_channels = 3;
CV_Assert(options_->descriptor_channels <= max_channels); CV_Assert(options_->descriptor_channels <= max_channels);
const int pattern_size = options_->descriptor_pattern_size;
float values[16*max_channels]; float values[16*max_channels];
const double size_mult[3] = {1, 2.0/3.0, 1.0/2.0}; CV_Assert((pattern_size & 1) == 0);
//const double size_mult[3] = {1, 2.0/3.0, 1.0/2.0};
const int sample_step[3] = { // static_cast<int>(ceil(pattern_size * size_mult[lvl]))
pattern_size,
divUp(pattern_size * 2, 3),
divUp(pattern_size, 2)
};
float ratio = (float)(1 << kpt.octave); float ratio = (float)(1 << kpt.octave);
float scale = (float)fRound(0.5f*kpt.size / ratio); float scale = (float)fRound(0.5f*kpt.size / ratio);
...@@ -1883,14 +1889,12 @@ void MLDB_Full_Descriptor_Invoker::Get_MLDB_Full_Descriptor(const KeyPoint& kpt, ...@@ -1883,14 +1889,12 @@ void MLDB_Full_Descriptor_Invoker::Get_MLDB_Full_Descriptor(const KeyPoint& kpt,
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 co = cos(angle);
float si = sin(angle); float si = sin(angle);
int pattern_size = options_->descriptor_pattern_size;
int dpos = 0; int dpos = 0;
for(int lvl = 0; lvl < 3; lvl++) { for(int lvl = 0; lvl < 3; lvl++) {
int val_count = (lvl + 2) * (lvl + 2); int val_count = (lvl + 2) * (lvl + 2);
int sample_step = static_cast<int>(ceil(pattern_size * size_mult[lvl])); MLDB_Fill_Values(values, sample_step[lvl], kpt.class_id, xf, yf, co, si, scale);
MLDB_Fill_Values(values, sample_step, kpt.class_id, xf, yf, co, si, scale);
MLDB_Binary_Comparisons(values, desc, val_count, dpos); MLDB_Binary_Comparisons(values, desc, val_count, dpos);
} }
} }
...@@ -1930,14 +1934,18 @@ void MLDB_Descriptor_Subset_Invoker::Get_MLDB_Descriptor_Subset(const KeyPoint& ...@@ -1930,14 +1934,18 @@ void MLDB_Descriptor_Subset_Invoker::Get_MLDB_Descriptor_Subset(const KeyPoint&
Mat values((4 + 9 + 16)*options.descriptor_channels, 1, CV_32FC1); Mat values((4 + 9 + 16)*options.descriptor_channels, 1, CV_32FC1);
// Sample everything, but only do the comparisons // Sample everything, but only do the comparisons
vector<int> steps(3); const int pattern_size = options.descriptor_pattern_size;
steps.at(0) = options.descriptor_pattern_size; CV_Assert((pattern_size & 1) == 0);
steps.at(1) = (int)ceil(2.f*options.descriptor_pattern_size / 3.f); const int sample_steps[3] = {
steps.at(2) = options.descriptor_pattern_size / 2; pattern_size,
divUp(pattern_size * 2, 3),
divUp(pattern_size, 2)
};
for (int i = 0; i < descriptorSamples_.rows; i++) { for (int i = 0; i < descriptorSamples_.rows; i++) {
const int *coords = descriptorSamples_.ptr<int>(i); const int *coords = descriptorSamples_.ptr<int>(i);
int sample_step = steps.at(coords[0]); CV_Assert(coords[0] >= 0 && coords[0] < 3);
const int sample_step = sample_steps[coords[0]];
di = 0.0f; di = 0.0f;
dx = 0.0f; dx = 0.0f;
dy = 0.0f; dy = 0.0f;
...@@ -2025,14 +2033,18 @@ void Upright_MLDB_Descriptor_Subset_Invoker::Get_Upright_MLDB_Descriptor_Subset( ...@@ -2025,14 +2033,18 @@ void Upright_MLDB_Descriptor_Subset_Invoker::Get_Upright_MLDB_Descriptor_Subset(
// Allocate memory for the matrix of values // Allocate memory for the matrix of values
Mat values ((4 + 9 + 16)*options.descriptor_channels, 1, CV_32FC1); Mat values ((4 + 9 + 16)*options.descriptor_channels, 1, CV_32FC1);
vector<int> steps(3); const int pattern_size = options.descriptor_pattern_size;
steps.at(0) = options.descriptor_pattern_size; CV_Assert((pattern_size & 1) == 0);
steps.at(1) = static_cast<int>(ceil(2.f*options.descriptor_pattern_size / 3.f)); const int sample_steps[3] = {
steps.at(2) = options.descriptor_pattern_size / 2; pattern_size,
divUp(pattern_size * 2, 3),
divUp(pattern_size, 2)
};
for (int i = 0; i < descriptorSamples_.rows; i++) { for (int i = 0; i < descriptorSamples_.rows; i++) {
const int *coords = descriptorSamples_.ptr<int>(i); const int *coords = descriptorSamples_.ptr<int>(i);
int sample_step = steps.at(coords[0]); CV_Assert(coords[0] >= 0 && coords[0] < 3);
int sample_step = sample_steps[coords[0]];
di = 0.0f, dx = 0.0f, dy = 0.0f; di = 0.0f, dx = 0.0f, dy = 0.0f;
for (int k = coords[1]; k < coords[1] + sample_step; k++) { for (int k = coords[1]; k < coords[1] + sample_step; k++) {
...@@ -2120,7 +2132,7 @@ void generateDescriptorSubsample(Mat& sampleList, Mat& comparisons, int nbits, ...@@ -2120,7 +2132,7 @@ void generateDescriptorSubsample(Mat& sampleList, Mat& comparisons, int nbits,
for (int i = 0, c = 0; i < 3; i++) { for (int i = 0, c = 0; i < 3; i++) {
int gdiv = i + 2; //grid divisions, per row int gdiv = i + 2; //grid divisions, per row
int gsz = gdiv*gdiv; int gsz = gdiv*gdiv;
int psz = (int)ceil(2.f*pattern_size / (float)gdiv); int psz = divUp(2*pattern_size, gdiv);
for (int j = 0; j < gsz; j++) { for (int j = 0; j < gsz; j++) {
for (int k = j + 1; k < gsz; k++, c++) { for (int k = j + 1; k < gsz; k++, c++) {
...@@ -2134,12 +2146,12 @@ void generateDescriptorSubsample(Mat& sampleList, Mat& comparisons, int nbits, ...@@ -2134,12 +2146,12 @@ void generateDescriptorSubsample(Mat& sampleList, Mat& comparisons, int nbits,
} }
RNG rng(1024); RNG rng(1024);
Mat_<int> comps = Mat_<int>(nchannels * (int)ceil(nbits / (float)nchannels), 2); const int npicks = divUp(nbits, nchannels);
Mat_<int> comps = Mat_<int>(nchannels * npicks, 2);
comps = 1000; comps = 1000;
// Select some samples. A sample includes all channels // Select some samples. A sample includes all channels
int count = 0; int count = 0;
int npicks = (int)ceil(nbits / (float)nchannels);
Mat_<int> samples(29, 3); Mat_<int> samples(29, 3);
Mat_<int> fullcopy = fullM.clone(); Mat_<int> fullcopy = fullM.clone();
samples = -1; samples = -1;
......
...@@ -72,7 +72,7 @@ int fed_tau_by_cycle_time(const float& t, const float& tau_max, ...@@ -72,7 +72,7 @@ int fed_tau_by_cycle_time(const float& t, const float& tau_max,
float scale = 0.0; // Ratio of t we search to maximal t float scale = 0.0; // Ratio of t we search to maximal t
// Compute necessary number of time steps // Compute necessary number of time steps
n = (int)(ceilf(sqrtf(3.0f*t/tau_max+0.25f)-0.5f-1.0e-8f)+ 0.5f); n = cvCeil(sqrtf(3.0f*t/tau_max+0.25f)-0.5f-1.0e-8f);
scale = 3.0f*t/(tau_max*(float)(n*(n+1))); scale = 3.0f*t/(tau_max*(float)(n*(n+1)));
// Call internal FED time step creation routine // Call internal FED time step creation routine
......
...@@ -49,7 +49,7 @@ void gaussian_2D_convolution(const cv::Mat& src, cv::Mat& dst, int ksize_x, int ...@@ -49,7 +49,7 @@ void gaussian_2D_convolution(const cv::Mat& src, cv::Mat& dst, int ksize_x, int
// Compute an appropriate kernel size according to the specified sigma // Compute an appropriate kernel size according to the specified sigma
if (sigma > ksize_x || sigma > ksize_y || ksize_x == 0 || ksize_y == 0) { if (sigma > ksize_x || sigma > ksize_y || ksize_x == 0 || ksize_y == 0) {
ksize_x_ = (int)ceil(2.0f*(1.0f + (sigma - 0.8f) / (0.3f))); ksize_x_ = cvCeil(2.0f*(1.0f + (sigma - 0.8f) / (0.3f)));
ksize_y_ = ksize_x_; ksize_y_ = ksize_x_;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册