Skip to content

Commit 8aca8d9

Browse files
committed
akaze: replace ceil()
- integer division => divUp() - cast to 'int' => cvCeil()
1 parent 9ca3982 commit 8aca8d9

File tree

4 files changed

+50
-38
lines changed

4 files changed

+50
-38
lines changed

modules/features2d/src/akaze.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ namespace cv
113113
if (descriptor_size == 0)
114114
{
115115
int t = (6 + 36 + 120) * descriptor_channels;
116-
return (int)ceil(t / 8.);
116+
return divUp(t, 8);
117117
}
118118
else
119119
{
120120
// We use the random bit selection length binary descriptor
121-
return (int)ceil(descriptor_size / 8.);
121+
return divUp(descriptor_size, 8);
122122
}
123123

124124
default:

modules/features2d/src/kaze/AKAZEFeatures.cpp

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void AKAZEFeatures::Allocate_Memory_Evolution(void) {
106106
*/
107107
static inline int getGaussianKernelSize(float sigma) {
108108
// Compute an appropriate kernel size according to the specified sigma
109-
int ksize = (int)ceil(2.0f*(1.0f + (sigma - 0.8f) / (0.3f)));
109+
int ksize = (int)cvCeil(2.0f*(1.0f + (sigma - 0.8f) / (0.3f)));
110110
ksize |= 1; // kernel should be odd
111111
return ksize;
112112
}
@@ -1131,20 +1131,17 @@ void AKAZEFeatures::Compute_Descriptors(std::vector<KeyPoint>& kpts, OutputArray
11311131
}
11321132

11331133
// Allocate memory for the matrix with the descriptors
1134-
if (options_.descriptor < AKAZE::DESCRIPTOR_MLDB_UPRIGHT) {
1135-
descriptors.create((int)kpts.size(), 64, CV_32FC1);
1136-
}
1137-
else {
1138-
// We use the full length binary descriptor -> 486 bits
1139-
if (options_.descriptor_size == 0) {
1140-
int t = (6 + 36 + 120)*options_.descriptor_channels;
1141-
descriptors.create((int)kpts.size(), (int)ceil(t / 8.), CV_8UC1);
1142-
}
1143-
else {
1144-
// We use the random bit selection length binary descriptor
1145-
descriptors.create((int)kpts.size(), (int)ceil(options_.descriptor_size / 8.), CV_8UC1);
1146-
}
1134+
int descriptor_size = 64;
1135+
int descriptor_type = CV_32FC1;
1136+
if (options_.descriptor >= AKAZE::DESCRIPTOR_MLDB_UPRIGHT)
1137+
{
1138+
int descriptor_bits = (options_.descriptor_size == 0)
1139+
? (6 + 36 + 120)*options_.descriptor_channels // the full length binary descriptor -> 486 bits
1140+
: options_.descriptor_size; // the random bit selection length binary descriptor
1141+
descriptor_size = divUp(descriptor_bits, 8);
1142+
descriptor_type = CV_8UC1;
11471143
}
1144+
descriptors.create((int)kpts.size(), descriptor_size, descriptor_type);
11481145

11491146
Mat desc = descriptors.getMat();
11501147

@@ -1701,10 +1698,11 @@ void Upright_MLDB_Full_Descriptor_Invoker::Get_Upright_MLDB_Full_Descriptor(cons
17011698

17021699
// For 2x2 grid, 3x3 grid and 4x4 grid
17031700
const int pattern_size = options_->descriptor_pattern_size;
1704-
int sample_step[3] = {
1701+
CV_Assert((pattern_size & 1) == 0);
1702+
const int sample_step[3] = {
17051703
pattern_size,
1706-
static_cast<int>(ceil(pattern_size*2./3.)),
1707-
pattern_size / 2
1704+
divUp(pattern_size * 2, 3),
1705+
divUp(pattern_size, 2)
17081706
};
17091707

17101708
// For the three grids
@@ -1873,8 +1871,16 @@ void MLDB_Full_Descriptor_Invoker::Get_MLDB_Full_Descriptor(const KeyPoint& kpt,
18731871

18741872
const int max_channels = 3;
18751873
CV_Assert(options_->descriptor_channels <= max_channels);
1874+
const int pattern_size = options_->descriptor_pattern_size;
1875+
18761876
float values[16*max_channels];
1877-
const double size_mult[3] = {1, 2.0/3.0, 1.0/2.0};
1877+
CV_Assert((pattern_size & 1) == 0);
1878+
//const double size_mult[3] = {1, 2.0/3.0, 1.0/2.0};
1879+
const int sample_step[3] = { // static_cast<int>(ceil(pattern_size * size_mult[lvl]))
1880+
pattern_size,
1881+
divUp(pattern_size * 2, 3),
1882+
divUp(pattern_size, 2)
1883+
};
18781884

18791885
float ratio = (float)(1 << kpt.octave);
18801886
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,
18831889
float angle = (kpt.angle * static_cast<float>(CV_PI)) / 180.f;
18841890
float co = cos(angle);
18851891
float si = sin(angle);
1886-
int pattern_size = options_->descriptor_pattern_size;
18871892

18881893
int dpos = 0;
18891894
for(int lvl = 0; lvl < 3; lvl++) {
18901895

18911896
int val_count = (lvl + 2) * (lvl + 2);
1892-
int sample_step = static_cast<int>(ceil(pattern_size * size_mult[lvl]));
1893-
MLDB_Fill_Values(values, sample_step, kpt.class_id, xf, yf, co, si, scale);
1897+
MLDB_Fill_Values(values, sample_step[lvl], kpt.class_id, xf, yf, co, si, scale);
18941898
MLDB_Binary_Comparisons(values, desc, val_count, dpos);
18951899
}
18961900
}
@@ -1930,14 +1934,18 @@ void MLDB_Descriptor_Subset_Invoker::Get_MLDB_Descriptor_Subset(const KeyPoint&
19301934
Mat values((4 + 9 + 16)*options.descriptor_channels, 1, CV_32FC1);
19311935

19321936
// Sample everything, but only do the comparisons
1933-
vector<int> steps(3);
1934-
steps.at(0) = options.descriptor_pattern_size;
1935-
steps.at(1) = (int)ceil(2.f*options.descriptor_pattern_size / 3.f);
1936-
steps.at(2) = options.descriptor_pattern_size / 2;
1937+
const int pattern_size = options.descriptor_pattern_size;
1938+
CV_Assert((pattern_size & 1) == 0);
1939+
const int sample_steps[3] = {
1940+
pattern_size,
1941+
divUp(pattern_size * 2, 3),
1942+
divUp(pattern_size, 2)
1943+
};
19371944

19381945
for (int i = 0; i < descriptorSamples_.rows; i++) {
19391946
const int *coords = descriptorSamples_.ptr<int>(i);
1940-
int sample_step = steps.at(coords[0]);
1947+
CV_Assert(coords[0] >= 0 && coords[0] < 3);
1948+
const int sample_step = sample_steps[coords[0]];
19411949
di = 0.0f;
19421950
dx = 0.0f;
19431951
dy = 0.0f;
@@ -2025,14 +2033,18 @@ void Upright_MLDB_Descriptor_Subset_Invoker::Get_Upright_MLDB_Descriptor_Subset(
20252033
// Allocate memory for the matrix of values
20262034
Mat values ((4 + 9 + 16)*options.descriptor_channels, 1, CV_32FC1);
20272035

2028-
vector<int> steps(3);
2029-
steps.at(0) = options.descriptor_pattern_size;
2030-
steps.at(1) = static_cast<int>(ceil(2.f*options.descriptor_pattern_size / 3.f));
2031-
steps.at(2) = options.descriptor_pattern_size / 2;
2036+
const int pattern_size = options.descriptor_pattern_size;
2037+
CV_Assert((pattern_size & 1) == 0);
2038+
const int sample_steps[3] = {
2039+
pattern_size,
2040+
divUp(pattern_size * 2, 3),
2041+
divUp(pattern_size, 2)
2042+
};
20322043

20332044
for (int i = 0; i < descriptorSamples_.rows; i++) {
20342045
const int *coords = descriptorSamples_.ptr<int>(i);
2035-
int sample_step = steps.at(coords[0]);
2046+
CV_Assert(coords[0] >= 0 && coords[0] < 3);
2047+
int sample_step = sample_steps[coords[0]];
20362048
di = 0.0f, dx = 0.0f, dy = 0.0f;
20372049

20382050
for (int k = coords[1]; k < coords[1] + sample_step; k++) {
@@ -2120,7 +2132,7 @@ void generateDescriptorSubsample(Mat& sampleList, Mat& comparisons, int nbits,
21202132
for (int i = 0, c = 0; i < 3; i++) {
21212133
int gdiv = i + 2; //grid divisions, per row
21222134
int gsz = gdiv*gdiv;
2123-
int psz = (int)ceil(2.f*pattern_size / (float)gdiv);
2135+
int psz = divUp(2*pattern_size, gdiv);
21242136

21252137
for (int j = 0; j < gsz; j++) {
21262138
for (int k = j + 1; k < gsz; k++, c++) {
@@ -2134,12 +2146,12 @@ void generateDescriptorSubsample(Mat& sampleList, Mat& comparisons, int nbits,
21342146
}
21352147

21362148
RNG rng(1024);
2137-
Mat_<int> comps = Mat_<int>(nchannels * (int)ceil(nbits / (float)nchannels), 2);
2149+
const int npicks = divUp(nbits, nchannels);
2150+
Mat_<int> comps = Mat_<int>(nchannels * npicks, 2);
21382151
comps = 1000;
21392152

21402153
// Select some samples. A sample includes all channels
21412154
int count = 0;
2142-
int npicks = (int)ceil(nbits / (float)nchannels);
21432155
Mat_<int> samples(29, 3);
21442156
Mat_<int> fullcopy = fullM.clone();
21452157
samples = -1;

modules/features2d/src/kaze/fed.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ int fed_tau_by_cycle_time(const float& t, const float& tau_max,
7272
float scale = 0.0; // Ratio of t we search to maximal t
7373

7474
// Compute necessary number of time steps
75-
n = (int)(ceilf(sqrtf(3.0f*t/tau_max+0.25f)-0.5f-1.0e-8f)+ 0.5f);
75+
n = cvCeil(sqrtf(3.0f*t/tau_max+0.25f)-0.5f-1.0e-8f);
7676
scale = 3.0f*t/(tau_max*(float)(n*(n+1)));
7777

7878
// Call internal FED time step creation routine

modules/features2d/src/kaze/nldiffusion_functions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void gaussian_2D_convolution(const cv::Mat& src, cv::Mat& dst, int ksize_x, int
4949

5050
// Compute an appropriate kernel size according to the specified sigma
5151
if (sigma > ksize_x || sigma > ksize_y || ksize_x == 0 || ksize_y == 0) {
52-
ksize_x_ = (int)ceil(2.0f*(1.0f + (sigma - 0.8f) / (0.3f)));
52+
ksize_x_ = cvCeil(2.0f*(1.0f + (sigma - 0.8f) / (0.3f)));
5353
ksize_y_ = ksize_x_;
5454
}
5555

0 commit comments

Comments
 (0)