Commit 6d500cc6 authored by Ievgen Khvedchenia's avatar Ievgen Khvedchenia

Merge KAZE and AKAZE features with most recent version

parent d27ed856
This diff is collapsed.
...@@ -6,148 +6,84 @@ ...@@ -6,148 +6,84 @@
* @author Pablo F. Alcantarilla, Jesus Nuevo * @author Pablo F. Alcantarilla, Jesus Nuevo
*/ */
#ifndef _AKAZE_H_ #pragma once
#define _AKAZE_H_
//*************************************************************************************
//*************************************************************************************
/* ************************************************************************* */
// Includes // Includes
#include "config.h" #include "precomp.hpp"
#include "fed.h" #include "AKAZEConfig.h"
#include "nldiffusion_functions.h"
//*************************************************************************************
//*************************************************************************************
/* ************************************************************************* */
// AKAZE Class Declaration // AKAZE Class Declaration
class AKAZEFeatures { class AKAZEFeatures {
private: private:
// Parameters of the AKAZE class AKAZEOptions options_; ///< Configuration options for AKAZE
int omax_; // Maximum octave level std::vector<TEvolution> evolution_; ///< Vector of nonlinear diffusion evolution
int noctaves_; // Number of octaves
int nsublevels_; // Number of sublevels per octave level /// FED parameters
int img_width_; // Width of the original image int ncycles_; ///< Number of cycles
int img_height_; // Height of the original image bool reordering_; ///< Flag for reordering time steps
float soffset_; // Base scale offset std::vector<std::vector<float > > tsteps_; ///< Vector of FED dynamic time steps
float factor_size_; // Factor for the multiscale derivatives std::vector<int> nsteps_; ///< Vector of number of steps per cycle
float sderivatives_; // Standard deviation of the Gaussian for the nonlinear diff. derivatives
float kcontrast_; // The contrast parameter for the scalar nonlinear diffusion /// Matrices for the M-LDB descriptor computation
float dthreshold_; // Feature detector threshold response cv::Mat descriptorSamples_; // List of positions in the grids to sample LDB bits from.
int diffusivity_; // Diffusivity type, 0->PM G1, 1->PM G2, 2-> Weickert, 3->Charbonnier cv::Mat descriptorBits_;
int descriptor_; // Descriptor mode: cv::Mat bitMask_;
// 0-> SURF_UPRIGHT, 1->SURF
// 2-> M-SURF_UPRIGHT, 3->M-SURF /// Computation times variables in ms
// 4-> M-LDB_UPRIGHT, 5->M-LDB AKAZETiming timing_;
int descriptor_size_; // Size of the descriptor in bits. Use 0 for the full descriptor
int descriptor_pattern_size_; // Size of the pattern. Actual size sampled is 2*pattern_size
int descriptor_channels_; // Number of channels to consider in the M-LDB descriptor
bool save_scale_space_; // For saving scale space images
bool verbosity_; // Verbosity level
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
// Some matrices for the M-LDB descriptor computation
cv::Mat descriptorSamples_; // List of positions in the grids to sample LDB bits from.
cv::Mat descriptorBits_;
cv::Mat bitMask_;
// Computation times variables in ms
double tkcontrast_; // Kcontrast factor computation
double tscale_; // Nonlinear Scale space generation
double tderivatives_; // Multiscale derivatives
double tdetector_; // Feature detector
double textrema_; // Scale Space extrema
double tsubpixel_; // Subpixel refinement
double tdescriptor_; // Feature descriptors
public: public:
// Constructor /// Constructor with input arguments
AKAZEFeatures(const AKAZEOptions &options); AKAZEFeatures(const AKAZEOptions& options);
// Destructor /// Destructor
~AKAZEFeatures(void); ~AKAZEFeatures();
// Setters /// Scale Space methods
void Set_Octave_Max(const int& omax) { void Allocate_Memory_Evolution();
omax_ = omax; int Create_Nonlinear_Scale_Space(const cv::Mat& img);
} void Feature_Detection(std::vector<cv::KeyPoint>& kpts);
void Set_NSublevels(const int& nsublevels) { void Compute_Determinant_Hessian_Response(void);
nsublevels_ = nsublevels; void Compute_Multiscale_Derivatives(void);
} void Find_Scale_Space_Extrema(std::vector<cv::KeyPoint>& kpts);
void Set_Save_Scale_Space_Flag(const bool& save_scale_space) { void Do_Subpixel_Refinement(std::vector<cv::KeyPoint>& kpts);
save_scale_space_ = save_scale_space; void Feature_Suppression_Distance(std::vector<cv::KeyPoint>& kpts, float mdist) const;
}
void Set_Image_Width(const int& img_width) { // Feature description methods
img_width_ = img_width; void Compute_Descriptors(std::vector<cv::KeyPoint>& kpts, cv::Mat& desc);
} void Compute_Main_Orientation(cv::KeyPoint& kpt) const;
void Set_Image_Height(const int& img_height) {
img_height_ = img_height; // SURF Pattern Descriptor
} void Get_SURF_Descriptor_Upright_64(const cv::KeyPoint& kpt, float* desc) const;
void Get_SURF_Descriptor_64(const cv::KeyPoint& kpt, float* desc) const;
// Getters
int Get_Image_Width(void) { // M-SURF Pattern Descriptor
return img_width_; void Get_MSURF_Upright_Descriptor_64(const cv::KeyPoint& kpt, float* desc) const;
} void Get_MSURF_Descriptor_64(const cv::KeyPoint& kpt, float* desc) const;
int Get_Image_Height(void) {
return img_height_; // M-LDB Pattern Descriptor
} void Get_Upright_MLDB_Full_Descriptor(const cv::KeyPoint& kpt, unsigned char* desc) const;
double Get_Time_KContrast(void) { void Get_MLDB_Full_Descriptor(const cv::KeyPoint& kpt, unsigned char* desc) const;
return tkcontrast_; void Get_Upright_MLDB_Descriptor_Subset(const cv::KeyPoint& kpt, unsigned char* desc);
} void Get_MLDB_Descriptor_Subset(const cv::KeyPoint& kpt, unsigned char* desc);
double Get_Time_Scale_Space(void) {
return tscale_; // Methods for saving some results and showing computation times
} void Save_Scale_Space();
double Get_Time_Derivatives(void) { void Save_Detector_Responses();
return tderivatives_; void Show_Computation_Times() const;
}
double Get_Time_Detector(void) { /// Return the computation times
return tdetector_; AKAZETiming Get_Computation_Times() const {
} return timing_;
double Get_Time_Descriptor(void) { }
return tdescriptor_;
}
// Scale Space methods
void Allocate_Memory_Evolution(void);
int Create_Nonlinear_Scale_Space(const cv::Mat& img);
void Feature_Detection(std::vector<cv::KeyPoint>& kpts);
void Compute_Determinant_Hessian_Response(void);
void Compute_Multiscale_Derivatives(void);
void Find_Scale_Space_Extrema(std::vector<cv::KeyPoint>& kpts);
void Do_Subpixel_Refinement(std::vector<cv::KeyPoint>& kpts);
void Feature_Suppression_Distance(std::vector<cv::KeyPoint>& kpts, float mdist);
// Feature description methods
void Compute_Descriptors(std::vector<cv::KeyPoint>& kpts, cv::Mat& desc);
void Compute_Main_Orientation_SURF(cv::KeyPoint& kpt);
// SURF Pattern Descriptor
void Get_SURF_Descriptor_Upright_64(const cv::KeyPoint& kpt, float *desc);
void Get_SURF_Descriptor_64(const cv::KeyPoint& kpt, float *desc);
// M-SURF Pattern Descriptor
void Get_MSURF_Upright_Descriptor_64(const cv::KeyPoint& kpt, float *desc);
void Get_MSURF_Descriptor_64(const cv::KeyPoint& kpt, float *desc);
// M-LDB Pattern Descriptor
void Get_Upright_MLDB_Full_Descriptor(const cv::KeyPoint& kpt, unsigned char *desc);
void Get_MLDB_Full_Descriptor(const cv::KeyPoint& kpt, unsigned char *desc);
void Get_Upright_MLDB_Descriptor_Subset(const cv::KeyPoint& kpt, unsigned char *desc);
void Get_MLDB_Descriptor_Subset(const cv::KeyPoint& kpt, unsigned char *desc);
}; };
//************************************************************************************* /* ************************************************************************* */
//*************************************************************************************
// Inline functions // Inline functions
/** /**
* @brief This function sets default parameters for the A-KAZE detector. * @brief This function sets default parameters for the A-KAZE detector.
...@@ -157,13 +93,8 @@ void setDefaultAKAZEOptions(AKAZEOptions& options); ...@@ -157,13 +93,8 @@ void setDefaultAKAZEOptions(AKAZEOptions& options);
// Inline functions // Inline functions
void generateDescriptorSubsample(cv::Mat& sampleList, cv::Mat& comparisons, void generateDescriptorSubsample(cv::Mat& sampleList, cv::Mat& comparisons,
int nbits, int pattern_size, int nchannels); int nbits, int pattern_size, int nchannels);
float get_angle(float x, float y); float get_angle(float x, float y);
float gaussian(float x, float y, float sigma); float gaussian(float x, float y, float sigma);
void check_descriptor_limits(int& x, int& y, const int width, const int height); void check_descriptor_limits(int& x, int& y, int width, int height);
int fRound(float flt); int fRound(float flt);
//*************************************************************************************
//*************************************************************************************
#endif
...@@ -9,13 +9,7 @@ ...@@ -9,13 +9,7 @@
/* ************************************************************************* */ /* ************************************************************************* */
// OpenCV // OpenCV
#include <opencv2/opencv.hpp> #include "precomp.hpp"
#include <opencv2/features2d/features2d.hpp>
// OpenMP
#ifdef _OPENMP
# include <omp.h>
#endif
// System Includes // System Includes
#include <string> #include <string>
......
#ifndef _NLDIFFUSION_FUNCTIONS_H_ /**
#define _NLDIFFUSION_FUNCTIONS_H_ * @file nldiffusion_functions.h
* @brief Functions for nonlinear diffusion filtering applications
* @date Sep 15, 2013
* @author Pablo F. Alcantarilla, Jesus Nuevo
*/
//****************************************************************************** #pragma once
//******************************************************************************
/* ************************************************************************* */
// Includes // Includes
#include "precomp.hpp" #include "precomp.hpp"
// OpenMP Includes /* ************************************************************************* */
#ifdef _OPENMP
# include <omp.h>
#endif
//*************************************************************************************
//*************************************************************************************
// Declaration of functions // Declaration of functions
void gaussian_2D_convolution(const cv::Mat& src, cv::Mat& dst, const size_t& ksize_x, void gaussian_2D_convolution(const cv::Mat& src, cv::Mat& dst, const size_t& ksize_x,
const size_t& ksize_y, const float& sigma); const size_t& ksize_y, const float& sigma);
...@@ -24,8 +21,8 @@ void pm_g1(const cv::Mat& Lx, const cv::Mat& Ly, cv::Mat& dst, const float& k); ...@@ -24,8 +21,8 @@ void pm_g1(const cv::Mat& Lx, const cv::Mat& Ly, cv::Mat& dst, const float& k);
void pm_g2(const cv::Mat& Lx, const cv::Mat& Ly, cv::Mat& dst, const float& k); void pm_g2(const cv::Mat& Lx, const cv::Mat& Ly, cv::Mat& dst, const float& k);
void weickert_diffusivity(const cv::Mat& Lx, const cv::Mat& Ly, cv::Mat& dst, const float& k); void weickert_diffusivity(const cv::Mat& Lx, const cv::Mat& Ly, cv::Mat& dst, const float& k);
void charbonnier_diffusivity(const cv::Mat& Lx, const cv::Mat& Ly, cv::Mat& dst, const float& k); void charbonnier_diffusivity(const cv::Mat& Lx, const cv::Mat& Ly, cv::Mat& dst, const float& k);
float compute_k_percentile(const cv::Mat& img, const float& perc, const float& gscale, float compute_k_percentile(const cv::Mat& img, float perc, float gscale,
const size_t& nbins, const size_t& ksize_x, const size_t& ksize_y); size_t nbins, size_t ksize_x, size_t ksize_y);
void compute_scharr_derivatives(const cv::Mat& src, cv::Mat& dst, const size_t& xorder, void compute_scharr_derivatives(const cv::Mat& src, cv::Mat& dst, const size_t& xorder,
const size_t& yorder, const size_t& scale); const size_t& yorder, const size_t& scale);
void nld_step_scalar(cv::Mat& Ld, const cv::Mat& c, cv::Mat& Lstep, const float& stepsize); void nld_step_scalar(cv::Mat& Ld, const cv::Mat& c, cv::Mat& Lstep, const float& stepsize);
...@@ -33,9 +30,5 @@ void downsample_image(const cv::Mat& src, cv::Mat& dst); ...@@ -33,9 +30,5 @@ void downsample_image(const cv::Mat& src, cv::Mat& dst);
void halfsample_image(const cv::Mat& src, cv::Mat& dst); void halfsample_image(const cv::Mat& src, cv::Mat& dst);
void compute_derivative_kernels(cv::OutputArray kx_, cv::OutputArray ky_, void compute_derivative_kernels(cv::OutputArray kx_, cv::OutputArray ky_,
const size_t& dx, const size_t& dy, const size_t& scale); const size_t& dx, const size_t& dy, const size_t& scale);
bool check_maximum_neighbourhood(const cv::Mat& img, int dsize, float value,
//************************************************************************************* int row, int col, bool same_img);
//*************************************************************************************
#endif
...@@ -262,11 +262,7 @@ void compute_derivative_kernels(cv::OutputArray _kx, cv::OutputArray _ky, ...@@ -262,11 +262,7 @@ void compute_derivative_kernels(cv::OutputArray _kx, cv::OutputArray _ky,
for (int k = 0; k < 2; k++) { for (int k = 0; k < 2; k++) {
Mat* kernel = k == 0 ? &kx : &ky; Mat* kernel = k == 0 ? &kx : &ky;
int order = k == 0 ? dx : dy; int order = k == 0 ? dx : dy;
std::vector<float> kerI(ksize); std::vector<float> kerI(ksize, 0.0f);
for (int t=0; t<ksize; t++) {
kerI[t] = 0;
}
if (order == 0) { if (order == 0) {
kerI[0] = norm, kerI[ksize/2] = w*norm, kerI[ksize-1] = norm; kerI[0] = norm, kerI[ksize/2] = w*norm, kerI[ksize-1] = norm;
......
File mode changed from 100755 to 100644
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment