1 /*M/////////////////////////////////////////////////////////////////////////////////////// 2 // 3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 // 5 // By downloading, copying, installing or using the software you agree to this license. 6 // If you do not agree to this license, do not download, install, 7 // copy or use the software. 8 // 9 // 10 // License Agreement 11 // For Open Source Computer Vision Library 12 // 13 // Copyright (C) 2008, Willow Garage Inc., all rights reserved. 14 // Third party copyrights are property of their respective owners. 15 // 16 // Redistribution and use in source and binary forms, with or without modification, 17 // are permitted provided that the following conditions are met: 18 // 19 // * Redistribution's of source code must retain the above copyright notice, 20 // this list of conditions and the following disclaimer. 21 // 22 // * Redistribution's in binary form must reproduce the above copyright notice, 23 // this list of conditions and the following disclaimer in the documentation 24 // and/or other materials provided with the distribution. 25 // 26 // * The name of Intel Corporation may not be used to endorse or promote products 27 // derived from this software without specific prior written permission. 28 // 29 // This software is provided by the copyright holders and contributors "as is" and 30 // any express or implied warranties, including, but not limited to, the implied 31 // warranties of merchantability and fitness for a particular purpose are disclaimed. 32 // In no event shall the Intel Corporation or contributors be liable for any direct, 33 // indirect, incidental, special, exemplary, or consequential damages 34 // (including, but not limited to, procurement of substitute goods or services; 35 // loss of use, data, or profits; or business interruption) however caused 36 // and on any theory of liability, whether in contract, strict liability, 37 // or tort (including negligence or otherwise) arising in any way out of 38 // the use of this software, even if advised of the possibility of such damage. 39 // 40 //M*/ 41 42 /* 43 OpenCV wrapper of reference implementation of 44 [1] KAZE Features. Pablo F. Alcantarilla, Adrien Bartoli and Andrew J. Davison. 45 In European Conference on Computer Vision (ECCV), Fiorenze, Italy, October 2012 46 http://www.robesafe.com/personal/pablo.alcantarilla/papers/Alcantarilla12eccv.pdf 47 @author Eugene Khvedchenya <ekhvedchenya@gmail.com> 48 */ 49 50 #include "precomp.hpp" 51 #include "kaze/KAZEFeatures.h" 52 53 namespace cv 54 { 55 56 class KAZE_Impl : public KAZE 57 { 58 public: KAZE_Impl(bool _extended,bool _upright,float _threshold,int _octaves,int _sublevels,int _diffusivity)59 KAZE_Impl(bool _extended, bool _upright, float _threshold, int _octaves, 60 int _sublevels, int _diffusivity) 61 : extended(_extended) 62 , upright(_upright) 63 , threshold(_threshold) 64 , octaves(_octaves) 65 , sublevels(_sublevels) 66 , diffusivity(_diffusivity) 67 { 68 } 69 ~KAZE_Impl()70 virtual ~KAZE_Impl() {} 71 setExtended(bool extended_)72 void setExtended(bool extended_) { extended = extended_; } getExtended() const73 bool getExtended() const { return extended; } 74 setUpright(bool upright_)75 void setUpright(bool upright_) { upright = upright_; } getUpright() const76 bool getUpright() const { return upright; } 77 setThreshold(double threshold_)78 void setThreshold(double threshold_) { threshold = (float)threshold_; } getThreshold() const79 double getThreshold() const { return threshold; } 80 setNOctaves(int octaves_)81 void setNOctaves(int octaves_) { octaves = octaves_; } getNOctaves() const82 int getNOctaves() const { return octaves; } 83 setNOctaveLayers(int octaveLayers_)84 void setNOctaveLayers(int octaveLayers_) { sublevels = octaveLayers_; } getNOctaveLayers() const85 int getNOctaveLayers() const { return sublevels; } 86 setDiffusivity(int diff_)87 void setDiffusivity(int diff_) { diffusivity = diff_; } getDiffusivity() const88 int getDiffusivity() const { return diffusivity; } 89 90 // returns the descriptor size in bytes descriptorSize() const91 int descriptorSize() const 92 { 93 return extended ? 128 : 64; 94 } 95 96 // returns the descriptor type descriptorType() const97 int descriptorType() const 98 { 99 return CV_32F; 100 } 101 102 // returns the default norm type defaultNorm() const103 int defaultNorm() const 104 { 105 return NORM_L2; 106 } 107 detectAndCompute(InputArray image,InputArray mask,std::vector<KeyPoint> & keypoints,OutputArray descriptors,bool useProvidedKeypoints)108 void detectAndCompute(InputArray image, InputArray mask, 109 std::vector<KeyPoint>& keypoints, 110 OutputArray descriptors, 111 bool useProvidedKeypoints) 112 { 113 cv::Mat img = image.getMat(); 114 if (img.type() != CV_8UC1) 115 cvtColor(image, img, COLOR_BGR2GRAY); 116 117 Mat img1_32; 118 img.convertTo(img1_32, CV_32F, 1.0 / 255.0, 0); 119 120 KAZEOptions options; 121 options.img_width = img.cols; 122 options.img_height = img.rows; 123 options.extended = extended; 124 options.upright = upright; 125 options.dthreshold = threshold; 126 options.omax = octaves; 127 options.nsublevels = sublevels; 128 options.diffusivity = diffusivity; 129 130 KAZEFeatures impl(options); 131 impl.Create_Nonlinear_Scale_Space(img1_32); 132 133 if (!useProvidedKeypoints) 134 { 135 impl.Feature_Detection(keypoints); 136 } 137 138 if (!mask.empty()) 139 { 140 cv::KeyPointsFilter::runByPixelsMask(keypoints, mask.getMat()); 141 } 142 143 if( descriptors.needed() ) 144 { 145 Mat& desc = descriptors.getMatRef(); 146 impl.Feature_Description(keypoints, desc); 147 148 CV_Assert((!desc.rows || desc.cols == descriptorSize())); 149 CV_Assert((!desc.rows || (desc.type() == descriptorType()))); 150 } 151 } 152 write(FileStorage & fs) const153 void write(FileStorage& fs) const 154 { 155 fs << "extended" << (int)extended; 156 fs << "upright" << (int)upright; 157 fs << "threshold" << threshold; 158 fs << "octaves" << octaves; 159 fs << "sublevels" << sublevels; 160 fs << "diffusivity" << diffusivity; 161 } 162 read(const FileNode & fn)163 void read(const FileNode& fn) 164 { 165 extended = (int)fn["extended"] != 0; 166 upright = (int)fn["upright"] != 0; 167 threshold = (float)fn["threshold"]; 168 octaves = (int)fn["octaves"]; 169 sublevels = (int)fn["sublevels"]; 170 diffusivity = (int)fn["diffusivity"]; 171 } 172 173 bool extended; 174 bool upright; 175 float threshold; 176 int octaves; 177 int sublevels; 178 int diffusivity; 179 }; 180 create(bool extended,bool upright,float threshold,int octaves,int sublevels,int diffusivity)181 Ptr<KAZE> KAZE::create(bool extended, bool upright, 182 float threshold, 183 int octaves, int sublevels, 184 int diffusivity) 185 { 186 return makePtr<KAZE_Impl>(extended, upright, threshold, octaves, sublevels, diffusivity); 187 } 188 } 189