Refactor of KAZE and AKAZE:
1) Clean-up from the unused code 2) Remove of SURF extraction method 3) Enabled threading for KAZE extraction 4) Exposed new properties for runtime configuration
This commit is contained in:
@@ -5,92 +5,81 @@
|
||||
* @author Pablo F. Alcantarilla
|
||||
*/
|
||||
|
||||
#ifndef __OPENCV_FEATURES_2D_KAZE_CONFIG_HPP__
|
||||
#define __OPENCV_FEATURES_2D_KAZE_CONFIG_HPP__
|
||||
|
||||
//******************************************************************************
|
||||
//******************************************************************************
|
||||
#pragma once
|
||||
|
||||
// OpenCV Includes
|
||||
#include "precomp.hpp"
|
||||
#include <opencv2/features2d.hpp>
|
||||
|
||||
//*************************************************************************************
|
||||
//*************************************************************************************
|
||||
|
||||
// Some defines
|
||||
#define NMAX_CHAR 400
|
||||
|
||||
// Some default options
|
||||
static const float DEFAULT_SCALE_OFFSET = 1.60f; // Base scale offset (sigma units)
|
||||
static const float DEFAULT_OCTAVE_MAX = 4.0f; // Maximum octave evolution of the image 2^sigma (coarsest scale sigma units)
|
||||
static const int DEFAULT_NSUBLEVELS = 4; // Default number of sublevels per scale level
|
||||
static const float DEFAULT_DETECTOR_THRESHOLD = 0.001f; // Detector response threshold to accept point
|
||||
static const float DEFAULT_MIN_DETECTOR_THRESHOLD = 0.00001f; // Minimum Detector response threshold to accept point
|
||||
static const int DEFAULT_DESCRIPTOR_MODE = 1; // Descriptor Mode 0->SURF, 1->M-SURF
|
||||
static const bool DEFAULT_USE_FED = true; // 0->AOS, 1->FED
|
||||
static const bool DEFAULT_UPRIGHT = false; // Upright descriptors, not invariant to rotation
|
||||
static const bool DEFAULT_EXTENDED = false; // Extended descriptor, dimension 128
|
||||
|
||||
// Some important configuration variables
|
||||
static const float DEFAULT_SIGMA_SMOOTHING_DERIVATIVES = 1.0f;
|
||||
static const float DEFAULT_KCONTRAST = 0.01f;
|
||||
static const float KCONTRAST_PERCENTILE = 0.7f;
|
||||
static const int KCONTRAST_NBINS = 300;
|
||||
static const bool COMPUTE_KCONTRAST = true;
|
||||
static const int DEFAULT_DIFFUSIVITY_TYPE = 1; // 0 -> PM G1, 1 -> PM G2, 2 -> Weickert
|
||||
static const bool USE_CLIPPING_NORMALIZATION = false;
|
||||
static const float CLIPPING_NORMALIZATION_RATIO = 1.6f;
|
||||
static const int CLIPPING_NORMALIZATION_NITER = 5;
|
||||
|
||||
//*************************************************************************************
|
||||
//*************************************************************************************
|
||||
|
||||
struct KAZEOptions {
|
||||
|
||||
KAZEOptions() {
|
||||
// Load the default options
|
||||
soffset = DEFAULT_SCALE_OFFSET;
|
||||
omax = static_cast<int>(DEFAULT_OCTAVE_MAX);
|
||||
nsublevels = DEFAULT_NSUBLEVELS;
|
||||
dthreshold = DEFAULT_DETECTOR_THRESHOLD;
|
||||
use_fed = DEFAULT_USE_FED;
|
||||
upright = DEFAULT_UPRIGHT;
|
||||
extended = DEFAULT_EXTENDED;
|
||||
descriptor = DEFAULT_DESCRIPTOR_MODE;
|
||||
diffusivity = DEFAULT_DIFFUSIVITY_TYPE;
|
||||
sderivatives = DEFAULT_SIGMA_SMOOTHING_DERIVATIVES;
|
||||
}
|
||||
enum DIFFUSIVITY_TYPE {
|
||||
PM_G1 = 0,
|
||||
PM_G2 = 1,
|
||||
WEICKERT = 2
|
||||
};
|
||||
|
||||
float soffset;
|
||||
int omax;
|
||||
int nsublevels;
|
||||
int img_width;
|
||||
int img_height;
|
||||
int diffusivity;
|
||||
float sderivatives;
|
||||
float dthreshold;
|
||||
bool use_fed;
|
||||
bool upright;
|
||||
bool extended;
|
||||
int descriptor;
|
||||
KAZEOptions()
|
||||
: descriptor(cv::KAZE::DESCRIPTOR_MSURF)
|
||||
, diffusivity(PM_G2)
|
||||
|
||||
, soffset(1.60f)
|
||||
, omax(4)
|
||||
, nsublevels(4)
|
||||
, img_width(0)
|
||||
, img_height(0)
|
||||
, sderivatives(1.0f)
|
||||
, dthreshold(0.001f)
|
||||
, kcontrast(0.01f)
|
||||
, kcontrast_percentille(0.7f)
|
||||
, kcontrast_bins(300)
|
||||
|
||||
, use_fed(true)
|
||||
, upright(false)
|
||||
, extended(false)
|
||||
|
||||
, use_clipping_normalilzation(false)
|
||||
, clipping_normalization_ratio(1.6f)
|
||||
, clipping_normalization_niter(5)
|
||||
{
|
||||
}
|
||||
|
||||
cv::KAZE::DESCRIPTOR_TYPE descriptor;
|
||||
DIFFUSIVITY_TYPE diffusivity;
|
||||
|
||||
float soffset;
|
||||
int omax;
|
||||
int nsublevels;
|
||||
int img_width;
|
||||
int img_height;
|
||||
float sderivatives;
|
||||
float dthreshold;
|
||||
float kcontrast;
|
||||
float kcontrast_percentille;
|
||||
int kcontrast_bins;
|
||||
|
||||
bool use_fed;
|
||||
bool upright;
|
||||
bool extended;
|
||||
|
||||
bool use_clipping_normalilzation;
|
||||
float clipping_normalization_ratio;
|
||||
int clipping_normalization_niter;
|
||||
};
|
||||
|
||||
struct TEvolution {
|
||||
cv::Mat Lx, Ly; // First order spatial derivatives
|
||||
cv::Mat Lxx, Lxy, Lyy; // Second order spatial derivatives
|
||||
cv::Mat Lflow; // Diffusivity image
|
||||
cv::Mat Lt; // Evolution image
|
||||
cv::Mat Lsmooth; // Smoothed image
|
||||
cv::Mat Lstep; // Evolution step update
|
||||
cv::Mat Ldet; // Detector response
|
||||
float etime; // Evolution time
|
||||
float esigma; // Evolution sigma. For linear diffusion t = sigma^2 / 2
|
||||
float octave; // Image octave
|
||||
float sublevel; // Image sublevel in each octave
|
||||
int sigma_size; // Integer esigma. For computing the feature detector responses
|
||||
cv::Mat Lx, Ly; // First order spatial derivatives
|
||||
cv::Mat Lxx, Lxy, Lyy; // Second order spatial derivatives
|
||||
cv::Mat Lflow; // Diffusivity image
|
||||
cv::Mat Lt; // Evolution image
|
||||
cv::Mat Lsmooth; // Smoothed image
|
||||
cv::Mat Lstep; // Evolution step update
|
||||
cv::Mat Ldet; // Detector response
|
||||
float etime; // Evolution time
|
||||
float esigma; // Evolution sigma. For linear diffusion t = sigma^2 / 2
|
||||
float octave; // Image octave
|
||||
float sublevel; // Image sublevel in each octave
|
||||
int sigma_size; // Integer esigma. For computing the feature detector responses
|
||||
};
|
||||
|
||||
//*************************************************************************************
|
||||
//*************************************************************************************
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -26,97 +26,52 @@ class KAZEFeatures {
|
||||
|
||||
private:
|
||||
|
||||
// Parameters of the Nonlinear diffusion class
|
||||
float soffset_; // Base scale offset
|
||||
float sderivatives_; // Standard deviation of the Gaussian for the nonlinear diff. derivatives
|
||||
int omax_; // Maximum octave level
|
||||
int nsublevels_; // Number of sublevels per octave level
|
||||
int img_width_; // Width of the original image
|
||||
int img_height_; // Height of the original image
|
||||
std::vector<TEvolution> evolution_; // Vector of nonlinear diffusion evolution
|
||||
float kcontrast_; // The contrast parameter for the scalar nonlinear diffusion
|
||||
float dthreshold_; // Feature detector threshold response
|
||||
int diffusivity_; // Diffusivity type, 0->PM G1, 1->PM G2, 2-> Weickert
|
||||
int descriptor_mode_; // Descriptor mode
|
||||
bool use_fed_; // Set to true in case we want to use FED for the nonlinear diffusion filtering. Set false for using AOS
|
||||
bool use_upright_; // Set to true in case we want to use the upright version of the descriptors
|
||||
bool use_extended_; // Set to true in case we want to use the extended version of the descriptors
|
||||
bool use_normalization;
|
||||
KAZEOptions options;
|
||||
|
||||
// Vector of keypoint vectors for finding extrema in multiple threads
|
||||
std::vector<std::vector<cv::KeyPoint> > kpts_par_;
|
||||
// Parameters of the Nonlinear diffusion class
|
||||
std::vector<TEvolution> evolution_; // Vector of nonlinear diffusion evolution
|
||||
|
||||
// FED parameters
|
||||
int ncycles_; // Number of cycles
|
||||
bool reordering_; // Flag for reordering time steps
|
||||
std::vector<std::vector<float > > tsteps_; // Vector of FED dynamic time steps
|
||||
std::vector<int> nsteps_; // Vector of number of steps per cycle
|
||||
// Vector of keypoint vectors for finding extrema in multiple threads
|
||||
std::vector<std::vector<cv::KeyPoint> > kpts_par_;
|
||||
|
||||
// Computation times variables in ms
|
||||
//double tkcontrast_; // Kcontrast factor computation
|
||||
//double tnlscale_; // Nonlinear Scale space generation
|
||||
//double tdetector_; // Feature detector
|
||||
//double tmderivatives_; // Multiscale derivatives computation
|
||||
//double tdresponse_; // Detector response computation
|
||||
//double tdescriptor_; // Feature descriptor
|
||||
//double tsubpixel_; // Subpixel refinement
|
||||
// FED parameters
|
||||
int ncycles_; // Number of cycles
|
||||
bool reordering_; // Flag for reordering time steps
|
||||
std::vector<std::vector<float > > tsteps_; // Vector of FED dynamic time steps
|
||||
std::vector<int> nsteps_; // Vector of number of steps per cycle
|
||||
|
||||
// Some auxiliary variables used in the AOS step
|
||||
cv::Mat Ltx_, Lty_, px_, py_, ax_, ay_, bx_, by_, qr_, qc_;
|
||||
// Some auxiliary variables used in the AOS step
|
||||
cv::Mat Ltx_, Lty_, px_, py_, ax_, ay_, bx_, by_, qr_, qc_;
|
||||
|
||||
public:
|
||||
|
||||
// Constructor
|
||||
KAZEFeatures(KAZEOptions& options);
|
||||
// Constructor
|
||||
KAZEFeatures(KAZEOptions& options);
|
||||
|
||||
// Public methods for KAZE interface
|
||||
void Allocate_Memory_Evolution(void);
|
||||
int Create_Nonlinear_Scale_Space(const cv::Mat& img);
|
||||
void Feature_Detection(std::vector<cv::KeyPoint>& kpts);
|
||||
void Feature_Description(std::vector<cv::KeyPoint>& kpts, cv::Mat& desc);
|
||||
// Public methods for KAZE interface
|
||||
void Allocate_Memory_Evolution(void);
|
||||
int Create_Nonlinear_Scale_Space(const cv::Mat& img);
|
||||
void Feature_Detection(std::vector<cv::KeyPoint>& kpts);
|
||||
void Feature_Description(std::vector<cv::KeyPoint>& kpts, cv::Mat& desc);
|
||||
|
||||
static void Compute_Main_Orientation(cv::KeyPoint& kpt, const std::vector<TEvolution>& evolution_, const KAZEOptions& options);
|
||||
|
||||
private:
|
||||
|
||||
// Feature Detection Methods
|
||||
void Compute_KContrast(const cv::Mat& img, const float& kper);
|
||||
void Compute_Multiscale_Derivatives(void);
|
||||
void Compute_Detector_Response(void);
|
||||
void Determinant_Hessian_Parallel(std::vector<cv::KeyPoint>& kpts);
|
||||
void Find_Extremum_Threading(const int& level);
|
||||
void Do_Subpixel_Refinement(std::vector<cv::KeyPoint>& kpts);
|
||||
// Feature Detection Methods
|
||||
void Compute_KContrast(const cv::Mat& img, const float& kper);
|
||||
void Compute_Multiscale_Derivatives(void);
|
||||
void Compute_Detector_Response(void);
|
||||
void Determinant_Hessian_Parallel(std::vector<cv::KeyPoint>& kpts);
|
||||
void Find_Extremum_Threading(const int& level);
|
||||
void Do_Subpixel_Refinement(std::vector<cv::KeyPoint>& kpts);
|
||||
|
||||
// AOS Methods
|
||||
void AOS_Step_Scalar(cv::Mat &Ld, const cv::Mat &Ldprev, const cv::Mat &c, const float& stepsize);
|
||||
void AOS_Rows(const cv::Mat &Ldprev, const cv::Mat &c, const float& stepsize);
|
||||
void AOS_Columns(const cv::Mat &Ldprev, const cv::Mat &c, const float& stepsize);
|
||||
void Thomas(const cv::Mat &a, const cv::Mat &b, const cv::Mat &Ld, cv::Mat &x);
|
||||
// AOS Methods
|
||||
void AOS_Step_Scalar(cv::Mat &Ld, const cv::Mat &Ldprev, const cv::Mat &c, const float& stepsize);
|
||||
void AOS_Rows(const cv::Mat &Ldprev, const cv::Mat &c, const float& stepsize);
|
||||
void AOS_Columns(const cv::Mat &Ldprev, const cv::Mat &c, const float& stepsize);
|
||||
void Thomas(const cv::Mat &a, const cv::Mat &b, const cv::Mat &Ld, cv::Mat &x);
|
||||
|
||||
// Feature Description methods
|
||||
void Compute_Main_Orientation_SURF(cv::KeyPoint& kpt);
|
||||
|
||||
// Descriptor Mode -> 0 SURF 64
|
||||
void Get_SURF_Upright_Descriptor_64(const cv::KeyPoint& kpt, float* desc);
|
||||
void Get_SURF_Descriptor_64(const cv::KeyPoint& kpt, float* desc);
|
||||
|
||||
// Descriptor Mode -> 0 SURF 128
|
||||
void Get_SURF_Upright_Descriptor_128(const cv::KeyPoint& kpt, float* desc);
|
||||
void Get_SURF_Descriptor_128(const cv::KeyPoint& kpt, float* desc);
|
||||
|
||||
// Descriptor Mode -> 1 M-SURF 64
|
||||
void Get_MSURF_Upright_Descriptor_64(const cv::KeyPoint& kpt, float* desc);
|
||||
void Get_MSURF_Descriptor_64(const cv::KeyPoint& kpt, float* desc);
|
||||
|
||||
// Descriptor Mode -> 1 M-SURF 128
|
||||
void Get_MSURF_Upright_Descriptor_128(const cv::KeyPoint& kpt, float* desc);
|
||||
void Get_MSURF_Descriptor_128(const cv::KeyPoint& kpt, float *desc);
|
||||
|
||||
// Descriptor Mode -> 2 G-SURF 64
|
||||
void Get_GSURF_Upright_Descriptor_64(const cv::KeyPoint& kpt, float* desc);
|
||||
void Get_GSURF_Descriptor_64(const cv::KeyPoint& kpt, float *desc);
|
||||
|
||||
// Descriptor Mode -> 2 G-SURF 128
|
||||
void Get_GSURF_Upright_Descriptor_128(const cv::KeyPoint& kpt, float* desc);
|
||||
void Get_GSURF_Descriptor_128(const cv::KeyPoint& kpt, float* desc);
|
||||
};
|
||||
|
||||
//*************************************************************************************
|
||||
|
||||
Reference in New Issue
Block a user