test_feature2d.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html
  4. #include "../test_precomp.hpp"
  5. #include "cvconfig.h"
  6. #include "opencv2/ts/ocl_test.hpp"
  7. #include <functional>
  8. #ifdef HAVE_OPENCL
  9. namespace opencv_test {
  10. namespace ocl {
  11. #define TEST_IMAGES testing::Values(\
  12. "detectors_descriptors_evaluation/images_datasets/leuven/img1.png",\
  13. "../stitching/a3.png", \
  14. "../stitching/s2.jpg")
  15. PARAM_TEST_CASE(Feature2DFixture, std::function<Ptr<Feature2D>()>, std::string)
  16. {
  17. std::string filename;
  18. Mat image, descriptors;
  19. vector<KeyPoint> keypoints;
  20. UMat uimage, udescriptors;
  21. vector<KeyPoint> ukeypoints;
  22. Ptr<Feature2D> feature;
  23. virtual void SetUp()
  24. {
  25. feature = GET_PARAM(0)();
  26. filename = GET_PARAM(1);
  27. image = readImage(filename);
  28. ASSERT_FALSE(image.empty());
  29. image.copyTo(uimage);
  30. OCL_OFF(feature->detect(image, keypoints));
  31. OCL_ON(feature->detect(uimage, ukeypoints));
  32. // note: we use keypoints from CPU for GPU too, to test descriptors separately
  33. OCL_OFF(feature->compute(image, keypoints, descriptors));
  34. OCL_ON(feature->compute(uimage, keypoints, udescriptors));
  35. }
  36. };
  37. OCL_TEST_P(Feature2DFixture, KeypointsSame)
  38. {
  39. EXPECT_EQ(keypoints.size(), ukeypoints.size());
  40. for (size_t i = 0; i < keypoints.size(); ++i)
  41. {
  42. EXPECT_GE(KeyPoint::overlap(keypoints[i], ukeypoints[i]), 0.95);
  43. EXPECT_NEAR(keypoints[i].angle, ukeypoints[i].angle, 0.05);
  44. }
  45. }
  46. OCL_TEST_P(Feature2DFixture, DescriptorsSame)
  47. {
  48. EXPECT_MAT_NEAR(descriptors, udescriptors, 0.001);
  49. }
  50. OCL_INSTANTIATE_TEST_CASE_P(AKAZE, Feature2DFixture,
  51. testing::Combine(testing::Values([]() { return AKAZE::create(); }), TEST_IMAGES));
  52. OCL_INSTANTIATE_TEST_CASE_P(AKAZE_DESCRIPTOR_KAZE, Feature2DFixture,
  53. testing::Combine(testing::Values([]() { return AKAZE::create(AKAZE::DESCRIPTOR_KAZE); }), TEST_IMAGES));
  54. }//ocl
  55. }//cvtest
  56. #endif //HAVE_OPENCL