Skip to content

Commit 7f8e9c2

Browse files
committed
replace some wrapped functions with direct calls to OpenCV functions
* improved readability for people familiar with opencv * do not same image twice in base level
1 parent 8015cfd commit 7f8e9c2

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

modules/features2d/src/kaze/AKAZEFeatures.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ void AKAZEFeatures::Allocate_Memory_Evolution(void) {
9999
}
100100

101101
/* ************************************************************************* */
102+
/**
103+
* @brief Computes kernel size for Gaussian smoothing if the image
104+
* @param sigma Kernel standard deviation
105+
* @returns kernel size
106+
*/
107+
static inline int getGaussianKernelSize(float sigma) {
108+
// Compute an appropriate kernel size according to the specified sigma
109+
int ksize = (int)ceil(2.0f*(1.0f + (sigma - 0.8f) / (0.3f)));
110+
ksize |= 1; // kernel should be odd
111+
return ksize;
112+
}
113+
102114
/**
103115
* @brief This method creates the nonlinear scale space for a given image
104116
* @param img Input image for which the nonlinear scale space needs to be created
@@ -109,10 +121,15 @@ int AKAZEFeatures::Create_Nonlinear_Scale_Space(const Mat& img)
109121
CV_INSTRUMENT_REGION()
110122
CV_Assert(evolution_.size() > 0);
111123

112-
// Copy the original image to the first level of the evolution
113-
img.copyTo(evolution_[0].Lt);
114-
gaussian_2D_convolution(evolution_[0].Lt, evolution_[0].Lt, 0, 0, options_.soffset);
115-
evolution_[0].Lt.copyTo(evolution_[0].Lsmooth);
124+
// create first level of the evolution
125+
int ksize = getGaussianKernelSize(options_.soffset);
126+
GaussianBlur(img, evolution_[0].Lt, Size(ksize, ksize), options_.soffset, options_.soffset, BORDER_REPLICATE);
127+
evolution_[0].Lsmooth = evolution_[0].Lt;
128+
129+
if (evolution_.size() == 1) {
130+
// we don't need to compute kcontrast factor
131+
return 0;
132+
}
116133

117134
// First compute the kcontrast factor
118135
options_.kcontrast = compute_k_percentile(img, options_.kcontrast_percentile, 1.0f, options_.kcontrast_nbins, 0, 0);
@@ -121,18 +138,21 @@ int AKAZEFeatures::Create_Nonlinear_Scale_Space(const Mat& img)
121138
for (size_t i = 1; i < evolution_.size(); i++) {
122139

123140
if (evolution_[i].octave > evolution_[i - 1].octave) {
124-
halfsample_image(evolution_[i - 1].Lt, evolution_[i].Lt);
141+
Size half_size = evolution_[i - 1].Lt.size();
142+
half_size.width /= 2;
143+
half_size.height /= 2;
144+
resize(evolution_[i - 1].Lt, evolution_[i].Lt, half_size, 0, 0, INTER_AREA);
125145
options_.kcontrast = options_.kcontrast*0.75f;
126146
}
127147
else {
128148
evolution_[i - 1].Lt.copyTo(evolution_[i].Lt);
129149
}
130150

131-
gaussian_2D_convolution(evolution_[i].Lt, evolution_[i].Lsmooth, 0, 0, 1.0f);
151+
GaussianBlur(evolution_[i].Lt, evolution_[i].Lsmooth, Size(5, 5), 1.0f, 1.0f, BORDER_REPLICATE);
132152

133153
// Compute the Gaussian derivatives Lx and Ly
134-
image_derivatives_scharr(evolution_[i].Lsmooth, evolution_[i].Lx, 1, 0);
135-
image_derivatives_scharr(evolution_[i].Lsmooth, evolution_[i].Ly, 0, 1);
154+
Scharr(evolution_[i].Lsmooth, evolution_[i].Lx, CV_32F, 1, 0, 1.0, 0, BORDER_DEFAULT);
155+
Scharr(evolution_[i].Lsmooth, evolution_[i].Ly, CV_32F, 0, 1, 1.0, 0, BORDER_DEFAULT);
136156

137157
// Compute the conductivity equation
138158
switch (options_.diffusivity) {

0 commit comments

Comments
 (0)