From a9b8fb8300d987b4bfd40dc2f47fc32d12d5f464 Mon Sep 17 00:00:00 2001 From: Vitaly Tuzov Date: Fri, 20 Oct 2017 21:48:16 +0300 Subject: [PATCH] GaussianBlur of the source image for LATCH descriptor made optional --- .../include/opencv2/xfeatures2d.hpp | 3 +- modules/xfeatures2d/src/latch.cpp | 33 +++++++++++++------ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/modules/xfeatures2d/include/opencv2/xfeatures2d.hpp b/modules/xfeatures2d/include/opencv2/xfeatures2d.hpp index 747922b3c..e42b49a87 100644 --- a/modules/xfeatures2d/include/opencv2/xfeatures2d.hpp +++ b/modules/xfeatures2d/include/opencv2/xfeatures2d.hpp @@ -160,6 +160,7 @@ LATCH is a binary descriptor based on learned comparisons of triplets of image p * rotationInvariance - whether or not the descriptor should compansate for orientation changes. * half_ssd_size - the size of half of the mini-patches size. For example, if we would like to compare triplets of patches of size 7x7x then the half_ssd_size should be (7-1)/2 = 3. +* sigma - sigma value for GaussianBlur smoothing of the source image. Source image will be used without smoothing in case sigma value is 0. Note: the descriptor can be coupled with any keypoint extractor. The only demand is that if you use set rotationInvariance = True then you will have to use an extractor which estimates the patch orientation (in degrees). Examples for such extractors are ORB and SIFT. @@ -170,7 +171,7 @@ Note: a complete example can be found under /samples/cpp/tutorial_code/xfeatures class CV_EXPORTS_W LATCH : public Feature2D { public: - CV_WRAP static Ptr create(int bytes = 32, bool rotationInvariance = true, int half_ssd_size=3); + CV_WRAP static Ptr create(int bytes = 32, bool rotationInvariance = true, int half_ssd_size = 3, double sigma = 2.0); }; /** @brief Class implementing DAISY descriptor, described in @cite Tola10 diff --git a/modules/xfeatures2d/src/latch.cpp b/modules/xfeatures2d/src/latch.cpp index a1f54545c..8a255ed0a 100644 --- a/modules/xfeatures2d/src/latch.cpp +++ b/modules/xfeatures2d/src/latch.cpp @@ -63,7 +63,7 @@ namespace cv public: enum { PATCH_SIZE = 48 }; - LATCHDescriptorExtractorImpl(int bytes = 32, bool rotationInvariance = true, int half_ssd_size = 3); + LATCHDescriptorExtractorImpl(int bytes = 32, bool rotationInvariance = true, int half_ssd_size = 3, double sigma = 2.0); virtual void read( const FileNode& ); virtual void write( FileStorage& ) const; @@ -81,14 +81,15 @@ namespace cv PixelTestFn test_fn_; bool rotationInvariance_; int half_ssd_size_; + double sigma_; std::vector sampling_points_ ; }; - Ptr LATCH::create(int bytes, bool rotationInvariance, int half_ssd_size) + Ptr LATCH::create(int bytes, bool rotationInvariance, int half_ssd_size, double sigma) { - return makePtr(bytes, rotationInvariance, half_ssd_size); + return makePtr(bytes, rotationInvariance, half_ssd_size, sigma); } void CalcuateSums(int count, const std::vector &points, bool rotationInvariance, const Mat &grayImage, const KeyPoint &pt, int &suma, int &sumc, float cos_theta, float sin_theta, int half_ssd_size); @@ -403,8 +404,8 @@ namespace cv - LATCHDescriptorExtractorImpl::LATCHDescriptorExtractorImpl(int bytes, bool rotationInvariance, int half_ssd_size) : - bytes_(bytes), test_fn_(NULL), rotationInvariance_(rotationInvariance), half_ssd_size_(half_ssd_size) + LATCHDescriptorExtractorImpl::LATCHDescriptorExtractorImpl(int bytes, bool rotationInvariance, int half_ssd_size, double sigma) : + bytes_(bytes), test_fn_(NULL), rotationInvariance_(rotationInvariance), half_ssd_size_(half_ssd_size), sigma_(sigma) { switch (bytes) { @@ -502,15 +503,27 @@ namespace cv Mat grayImage; - GaussianBlur(image, grayImage, cv::Size(3, 3), 2, 2); - - if (image.type() != CV_8U) cvtColor(image, grayImage, COLOR_BGR2GRAY); - + switch (image.type()) + { + case CV_8UC1: + grayImage = image; + break; + case CV_8UC3: + cvtColor(image, grayImage, COLOR_BGR2GRAY); + break; + case CV_8UC4: + cvtColor(image, grayImage, COLOR_BGRA2GRAY); + break; + default: + CV_Error(Error::StsBadArg, "Image should be 8UC1, 8UC3 or 8UC4"); + } + if (sigma_ != 0.) + GaussianBlur(grayImage, grayImage, cv::Size(3, 3), sigma_, sigma_); //Remove keypoints very close to the border KeyPointsFilter::runByImageBorder(keypoints, image.size(), PATCH_SIZE / 2 + half_ssd_size_); - + bool _1d = false; Mat descriptors;