test_thinning.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. namespace opencv_test { namespace {
  6. static int createTestImage(Mat& src)
  7. {
  8. src = Mat::zeros(Size(256, 256), CV_8UC1);
  9. for (int x = 50; x < src.cols - 50; x += 50)
  10. {
  11. cv::circle(src, Point(x, x/2), 30 + x/2, Scalar(255), 5);
  12. }
  13. int src_pixels = countNonZero(src);
  14. EXPECT_GT(src_pixels, 0);
  15. return src_pixels;
  16. }
  17. TEST(ximgproc_Thinning, simple_ZHANGSUEN)
  18. {
  19. Mat src;
  20. int src_pixels = createTestImage(src);
  21. Mat dst;
  22. thinning(src, dst, THINNING_ZHANGSUEN);
  23. int dst_pixels = countNonZero(dst);
  24. EXPECT_LE(dst_pixels, src_pixels);
  25. #if 0
  26. imshow("src", src); imshow("dst", dst); waitKey();
  27. #endif
  28. }
  29. TEST(ximgproc_Thinning, simple_GUOHALL)
  30. {
  31. Mat src;
  32. int src_pixels = createTestImage(src);
  33. Mat dst;
  34. thinning(src, dst, THINNING_GUOHALL);
  35. int dst_pixels = countNonZero(dst);
  36. EXPECT_LE(dst_pixels, src_pixels);
  37. #if 0
  38. imshow("src", src); imshow("dst", dst); waitKey();
  39. #endif
  40. }
  41. }} // namespace