test_mcc.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 <vector>
  6. namespace opencv_test
  7. {
  8. namespace
  9. {
  10. using namespace std;
  11. /****************************************************************************************\
  12. * Test drawing works properly
  13. \****************************************************************************************/
  14. void runCCheckerDraw(Ptr<CChecker> pChecker, int rows, int cols, unsigned int number_of_cells_in_colorchecker)
  15. {
  16. cv::Mat img(rows, cols, CV_8UC3, {0, 0, 0});
  17. Ptr<CCheckerDraw> cdraw = CCheckerDraw::create(pChecker);
  18. cdraw->draw(img);
  19. //make sure this contains extacly as many rectangles as in the pChecker
  20. vector<vector<Point>> contours;
  21. cv::cvtColor(img, img, COLOR_BGR2GRAY);
  22. findContours(img, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);
  23. ASSERT_EQ(contours.size(), number_of_cells_in_colorchecker);
  24. }
  25. TEST(CV_mccRunCCheckerDrawTest, accuracy_MCC24)
  26. {
  27. Ptr<CChecker> pChecker = CChecker::create();
  28. pChecker->setTarget(MCC24);
  29. pChecker->setBox({{0, 0}, {480, 0}, {480, 640}, {0, 640}});
  30. runCCheckerDraw(pChecker, 640, 480, 24);
  31. }
  32. TEST(CV_mccRunCCheckerDrawTest, accuracy_SG140)
  33. {
  34. Ptr<CChecker> pChecker = CChecker::create();
  35. pChecker->setTarget(SG140);
  36. pChecker->setBox({{0, 0}, {480, 0}, {480, 640}, {0, 640}});
  37. runCCheckerDraw(pChecker, 640, 480, 140);
  38. }
  39. TEST(CV_mccRunCCheckerDrawTest, accuracy_VINYL18)
  40. {
  41. Ptr<CChecker> pChecker = CChecker::create();
  42. pChecker->setTarget(VINYL18);
  43. pChecker->setBox({{0, 0}, {480, 0}, {480, 640}, {0, 640}});
  44. runCCheckerDraw(pChecker, 640, 480, 18);
  45. }
  46. /****************************************************************************************\
  47. * Test detection works properly on the simplest images
  48. \****************************************************************************************/
  49. void runCCheckerDetectorBasic(std::string image_name, TYPECHART chartType)
  50. {
  51. Ptr<CCheckerDetector> detector = CCheckerDetector::create();
  52. std::string path = cvtest::findDataFile("mcc/" + image_name);
  53. cv::Mat img = imread(path);
  54. ASSERT_FALSE(img.empty()) << "Test image can't be loaded: " << path;
  55. ASSERT_TRUE(detector->process(img, chartType));
  56. }
  57. TEST(CV_mccRunCCheckerDetectorBasic, accuracy_SG140)
  58. {
  59. runCCheckerDetectorBasic("SG140.png", SG140);
  60. }
  61. TEST(CV_mccRunCCheckerDetectorBasic, accuracy_MCC24)
  62. {
  63. runCCheckerDetectorBasic("MCC24.png", MCC24);
  64. }
  65. TEST(CV_mccRunCCheckerDetectorBasic, accuracy_VINYL18)
  66. {
  67. runCCheckerDetectorBasic("VINYL18.png", VINYL18);
  68. }
  69. } // namespace
  70. } // namespace opencv_test