From f1e3d4d49249f127c72870807c5ae207a5d657f8 Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Thu, 12 Apr 2012 13:06:05 +0000 Subject: [PATCH] adding test for the bug #1795 --- modules/nonfree/test/test_features2d.cpp | 50 ++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/modules/nonfree/test/test_features2d.cpp b/modules/nonfree/test/test_features2d.cpp index 80eb900..a932b9b 100644 --- a/modules/nonfree/test/test_features2d.cpp +++ b/modules/nonfree/test/test_features2d.cpp @@ -1028,3 +1028,53 @@ TEST( Features2d_DescriptorExtractor_Calonder_float, regression ) test.safe_run(); } #endif*/ // CV_SSE2 + +TEST(Features2d_BruteForceDescriptorMatcher_knnMatch, regression) +{ + const int sz = 100; + const int k = 3; + + Ptr ext = DescriptorExtractor::create("SURF"); + ASSERT_TRUE(ext != NULL); + + Ptr det = FeatureDetector::create("SURF"); + //"%YAML:1.0\nhessianThreshold: 8000.\noctaves: 3\noctaveLayers: 4\nupright: 0\n" + ASSERT_TRUE(det != NULL); + + Ptr matcher = DescriptorMatcher::create("BruteForce"); + ASSERT_TRUE(matcher != NULL); + + Mat imgT(sz, sz, CV_8U, Scalar(255)); + line(imgT, Point(20, sz/2), Point(sz-21, sz/2), Scalar(100), 2); + line(imgT, Point(sz/2, 20), Point(sz/2, sz-21), Scalar(100), 2); + vector kpT; + kpT.push_back( KeyPoint(50, 50, 16, 0, 20000, 1, -1) ); + kpT.push_back( KeyPoint(42, 42, 16, 160, 10000, 1, -1) ); + Mat descT; + ext->compute(imgT, kpT, descT); + + Mat imgQ(sz, sz, CV_8U, Scalar(255)); + line(imgQ, Point(30, sz/2), Point(sz-31, sz/2), Scalar(100), 3); + line(imgQ, Point(sz/2, 30), Point(sz/2, sz-31), Scalar(100), 3); + vector kpQ; + det->detect(imgQ, kpQ); + Mat descQ; + ext->compute(imgQ, kpQ, descQ); + + vector > matches; + + matcher->knnMatch(descQ, descT, matches, k); + + //cout << "\nBest " << k << " matches to " << descT.rows << " train desc-s." << endl; + ASSERT_EQ(descQ.rows, matches.size()); + for(int i = 0; i= matches[i].size()); + for(int j = 0; j " << matches[i][j].trainIdx << endl; + ASSERT_EQ(matches[i][j].queryIdx, i); + } + } +} -- 2.7.4