Skip to content

Commit 6453300

Browse files
committed
akaze: optimize allocations
1 parent 8aca8d9 commit 6453300

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

modules/features2d/src/kaze/AKAZEFeatures.cpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,12 +1679,10 @@ void Upright_MLDB_Full_Descriptor_Invoker::Get_Upright_MLDB_Full_Descriptor(cons
16791679
const AKAZEOptions & options = *options_;
16801680
const std::vector<Evolution>& evolution = *evolution_;
16811681

1682-
// Matrices for the M-LDB descriptor
1683-
Mat values[3] = {
1684-
Mat(4, options.descriptor_channels, CV_32FC1),
1685-
Mat(9, options.descriptor_channels, CV_32FC1),
1686-
Mat(16, options.descriptor_channels, CV_32FC1)
1687-
};
1682+
// Buffer for the M-LDB descriptor
1683+
const int max_channels = 3;
1684+
CV_Assert(options.descriptor_channels <= max_channels);
1685+
float values[16*max_channels];
16881686

16891687
// Get the information from the keypoint
16901688
ratio = (float)(1 << kpt.octave);
@@ -1739,7 +1737,7 @@ void Upright_MLDB_Full_Descriptor_Invoker::Get_Upright_MLDB_Full_Descriptor(cons
17391737
dx /= nsamples;
17401738
dy /= nsamples;
17411739

1742-
float *val = values[z].ptr<float>(dcount2);
1740+
float *val = &values[dcount2*max_channels];
17431741
*(val) = di;
17441742
*(val+1) = dx;
17451743
*(val+2) = dy;
@@ -1751,8 +1749,8 @@ void Upright_MLDB_Full_Descriptor_Invoker::Get_Upright_MLDB_Full_Descriptor(cons
17511749
const int num = (z + 2) * (z + 2);
17521750
for (int i = 0; i < num; i++) {
17531751
for (int j = i + 1; j < num; j++) {
1754-
const float * valI = values[z].ptr<float>(i);
1755-
const float * valJ = values[z].ptr<float>(j);
1752+
const float * valI = &values[i*max_channels];
1753+
const float * valJ = &values[j*max_channels];
17561754
for (int k = 0; k < 3; ++k) {
17571755
if (*(valI + k) > *(valJ + k)) {
17581756
desc[dcount1 / 8] |= (1 << (dcount1 % 8));
@@ -1931,7 +1929,11 @@ void MLDB_Descriptor_Subset_Invoker::Get_MLDB_Descriptor_Subset(const KeyPoint&
19311929
float si = sin(angle);
19321930

19331931
// Allocate memory for the matrix of values
1934-
Mat values((4 + 9 + 16)*options.descriptor_channels, 1, CV_32FC1);
1932+
// Buffer for the M-LDB descriptor
1933+
const int max_channels = 3;
1934+
const int channels = options.descriptor_channels;
1935+
CV_Assert(channels <= max_channels);
1936+
float values[(4 + 9 + 16)*max_channels];
19351937

19361938
// Sample everything, but only do the comparisons
19371939
const int pattern_size = options.descriptor_pattern_size;
@@ -1978,23 +1980,23 @@ void MLDB_Descriptor_Subset_Invoker::Get_MLDB_Descriptor_Subset(const KeyPoint&
19781980
}
19791981
}
19801982

1981-
*(values.ptr<float>(options.descriptor_channels*i)) = di;
1983+
float* pValues = &values[channels * i];
1984+
pValues[0] = di;
19821985

1983-
if (options.descriptor_channels == 2) {
1984-
*(values.ptr<float>(options.descriptor_channels*i + 1)) = dx;
1986+
if (channels == 2) {
1987+
pValues[1] = dx;
19851988
}
1986-
else if (options.descriptor_channels == 3) {
1987-
*(values.ptr<float>(options.descriptor_channels*i + 1)) = dx;
1988-
*(values.ptr<float>(options.descriptor_channels*i + 2)) = dy;
1989+
else if (channels == 3) {
1990+
pValues[1] = dx;
1991+
pValues[2] = dy;
19891992
}
19901993
}
19911994

19921995
// Do the comparisons
1993-
const float *vals = values.ptr<float>(0);
19941996
const int *comps = descriptorBits_.ptr<int>(0);
19951997

19961998
for (int i = 0; i<descriptorBits_.rows; i++) {
1997-
if (vals[comps[2 * i]] > vals[comps[2 * i + 1]]) {
1999+
if (values[comps[2 * i]] > values[comps[2 * i + 1]]) {
19982000
desc[i / 8] |= (1 << (i % 8));
19992001
} else {
20002002
desc[i / 8] &= ~(1 << (i % 8));

0 commit comments

Comments
 (0)