Merge pull request #7688 from alalek:fix_orb_test

pull/7726/head
Vadim Pisarevsky 8 years ago
commit 511c0c2e71
  1. 21
      modules/features2d/perf/opencl/perf_orb.cpp
  2. 17
      modules/features2d/perf/perf_orb.cpp
  3. 78
      modules/features2d/test/test_rotation_and_scale_invariance.cpp

@ -27,8 +27,8 @@ OCL_PERF_TEST_P(ORBFixture, ORB_Detect, ORB_IMAGES)
OCL_TEST_CYCLE() detector->detect(frame, points, mask); OCL_TEST_CYCLE() detector->detect(frame, points, mask);
std::sort(points.begin(), points.end(), comparators::KeypointGreater()); EXPECT_GT(points.size(), 20u);
SANITY_CHECK_KEYPOINTS(points, 1e-5); SANITY_CHECK_NOTHING();
} }
OCL_PERF_TEST_P(ORBFixture, ORB_Extract, ORB_IMAGES) OCL_PERF_TEST_P(ORBFixture, ORB_Extract, ORB_IMAGES)
@ -47,13 +47,14 @@ OCL_PERF_TEST_P(ORBFixture, ORB_Extract, ORB_IMAGES)
Ptr<ORB> detector = ORB::create(1500, 1.3f, 1); Ptr<ORB> detector = ORB::create(1500, 1.3f, 1);
vector<KeyPoint> points; vector<KeyPoint> points;
detector->detect(frame, points, mask); detector->detect(frame, points, mask);
std::sort(points.begin(), points.end(), comparators::KeypointGreater()); EXPECT_GT(points.size(), 20u);
UMat descriptors; UMat descriptors;
OCL_TEST_CYCLE() detector->compute(frame, points, descriptors); OCL_TEST_CYCLE() detector->compute(frame, points, descriptors);
SANITY_CHECK(descriptors); EXPECT_EQ((size_t)descriptors.rows, points.size());
SANITY_CHECK_NOTHING();
} }
OCL_PERF_TEST_P(ORBFixture, ORB_Full, ORB_IMAGES) OCL_PERF_TEST_P(ORBFixture, ORB_Full, ORB_IMAGES)
@ -61,12 +62,6 @@ OCL_PERF_TEST_P(ORBFixture, ORB_Full, ORB_IMAGES)
string filename = getDataPath(GetParam()); string filename = getDataPath(GetParam());
Mat mframe = imread(filename, IMREAD_GRAYSCALE); Mat mframe = imread(filename, IMREAD_GRAYSCALE);
double desc_eps = 1e-6;
#ifdef ANDROID
if (cv::ocl::Device::getDefault().isNVidia())
desc_eps = 2;
#endif
if (mframe.empty()) if (mframe.empty())
FAIL() << "Unable to load source image " << filename; FAIL() << "Unable to load source image " << filename;
@ -81,9 +76,9 @@ OCL_PERF_TEST_P(ORBFixture, ORB_Full, ORB_IMAGES)
OCL_TEST_CYCLE() detector->detectAndCompute(frame, mask, points, descriptors, false); OCL_TEST_CYCLE() detector->detectAndCompute(frame, mask, points, descriptors, false);
::perf::sort(points, descriptors); EXPECT_GT(points.size(), 20u);
SANITY_CHECK_KEYPOINTS(points, 1e-5); EXPECT_EQ((size_t)descriptors.rows, points.size());
SANITY_CHECK(descriptors, desc_eps); SANITY_CHECK_NOTHING();
} }
} // ocl } // ocl

@ -27,8 +27,9 @@ PERF_TEST_P(orb, detect, testing::Values(ORB_IMAGES))
TEST_CYCLE() detector->detect(frame, points, mask); TEST_CYCLE() detector->detect(frame, points, mask);
sort(points.begin(), points.end(), comparators::KeypointGreater()); EXPECT_GT(points.size(), 20u);
SANITY_CHECK_KEYPOINTS(points, 1e-5);
SANITY_CHECK_NOTHING();
} }
PERF_TEST_P(orb, extract, testing::Values(ORB_IMAGES)) PERF_TEST_P(orb, extract, testing::Values(ORB_IMAGES))
@ -45,13 +46,15 @@ PERF_TEST_P(orb, extract, testing::Values(ORB_IMAGES))
Ptr<ORB> detector = ORB::create(1500, 1.3f, 1); Ptr<ORB> detector = ORB::create(1500, 1.3f, 1);
vector<KeyPoint> points; vector<KeyPoint> points;
detector->detect(frame, points, mask); detector->detect(frame, points, mask);
sort(points.begin(), points.end(), comparators::KeypointGreater());
EXPECT_GT(points.size(), 20u);
Mat descriptors; Mat descriptors;
TEST_CYCLE() detector->compute(frame, points, descriptors); TEST_CYCLE() detector->compute(frame, points, descriptors);
SANITY_CHECK(descriptors); EXPECT_EQ((size_t)descriptors.rows, points.size());
SANITY_CHECK_NOTHING();
} }
PERF_TEST_P(orb, full, testing::Values(ORB_IMAGES)) PERF_TEST_P(orb, full, testing::Values(ORB_IMAGES))
@ -71,7 +74,7 @@ PERF_TEST_P(orb, full, testing::Values(ORB_IMAGES))
TEST_CYCLE() detector->detectAndCompute(frame, mask, points, descriptors, false); TEST_CYCLE() detector->detectAndCompute(frame, mask, points, descriptors, false);
perf::sort(points, descriptors); EXPECT_GT(points.size(), 20u);
SANITY_CHECK_KEYPOINTS(points, 1e-5); EXPECT_EQ((size_t)descriptors.rows, points.size());
SANITY_CHECK(descriptors); SANITY_CHECK_NOTHING();
} }

@ -47,7 +47,7 @@ using namespace cv;
const string IMAGE_TSUKUBA = "/features2d/tsukuba.png"; const string IMAGE_TSUKUBA = "/features2d/tsukuba.png";
const string IMAGE_BIKES = "/detectors_descriptors_evaluation/images_datasets/bikes/img1.png"; const string IMAGE_BIKES = "/detectors_descriptors_evaluation/images_datasets/bikes/img1.png";
#define SHOW_DEBUG_LOG 0 #define SHOW_DEBUG_LOG 1
static static
Mat generateHomography(float angle) Mat generateHomography(float angle)
@ -63,7 +63,7 @@ Mat generateHomography(float angle)
} }
static static
Mat rotateImage(const Mat& srcImage, float angle, Mat& dstImage, Mat& dstMask) Mat rotateImage(const Mat& srcImage, const Mat& srcMask, float angle, Mat& dstImage, Mat& dstMask)
{ {
// angle - rotation around Oz in degrees // angle - rotation around Oz in degrees
float diag = std::sqrt(static_cast<float>(srcImage.cols * srcImage.cols + srcImage.rows * srcImage.rows)); float diag = std::sqrt(static_cast<float>(srcImage.cols * srcImage.cols + srcImage.rows * srcImage.rows));
@ -75,8 +75,6 @@ Mat rotateImage(const Mat& srcImage, float angle, Mat& dstImage, Mat& dstMask)
RDShift.at<float>(1,2) = diag/2; RDShift.at<float>(1,2) = diag/2;
Size sz(cvRound(diag), cvRound(diag)); Size sz(cvRound(diag), cvRound(diag));
Mat srcMask(srcImage.size(), CV_8UC1, Scalar(255));
Mat H = RDShift * generateHomography(angle) * LUShift; Mat H = RDShift * generateHomography(angle) * LUShift;
warpPerspective(srcImage, dstImage, H, sz); warpPerspective(srcImage, dstImage, H, sz);
warpPerspective(srcMask, dstMask, H, sz); warpPerspective(srcMask, dstMask, H, sz);
@ -212,16 +210,22 @@ protected:
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
return; return;
} }
std::cout << "Image: " << image0.size() << std::endl;
const int borderSize = 16;
Mat mask0(image0.size(), CV_8UC1, Scalar(0));
mask0(Rect(borderSize, borderSize, mask0.cols - 2*borderSize, mask0.rows - 2*borderSize)).setTo(Scalar(255));
vector<KeyPoint> keypoints0; vector<KeyPoint> keypoints0;
featureDetector->detect(image0, keypoints0); featureDetector->detect(image0, keypoints0, mask0);
std::cout << "Intial keypoints: " << keypoints0.size() << std::endl;
if(keypoints0.size() < 15) if(keypoints0.size() < 15)
CV_Error(Error::StsAssert, "Detector gives too few points in a test image\n"); CV_Error(Error::StsAssert, "Detector gives too few points in a test image\n");
const int maxAngle = 360, angleStep = 15; const int maxAngle = 360, angleStep = 15;
for(int angle = 0; angle < maxAngle; angle += angleStep) for(int angle = 0; angle < maxAngle; angle += angleStep)
{ {
Mat H = rotateImage(image0, static_cast<float>(angle), image1, mask1); Mat H = rotateImage(image0, mask0, static_cast<float>(angle), image1, mask1);
vector<KeyPoint> keypoints1; vector<KeyPoint> keypoints1;
featureDetector->detect(image1, keypoints1, mask1); featureDetector->detect(image1, keypoints1, mask1);
@ -264,10 +268,9 @@ protected:
float keyPointMatchesRatio = static_cast<float>(keyPointMatchesCount) / keypoints0.size(); float keyPointMatchesRatio = static_cast<float>(keyPointMatchesCount) / keypoints0.size();
if(keyPointMatchesRatio < minKeyPointMatchesRatio) if(keyPointMatchesRatio < minKeyPointMatchesRatio)
{ {
ts->printf(cvtest::TS::LOG, "Incorrect keyPointMatchesRatio: curr = %f, min = %f.\n", ts->printf(cvtest::TS::LOG, "Angle: %f: Incorrect keyPointMatchesRatio: curr = %f, min = %f (matched=%d total=%d - %d).\n",
keyPointMatchesRatio, minKeyPointMatchesRatio); (float)angle, keyPointMatchesRatio, minKeyPointMatchesRatio, (int)keyPointMatchesCount, (int)keypoints0.size(), (int)keypoints1.size());
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY); ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
return;
} }
if(keyPointMatchesCount) if(keyPointMatchesCount)
@ -275,15 +278,18 @@ protected:
float angleInliersRatio = static_cast<float>(angleInliersCount) / keyPointMatchesCount; float angleInliersRatio = static_cast<float>(angleInliersCount) / keyPointMatchesCount;
if(angleInliersRatio < minAngleInliersRatio) if(angleInliersRatio < minAngleInliersRatio)
{ {
ts->printf(cvtest::TS::LOG, "Incorrect angleInliersRatio: curr = %f, min = %f.\n", ts->printf(cvtest::TS::LOG, "Angle: %f: Incorrect angleInliersRatio: curr = %f, min = %f.\n",
angleInliersRatio, minAngleInliersRatio); (float)angle, angleInliersRatio, minAngleInliersRatio);
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY); ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
return;
} }
} }
#if SHOW_DEBUG_LOG #if SHOW_DEBUG_LOG
std::cout << "keyPointMatchesRatio - " << keyPointMatchesRatio std::cout
<< " - angleInliersRatio " << static_cast<float>(angleInliersCount) / keyPointMatchesCount << std::endl; << "angle = " << angle
<< ", keypoints = " << keypoints1.size()
<< ", keyPointMatchesRatio = " << keyPointMatchesRatio
<< ", angleInliersRatio = " << (keyPointMatchesCount ? (static_cast<float>(angleInliersCount) / keyPointMatchesCount) : 0)
<< std::endl;
#endif #endif
} }
ts->set_failed_test_info( cvtest::TS::OK ); ts->set_failed_test_info( cvtest::TS::OK );
@ -324,10 +330,16 @@ protected:
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
return; return;
} }
std::cout << "Image: " << image0.size() << std::endl;
const int borderSize = 16;
Mat mask0(image0.size(), CV_8UC1, Scalar(0));
mask0(Rect(borderSize, borderSize, mask0.cols - 2*borderSize, mask0.rows - 2*borderSize)).setTo(Scalar(255));
vector<KeyPoint> keypoints0; vector<KeyPoint> keypoints0;
Mat descriptors0; Mat descriptors0;
featureDetector->detect(image0, keypoints0); featureDetector->detect(image0, keypoints0, mask0);
std::cout << "Intial keypoints: " << keypoints0.size() << std::endl;
if(keypoints0.size() < 15) if(keypoints0.size() < 15)
CV_Error(Error::StsAssert, "Detector gives too few points in a test image\n"); CV_Error(Error::StsAssert, "Detector gives too few points in a test image\n");
descriptorExtractor->compute(image0, keypoints0, descriptors0); descriptorExtractor->compute(image0, keypoints0, descriptors0);
@ -338,7 +350,7 @@ protected:
const int maxAngle = 360, angleStep = 15; const int maxAngle = 360, angleStep = 15;
for(int angle = 0; angle < maxAngle; angle += angleStep) for(int angle = 0; angle < maxAngle; angle += angleStep)
{ {
Mat H = rotateImage(image0, static_cast<float>(angle), image1, mask1); Mat H = rotateImage(image0, mask0, static_cast<float>(angle), image1, mask1);
vector<KeyPoint> keypoints1; vector<KeyPoint> keypoints1;
rotateKeyPoints(keypoints0, H, static_cast<float>(angle), keypoints1); rotateKeyPoints(keypoints0, H, static_cast<float>(angle), keypoints1);
@ -369,7 +381,11 @@ protected:
return; return;
} }
#if SHOW_DEBUG_LOG #if SHOW_DEBUG_LOG
std::cout << "descInliersRatio " << static_cast<float>(descInliersCount) / keypoints0.size() << std::endl; std::cout
<< "angle = " << angle
<< ", keypoints = " << keypoints1.size()
<< ", descInliersRatio = " << static_cast<float>(descInliersCount) / keypoints0.size()
<< std::endl;
#endif #endif
} }
ts->set_failed_test_info( cvtest::TS::OK ); ts->set_failed_test_info( cvtest::TS::OK );
@ -485,8 +501,11 @@ protected:
} }
} }
#if SHOW_DEBUG_LOG #if SHOW_DEBUG_LOG
std::cout << "keyPointMatchesRatio - " << keyPointMatchesRatio std::cout
<< " - scaleInliersRatio " << static_cast<float>(scaleInliersCount) / keyPointMatchesCount << std::endl; << "scale = " << scale
<< ", keyPointMatchesRatio = " << keyPointMatchesRatio
<< ", scaleInliersRatio = " << (keyPointMatchesCount ? static_cast<float>(scaleInliersCount) / keyPointMatchesCount : 0)
<< std::endl;
#endif #endif
} }
ts->set_failed_test_info( cvtest::TS::OK ); ts->set_failed_test_info( cvtest::TS::OK );
@ -573,7 +592,10 @@ protected:
return; return;
} }
#if SHOW_DEBUG_LOG #if SHOW_DEBUG_LOG
std::cout << "descInliersRatio " << static_cast<float>(descInliersCount) / keypoints0.size() << std::endl; std::cout
<< "scale = " << scale
<< ", descInliersRatio = " << static_cast<float>(descInliersCount) / keypoints0.size()
<< std::endl;
#endif #endif
} }
ts->set_failed_test_info( cvtest::TS::OK ); ts->set_failed_test_info( cvtest::TS::OK );
@ -595,7 +617,7 @@ protected:
TEST(Features2d_RotationInvariance_Detector_BRISK, regression) TEST(Features2d_RotationInvariance_Detector_BRISK, regression)
{ {
DetectorRotationInvarianceTest test(BRISK::create(), DetectorRotationInvarianceTest test(BRISK::create(),
0.32f, 0.45f,
0.76f); 0.76f);
test.safe_run(); test.safe_run();
} }
@ -603,7 +625,7 @@ TEST(Features2d_RotationInvariance_Detector_BRISK, regression)
TEST(Features2d_RotationInvariance_Detector_ORB, regression) TEST(Features2d_RotationInvariance_Detector_ORB, regression)
{ {
DetectorRotationInvarianceTest test(ORB::create(), DetectorRotationInvarianceTest test(ORB::create(),
0.47f, 0.5f,
0.76f); 0.76f);
test.safe_run(); test.safe_run();
} }
@ -657,13 +679,11 @@ TEST(Features2d_ScaleInvariance_Detector_AKAZE, regression)
test.safe_run(); test.safe_run();
} }
//TEST(Features2d_ScaleInvariance_Detector_ORB, regression) TEST(Features2d_ScaleInvariance_Detector_ORB, regression)
//{ {
// DetectorScaleInvarianceTest test(Algorithm::create<FeatureDetector>("Feature2D.ORB"), DetectorScaleInvarianceTest test(ORB::create(), 0.08f, 0.49f);
// 0.22f, test.safe_run();
// 0.83f); }
// test.safe_run();
//}
/* /*
* Descriptor's scale invariance check * Descriptor's scale invariance check

Loading…
Cancel
Save