test_common.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 "test_common.hpp"
  6. namespace opencv_test {
  7. static
  8. Mat generateTestImageBGR_()
  9. {
  10. Size sz(640, 480);
  11. Mat result(sz, CV_8UC3, Scalar::all(0));
  12. const string fname = cvtest::findDataFile("../cv/shared/baboon.png");
  13. Mat image = imread(fname, IMREAD_COLOR);
  14. CV_Assert(!image.empty());
  15. CV_CheckEQ(image.size(), Size(512, 512), "");
  16. Rect roi((640-512) / 2, 0, 512, 480);
  17. image(Rect(0, 0, 512, 480)).copyTo(result(roi));
  18. result(Rect(0, 0, 5, 5)).setTo(Scalar(0, 0, 255)); // R
  19. result(Rect(5, 0, 5, 5)).setTo(Scalar(0, 255, 0)); // G
  20. result(Rect(10, 0, 5, 5)).setTo(Scalar(255, 0, 0)); // B
  21. result(Rect(0, 5, 5, 5)).setTo(Scalar(128, 128, 128)); // gray
  22. //imshow("test_image", result); waitKey();
  23. return result;
  24. }
  25. Mat generateTestImageBGR()
  26. {
  27. static Mat image = generateTestImageBGR_(); // initialize once
  28. CV_Assert(!image.empty());
  29. return image;
  30. }
  31. static
  32. Mat generateTestImageGrayscale_()
  33. {
  34. Mat imageBGR = generateTestImageBGR();
  35. CV_Assert(!imageBGR.empty());
  36. Mat result;
  37. cvtColor(imageBGR, result, COLOR_BGR2GRAY);
  38. return result;
  39. }
  40. Mat generateTestImageGrayscale()
  41. {
  42. static Mat image = generateTestImageGrayscale_(); // initialize once
  43. return image;
  44. }
  45. } // namespace