test_feature2d.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #ifdef HAVE_OPENCL
  8. namespace opencv_test {
  9. namespace ocl {
  10. #define TEST_IMAGES testing::Values(\
  11. "detectors_descriptors_evaluation/images_datasets/leuven/img1.png",\
  12. "../stitching/a3.png", \
  13. "../stitching/s2.jpg")
  14. PARAM_TEST_CASE(Feature2DFixture, Ptr<Feature2D>, std::string)
  15. {
  16. std::string filename;
  17. Mat image, descriptors;
  18. vector<KeyPoint> keypoints;
  19. UMat uimage, udescriptors;
  20. vector<KeyPoint> ukeypoints;
  21. Ptr<Feature2D> feature;
  22. virtual void SetUp()
  23. {
  24. feature = GET_PARAM(0);
  25. filename = GET_PARAM(1);
  26. image = readImage(filename);
  27. ASSERT_FALSE(image.empty());
  28. image.copyTo(uimage);
  29. OCL_OFF(feature->detect(image, keypoints));
  30. OCL_ON(feature->detect(uimage, ukeypoints));
  31. // note: we use keypoints from CPU for GPU too, to test descriptors separately
  32. OCL_OFF(feature->compute(image, keypoints, descriptors));
  33. OCL_ON(feature->compute(uimage, keypoints, udescriptors));
  34. }
  35. };
  36. OCL_TEST_P(Feature2DFixture, KeypointsSame)
  37. {
  38. EXPECT_EQ(keypoints.size(), ukeypoints.size());
  39. for (size_t i = 0; i < keypoints.size(); ++i)
  40. {
  41. EXPECT_GE(KeyPoint::overlap(keypoints[i], ukeypoints[i]), 0.95);
  42. EXPECT_NEAR(keypoints[i].angle, ukeypoints[i].angle, 0.05);
  43. }
  44. }
  45. OCL_TEST_P(Feature2DFixture, DescriptorsSame)
  46. {
  47. EXPECT_MAT_NEAR(descriptors, udescriptors, 0.001);
  48. }
  49. OCL_INSTANTIATE_TEST_CASE_P(AKAZE, Feature2DFixture,
  50. testing::Combine(testing::Values(AKAZE::create()), TEST_IMAGES));
  51. OCL_INSTANTIATE_TEST_CASE_P(AKAZE_DESCRIPTOR_KAZE, Feature2DFixture,
  52. testing::Combine(testing::Values(AKAZE::create(AKAZE::DESCRIPTOR_KAZE)), TEST_IMAGES));
  53. }//ocl
  54. }//cvtest
  55. #endif //HAVE_OPENCL