Commit 6f07e2fc authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

Merge pull request #1419 from terfendail:latch_blur

parents d71da5df 97037fba
......@@ -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<LATCH> create(int bytes = 32, bool rotationInvariance = true, int half_ssd_size=3);
CV_WRAP static Ptr<LATCH> 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
......
......@@ -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<int> sampling_points_ ;
};
Ptr<LATCH> LATCH::create(int bytes, bool rotationInvariance, int half_ssd_size)
Ptr<LATCH> LATCH::create(int bytes, bool rotationInvariance, int half_ssd_size, double sigma)
{
return makePtr<LATCHDescriptorExtractorImpl>(bytes, rotationInvariance, half_ssd_size);
return makePtr<LATCHDescriptorExtractorImpl>(bytes, rotationInvariance, half_ssd_size, sigma);
}
void CalcuateSums(int count, const std::vector<int> &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;
......
......@@ -1121,7 +1121,7 @@ TEST( Features2d_DescriptorExtractor_LUCID, regression )
TEST( Features2d_DescriptorExtractor_LATCH, regression )
{
CV_DescriptorExtractorTest<Hamming> test( "descriptor-latch", 1,
LATCH::create() );
LATCH::create(32, true, 3, 0) );
test.safe_run();
}
......
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