test_drawing.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. //
  5. // Copyright (C) 2018, Intel Corporation, all rights reserved.
  6. // Third party copyrights are property of their respective owners.
  7. #include "test_precomp.hpp"
  8. namespace opencv_test { namespace {
  9. static
  10. Mat getReference_DrawKeypoint(int cn)
  11. {
  12. static Mat ref = (Mat_<uint8_t>(11, 11) <<
  13. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  14. 1, 1, 1, 1, 15, 54, 15, 1, 1, 1, 1,
  15. 1, 1, 1, 76, 217, 217, 221, 81, 1, 1, 1,
  16. 1, 1, 100, 224, 111, 57, 115, 225, 101, 1, 1,
  17. 1, 44, 215, 100, 1, 1, 1, 101, 214, 44, 1,
  18. 1, 54, 212, 57, 1, 1, 1, 55, 212, 55, 1,
  19. 1, 40, 215, 104, 1, 1, 1, 105, 215, 40, 1,
  20. 1, 1, 102, 221, 111, 55, 115, 222, 103, 1, 1,
  21. 1, 1, 1, 76, 218, 217, 220, 81, 1, 1, 1,
  22. 1, 1, 1, 1, 15, 55, 15, 1, 1, 1, 1,
  23. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
  24. Mat res;
  25. cvtColor(ref, res, (cn == 4) ? COLOR_GRAY2BGRA : COLOR_GRAY2BGR);
  26. return res;
  27. }
  28. typedef testing::TestWithParam<MatType> Features2D_drawKeypoints;
  29. TEST_P(Features2D_drawKeypoints, Accuracy)
  30. {
  31. const int cn = CV_MAT_CN(GetParam());
  32. Mat inpImg(11, 11, GetParam(), Scalar(1, 1, 1, 255)), outImg;
  33. std::vector<KeyPoint> keypoints(1, KeyPoint(5, 5, 1));
  34. drawKeypoints(inpImg, keypoints, outImg, Scalar::all(255));
  35. ASSERT_EQ(outImg.channels(), (cn == 4) ? 4 : 3);
  36. Mat ref_ = getReference_DrawKeypoint(cn);
  37. EXPECT_EQ(0, cv::norm(outImg, ref_, NORM_INF));
  38. }
  39. INSTANTIATE_TEST_CASE_P(/**/, Features2D_drawKeypoints, Values(CV_8UC1, CV_8UC3, CV_8UC4));
  40. typedef testing::TestWithParam<tuple<MatType, MatType> > Features2D_drawMatches;
  41. TEST_P(Features2D_drawMatches, Accuracy)
  42. {
  43. Mat inpImg1(11, 11, get<0>(GetParam()), Scalar(1, 1, 1, 255));
  44. Mat inpImg2(11, 11, get<1>(GetParam()), Scalar(2, 2, 2, 255)), outImg2, outImg;
  45. std::vector<KeyPoint> keypoints(1, KeyPoint(5, 5, 1));
  46. // Get outImg2 using drawKeypoints assuming that it works correctly (see the test above).
  47. drawKeypoints(inpImg2, keypoints, outImg2, Scalar::all(255));
  48. ASSERT_EQ(outImg2.channels(), (inpImg2.channels() == 4) ? 4 : 3);
  49. // Merge both references.
  50. const int cn = max(3, max(inpImg1.channels(), inpImg2.channels()));
  51. if (cn == 4 && outImg2.channels() == 3)
  52. cvtColor(outImg2, outImg2, COLOR_BGR2BGRA);
  53. Mat ref_ = getReference_DrawKeypoint(cn);
  54. Mat concattedRef;
  55. hconcat(ref_, outImg2, concattedRef);
  56. std::vector<DMatch> matches;
  57. drawMatches(inpImg1, keypoints, inpImg2, keypoints, matches, outImg,
  58. Scalar::all(255), Scalar::all(255));
  59. ASSERT_EQ(outImg.channels(), cn);
  60. EXPECT_EQ(0, cv::norm(outImg, concattedRef, NORM_INF));
  61. }
  62. INSTANTIATE_TEST_CASE_P(/**/, Features2D_drawMatches, Combine(
  63. Values(CV_8UC1, CV_8UC3, CV_8UC4),
  64. Values(CV_8UC1, CV_8UC3, CV_8UC4)
  65. ));
  66. }} // namespace