Skip to content
Snippets Groups Projects
Commit 542c137c authored by Angel Santamaria-Navarro's avatar Angel Santamaria-Navarro
Browse files

added descriptor sift

parent e9332e1e
No related branches found
No related tags found
No related merge requests found
...@@ -32,6 +32,8 @@ SET(sources ...@@ -32,6 +32,8 @@ SET(sources
descriptors/descriptor_base.cpp descriptors/descriptor_base.cpp
descriptors/orb/descriptor_orb.cpp descriptors/orb/descriptor_orb.cpp
descriptors/orb/descriptor_orb_load_yaml.cpp descriptors/orb/descriptor_orb_load_yaml.cpp
descriptors/sift/descriptor_sift.cpp
descriptors/sift/descriptor_sift_load_yaml.cpp
matchers/matcher_base.cpp ) matchers/matcher_base.cpp )
# application header files # application header files
...@@ -58,6 +60,7 @@ SET(headers ...@@ -58,6 +60,7 @@ SET(headers
descriptors/descriptor_factory.h descriptors/descriptor_factory.h
descriptors/descriptor_base.h descriptors/descriptor_base.h
descriptors/orb/descriptor_orb.h descriptors/orb/descriptor_orb.h
descriptors/sift/descriptor_sift.h
matchers/matcher_factory.h matchers/matcher_factory.h
matchers/matcher_base.h) matchers/matcher_base.h)
......
#include "descriptor_sift.h"
namespace vision_utils {
DescriptorSIFT::DescriptorSIFT(void)
{}
DescriptorSIFT::~DescriptorSIFT(void)
{}
} /* namespace vision_utils */
// Register in the DescriptorsFactory
namespace vision_utils
{
VU_REGISTER_DESCRIPTOR("SIFT", DescriptorSIFT);
} /* namespace vision_utils */
#ifndef _DESCRIPTOR_SIFT_H_
#define _DESCRIPTOR_SIFT_H_
#include "../descriptor_base.h"
#include "../descriptor_factory.h"
// yaml-cpp library
#ifdef USING_YAML
#include <yaml-cpp/yaml.h>
#endif
namespace vision_utils {
// Create all pointers
VU_PTR_TYPEDEFS(DescriptorSIFT);
VU_PTR_TYPEDEFS(DescriptorParamsSIFT);
/** \brief Class parameters
*
*/
struct DescriptorParamsSIFT: public ParamsBase
{
int nfeatures=0; // The number of best features to retain. The features are ranked by their scores (measured in SIFT algorithm as the local contrast)
int nOctaveLayers=3; // The number of layers in each octave. 3 is the value used in D. Lowe paper. The number of octaves is computed automatically from the image resolution.
double contrastThreshold=0.04; // The contrast threshold used to filter out weak features in semi-uniform (low-contrast) regions. The larger the threshold, the less features are produced by the detector.
double edgeThreshold=10; // The threshold used to filter out edge-like features. Note that the its meaning is different from the contrastThreshold, i.e. the larger the edgeThreshold, the less features are filtered out (more features are retained).
double sigma=1.6; // The sigma of the Gaussian applied to the input image at the octave #0. If your image is captured with a weak camera with soft lenses, you might want to reduce the number.
};
/** \brief DETECTOR class
*
*/
class DescriptorSIFT : public DescriptorBase {
public:
DescriptorSIFT();
virtual ~DescriptorSIFT(void);
// Factory method
static DescriptorBasePtr create(const std::string& _unique_name, const ParamsBasePtr _params);
private:
void defineDescriptor(const ParamsBasePtr _params);
};
/*
* brief Define detector
*/
inline void DescriptorSIFT::defineDescriptor(const ParamsBasePtr _params)
{
DescriptorParamsSIFTPtr params_ptr = std::static_pointer_cast<DescriptorParamsSIFT>(_params);
descriptor_ = cv::xfeatures2d::SIFT::create(params_ptr->nfeatures,
params_ptr->nOctaveLayers,
params_ptr->contrastThreshold,
params_ptr->edgeThreshold,
params_ptr->sigma);
}
/*
* brief Create object in factory
*/
inline DescriptorBasePtr DescriptorSIFT::create(const std::string& _unique_name, const ParamsBasePtr _params)
{
DescriptorSIFTPtr det_ptr = std::make_shared<DescriptorSIFT>();
det_ptr->setName(_unique_name);
det_ptr->defineDescriptor(_params);
return det_ptr;
}
} /* namespace vision_utils */
#endif /* _DESCRIPTOR_SIFT_H_ */
#include "descriptor_sift.h"
#ifdef USING_YAML
// yaml-cpp library
#include <yaml-cpp/yaml.h>
namespace vision_utils
{
namespace
{
static ParamsBasePtr createParamsSIFTDescriptor(const std::string & _filename_dot_yaml)
{
DescriptorParamsSIFTPtr params_ptr = std::make_shared<DescriptorParamsSIFT>();
using std::string;
using YAML::Node;
Node yaml_params = YAML::LoadFile(_filename_dot_yaml);
if (!yaml_params.IsNull())
{
Node d_yaml = yaml_params["descriptor"];
if(d_yaml["type"].as<string>() == "SIFT")
{
params_ptr->nfeatures = d_yaml["nfeatures"].as<int>();
params_ptr->nOctaveLayers = d_yaml["nOctaveLayers"].as<int>();
params_ptr->contrastThreshold = d_yaml["contrastThreshold"].as<double>();
params_ptr->edgeThreshold = d_yaml["edgeThreshold"].as<double>();
params_ptr->sigma = d_yaml["sigma"].as<double>();
}else
{
std::cerr << "Bad configuration file. Wrong type " << d_yaml["type"].as<string>() << std::endl;
return nullptr;
}
}
return params_ptr;
}
// Register in the SensorFactory
const bool registered_detSIFT_params = ParamsFactory::get().registerCreator("SIFT", createParamsSIFTDescriptor);
} /* namespace [unnamed] */
} /* namespace vision_utils */
#endif /* IF USING_YAML */
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
// Descriptors // Descriptors
#include "../descriptors/orb/descriptor_orb.h" #include "../descriptors/orb/descriptor_orb.h"
//#include "../descriptors/sift/descriptor_sift.h" #include "../descriptors/sift/descriptor_sift.h"
//#include "../descriptors/surf/descriptor_surf.h" //#include "../descriptors/surf/descriptor_surf.h"
//#include "../descriptors/kaze/descriptor_kaze.h" //#include "../descriptors/kaze/descriptor_kaze.h"
//#include "../descriptors/akaze/descriptor_akaze.h" //#include "../descriptors/akaze/descriptor_akaze.h"
...@@ -93,8 +93,8 @@ int main(void) ...@@ -93,8 +93,8 @@ int main(void)
if (des_name.compare("ORB") == 0) if (des_name.compare("ORB") == 0)
des_ptr = std::static_pointer_cast<DescriptorORB>(des_ptr); des_ptr = std::static_pointer_cast<DescriptorORB>(des_ptr);
// else if (des_name.compare("SIFT") == 0) else if (des_name.compare("SIFT") == 0)
// des_ptr = std::static_pointer_cast<DescriptorSIFT>(des_ptr); des_ptr = std::static_pointer_cast<DescriptorSIFT>(des_ptr);
// else if (des_name.compare("SURF") == 0) // else if (des_name.compare("SURF") == 0)
// des_ptr = std::static_pointer_cast<DescriptorSURF>(des_ptr); // des_ptr = std::static_pointer_cast<DescriptorSURF>(des_ptr);
// else if (des_name.compare("KAZE") == 0) // else if (des_name.compare("KAZE") == 0)
......
sensor: sensor:
type: "USB_CAM" type: "USB_CAM"
detector: detector:
type: "ORB" type: "ORB"
nfeatures: 100 nfeatures: 100
scale factor: 1.2 scale factor: 2
nlevels: 8 nlevels: 8
edge threshold: 8 # 16 edge threshold: 8 # 16
first level: 0 first level: 0
WTA_K: 2 # See: http://docs.opencv.org/trunk/db/d95/classcv_1_1ORB.html#a180ae17d3300cf2c619aa240d9b607e5 WTA_K: 2 # See: http://docs.opencv.org/trunk/db/d95/classcv_1_1ORB.html#a180ae17d3300cf2c619aa240d9b607e5
score type: 1 #enum { kBytes = 32, HARRIS_SCORE=0, FAST_SCORE=1 }; score type: 1 #enum { kBytes = 32, HARRIS_SCORE=0, FAST_SCORE=1 };
patch size: 15 # 31 patch size: 15 # 31
descriptor:
type: "ORB"
nfeatures: 100
scale factor: 2
nlevels: 8
edge threshold: 8 # 16
first level: 0
WTA_K: 2 # See: http://docs.opencv.org/trunk/db/d95/classcv_1_1ORB.html#a180ae17d3300cf2c619aa240d9b607e5
score type: 1 #enum { kBytes = 32, HARRIS_SCORE=0, FAST_SCORE=1 };
patch size: 15 # 31
sensor: sensor:
type: "USB_CAM" type: "USB_CAM"
detector: detector:
type: "SIFT" type: "SIFT"
nfeatures: 0 nfeatures: 0
nOctaveLayers: 3 nOctaveLayers: 3
contrastThreshold: 0.04 contrastThreshold: 0.04
edgeThreshold: 10 edgeThreshold: 10
sigma: 1.6 sigma: 1.6
\ No newline at end of file
descriptor:
type: "SIFT"
nfeatures: 0
nOctaveLayers: 3
contrastThreshold: 0.04
edgeThreshold: 10
sigma: 1.6
\ No newline at end of file
sensor: sensor:
type: "USB_CAM" type: "USB_CAM"
detector: detector:
type: "SURF" type: "SURF"
hessianThreshold: 400 hessianThreshold: 400
nOctaves: 4 nOctaves: 4
nOctaveLayers: 2 nOctaveLayers: 2
extended: true extended: true
upright: false upright: false
\ No newline at end of file
descriptor:
type: "SURF"
hessianThreshold: 400
nOctaves: 4
nOctaveLayers: 2
extended: true
upright: false
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment