1 // Copyright (c) 2015 Pierre MOULON. 2 3 // This Source Code Form is subject to the terms of the Mozilla Public 4 // License, v. 2.0. If a copy of the MPL was not distributed with this 5 // file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 7 #ifndef OPENMVG_FEATURES_AKAZE_IMAGE_DESCRIBER_HPP 8 #define OPENMVG_FEATURES_AKAZE_IMAGE_DESCRIBER_HPP 9 10 11 #include "openMVG/features/akaze/AKAZE.hpp" 12 #include "openMVG/features/image_describer.hpp" 13 #include "openMVG/features/regions_factory.hpp" 14 #include "openMVG/system/logger.hpp" 15 16 #include <numeric> 17 18 namespace openMVG { 19 namespace features { 20 21 22 enum EAKAZE_DESCRIPTOR 23 { 24 AKAZE_MSURF, 25 AKAZE_LIOP, 26 AKAZE_MLDB 27 }; 28 29 class AKAZE_Image_describer : public Image_describer 30 { 31 public: 32 33 struct Params 34 { ParamsopenMVG::features::AKAZE_Image_describer::Params35 Params( 36 const features::AKAZE::Params config = features::AKAZE::Params(), 37 EAKAZE_DESCRIPTOR eAkazeDescriptor = AKAZE_MSURF 38 ):options_(config), eAkazeDescriptor_(eAkazeDescriptor){} 39 40 template<class Archive> 41 void serialize(Archive & ar); 42 43 // Parameters 44 features::AKAZE::Params options_; 45 EAKAZE_DESCRIPTOR eAkazeDescriptor_; 46 }; 47 AKAZE_Image_describer(const Params & params=Params (),bool bOrientation=true)48 AKAZE_Image_describer( 49 const Params & params = Params(), 50 bool bOrientation = true 51 ):Image_describer(), params_(params), bOrientation_(bOrientation) {} 52 53 static std::unique_ptr<AKAZE_Image_describer> create(const Params& params, bool orientation = true); 54 Set_configuration_preset(EDESCRIBER_PRESET preset)55 bool Set_configuration_preset(EDESCRIBER_PRESET preset) override 56 { 57 switch (preset) 58 { 59 case NORMAL_PRESET: 60 params_.options_.fThreshold = features::AKAZE::Params().fThreshold; 61 break; 62 case HIGH_PRESET: 63 params_.options_.fThreshold = features::AKAZE::Params().fThreshold/10.f; 64 break; 65 case ULTRA_PRESET: 66 params_.options_.fThreshold = features::AKAZE::Params().fThreshold/100.f; 67 break; 68 default: 69 OPENMVG_LOG_ERROR << "Unknow preset configuration"; 70 return false; 71 } 72 return true; 73 } 74 75 template<class Archive> 76 void serialize(Archive & ar); 77 78 protected: GetfDescFactor() const79 virtual float GetfDescFactor() const 80 { 81 return 10.f*sqrtf(2.f); 82 } 83 84 Params params_; 85 bool bOrientation_; 86 }; 87 88 class AKAZE_Image_describer_SURF : public AKAZE_Image_describer 89 { 90 public: 91 92 using Regions_type = AKAZE_Float_Regions; 93 AKAZE_Image_describer_SURF(const Params & params=Params (),bool bOrientation=true)94 AKAZE_Image_describer_SURF( 95 const Params& params = Params(), 96 bool bOrientation = true 97 ) 98 :AKAZE_Image_describer(params, bOrientation) { } 99 Describe(const image::Image<unsigned char> & image,const image::Image<unsigned char> * mask=nullptr)100 std::unique_ptr<Regions> Describe( 101 const image::Image<unsigned char>& image, 102 const image::Image<unsigned char>* mask = nullptr 103 ) override 104 { 105 return Describe_AKAZE_SURF(image, mask); 106 } 107 Allocate() const108 std::unique_ptr<Regions> Allocate() const override 109 { 110 return std::unique_ptr<Regions_type>(new Regions_type); 111 } 112 113 std::unique_ptr<Regions_type> Describe_AKAZE_SURF( 114 const image::Image<unsigned char>& image, 115 const image::Image<unsigned char>* mask = nullptr 116 ); 117 }; 118 119 class AKAZE_Image_describer_LIOP : public AKAZE_Image_describer { 120 public: 121 using Regions_type = AKAZE_Liop_Regions; 122 AKAZE_Image_describer_LIOP(const Params & params=Params (),bool bOrientation=true)123 AKAZE_Image_describer_LIOP( 124 const Params& params = Params(), 125 bool bOrientation = true 126 ):AKAZE_Image_describer(params, bOrientation) { } 127 Describe(const image::Image<unsigned char> & image,const image::Image<unsigned char> * mask=nullptr)128 std::unique_ptr<Regions> Describe( 129 const image::Image<unsigned char>& image, 130 const image::Image<unsigned char>* mask = nullptr 131 ) override 132 { 133 return Describe_AKAZE_LIOP(image, mask); 134 } 135 Allocate() const136 std::unique_ptr<Regions> Allocate() const override 137 { 138 return std::unique_ptr<Regions_type>(new Regions_type); 139 } 140 141 std::unique_ptr<Regions_type> Describe_AKAZE_LIOP( 142 const image::Image<unsigned char>& image, 143 const image::Image<unsigned char>* mask = nullptr 144 ); 145 }; 146 147 class AKAZE_Image_describer_MLDB : public AKAZE_Image_describer 148 { 149 public: 150 using Regions_type = AKAZE_Binary_Regions; 151 AKAZE_Image_describer_MLDB(const Params & params=Params (),bool bOrientation=true)152 AKAZE_Image_describer_MLDB( 153 const Params& params = Params(), 154 bool bOrientation = true 155 ):AKAZE_Image_describer(params, bOrientation) { } 156 Describe(const image::Image<unsigned char> & image,const image::Image<unsigned char> * mask=nullptr)157 std::unique_ptr<Regions> Describe( 158 const image::Image<unsigned char>& image, 159 const image::Image<unsigned char>* mask = nullptr 160 ) override 161 { 162 return Describe_AKAZE_MLDB(image, mask); 163 } 164 Allocate() const165 std::unique_ptr<Regions> Allocate() const override 166 { 167 return std::unique_ptr<Regions_type>(new Regions_type); 168 } 169 170 std::unique_ptr<Regions_type> Describe_AKAZE_MLDB( 171 const image::Image<unsigned char>& image, 172 const image::Image<unsigned char>* mask = nullptr 173 ); 174 175 protected: GetfDescFactor() const176 float GetfDescFactor() const override 177 { 178 return 11.f*sqrtf(2.f); 179 } 180 }; 181 182 } // namespace features 183 } // namespace openMVG 184 185 #endif // OPENMVG_FEATURES_AKAZE_IMAGE_DESCRIBER_HPP 186