Skip to content

Commit 5e64ac0

Browse files
author
GilLevi
committed
added tests and renamed LATCH
1 parent f7c3099 commit 5e64ac0

File tree

5 files changed

+83
-7
lines changed

5 files changed

+83
-7
lines changed

modules/xfeatures2d/include/opencv2/xfeatures2d.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ Note: the descriptor can be coupled with any keypoint extractor. The only demand
166166
Note: a complete example can be found under /samples/cpp/tutorial_code/xfeatures2D/latch_match.cpp
167167
168168
*/
169-
class CV_EXPORTS LATCHDescriptorExtractor : public DescriptorExtractor
169+
class CV_EXPORTS LATCH : public DescriptorExtractor
170170
{
171171
public:
172-
static Ptr<LATCHDescriptorExtractor> create(int bytes = 32, bool rotationInvariance = true, int half_ssd_size=3);
172+
static Ptr<LATCH> create(int bytes = 32, bool rotationInvariance = true, int half_ssd_size=3);
173173
};
174174

175175

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "perf_precomp.hpp"
2+
3+
using namespace std;
4+
using namespace cv;
5+
using namespace cv::xfeatures2d;
6+
using namespace perf;
7+
using std::tr1::make_tuple;
8+
using std::tr1::get;
9+
10+
typedef perf::TestBaseWithParam<std::string> latch;
11+
12+
#define LATCH_IMAGES \
13+
"cv/detectors_descriptors_evaluation/images_datasets/leuven/img1.png",\
14+
"stitching/a3.png"
15+
16+
PERF_TEST_P(latch, extract, testing::Values(LATCH_IMAGES))
17+
{
18+
string filename = getDataPath(GetParam());
19+
Mat frame = imread(filename, IMREAD_GRAYSCALE);
20+
ASSERT_FALSE(frame.empty()) << "Unable to load source image " << filename;
21+
22+
Mat mask;
23+
declare.in(frame).time(90);
24+
25+
Ptr<SURF> detector = SURF::create();
26+
vector<KeyPoint> points;
27+
detector->detect(frame, points, mask);
28+
29+
Ptr<LATCH> descriptor = LATCH::create();
30+
vector<uchar> descriptors;
31+
TEST_CYCLE() descriptor->compute(frame, points, descriptors);
32+
33+
SANITY_CHECK(descriptors, 1e-4);
34+
}

modules/xfeatures2d/src/latch.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ namespace cv
5858
/*
5959
* LATCH Descriptor
6060
*/
61-
class LATCHDescriptorExtractorImpl : public LATCHDescriptorExtractor
61+
class LATCHDescriptorExtractorImpl : public LATCH
6262
{
6363
public:
6464
enum { PATCH_SIZE = 48 };
@@ -86,7 +86,7 @@ namespace cv
8686
std::vector<int> sampling_points_ ;
8787
};
8888

89-
Ptr<LATCHDescriptorExtractor> LATCHDescriptorExtractor::create(int bytes, bool rotationInvariance, int half_ssd_size)
89+
Ptr<LATCH> LATCH::create(int bytes, bool rotationInvariance, int half_ssd_size)
9090
{
9191
return makePtr<LATCHDescriptorExtractorImpl>(bytes, rotationInvariance, half_ssd_size);
9292
}
@@ -488,10 +488,18 @@ namespace cv
488488
fs << "descriptorSize" << bytes_;
489489
}
490490

491-
void LATCHDescriptorExtractorImpl::compute(InputArray image,
491+
void LATCHDescriptorExtractorImpl::compute(InputArray _image,
492492
std::vector<KeyPoint>& keypoints,
493-
OutputArray descriptors)
493+
OutputArray _descriptors)
494494
{
495+
Mat image = _image.getMat();
496+
497+
if ( image.empty() )
498+
return;
499+
500+
if ( keypoints.empty() )
501+
return;
502+
495503

496504
Mat grayImage;
497505
GaussianBlur(image, grayImage, cv::Size(3, 3), 2, 2);
@@ -502,9 +510,26 @@ namespace cv
502510

503511
//Remove keypoints very close to the border
504512
KeyPointsFilter::runByImageBorder(keypoints, image.size(), PATCH_SIZE / 2 + half_ssd_size_);
513+
514+
bool _1d = false;
515+
Mat descriptors;
516+
517+
_1d = _descriptors.kind() == _InputArray::STD_VECTOR && _descriptors.type() == CV_8U;
518+
if( _1d )
519+
{
520+
_descriptors.create((int)keypoints.size()*bytes_, 1, CV_8U);
521+
descriptors = _descriptors.getMat().reshape(1, (int)keypoints.size());
522+
}
523+
else
524+
{
525+
_descriptors.create((int)keypoints.size(), bytes_, CV_8U);
526+
descriptors = _descriptors.getMat();
527+
}
505528

529+
//_descriptors.create((int)keypoints.size(), bytes_, CV_8U);
530+
// prepare descriptors as mat
531+
//Mat descriptors = _descriptors.getMat();
506532

507-
descriptors.create((int)keypoints.size(), bytes_, CV_8U);
508533

509534
test_fn_(grayImage, keypoints, descriptors, sampling_points_, rotationInvariance_, half_ssd_size_);
510535
}

modules/xfeatures2d/test/test_features2d.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,13 @@ TEST( Features2d_DescriptorExtractor_LUCID, regression )
10321032
test.safe_run();
10331033
}
10341034

1035+
TEST( Features2d_DescriptorExtractor_LATCH, regression )
1036+
{
1037+
CV_DescriptorExtractorTest<Hamming> test( "descriptor-latch", 1,
1038+
LATCH::create() );
1039+
test.safe_run();
1040+
}
1041+
10351042

10361043

10371044
/*#if CV_SSE2

modules/xfeatures2d/test/test_rotation_and_scale_invariance.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,16 @@ TEST(Features2d_RotationInvariance_Descriptor_SIFT, regression)
651651
test.safe_run();
652652
}
653653

654+
TEST(Features2d_RotationInvariance_Descriptor_LATCH, regression)
655+
{
656+
DescriptorRotationInvarianceTest test(SIFT::create(),
657+
LATCH::create(),
658+
NORM_HAMMING,
659+
0.9999f);
660+
test.safe_run();
661+
}
662+
663+
654664
/*
655665
* Detector's scale invariance check
656666
*/

0 commit comments

Comments
 (0)