test_inpainting.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. using namespace xphoto;
  7. static void test_inpainting(const Size inputSize, InpaintTypes mode, double expected_psnr, ImreadModes inputMode = IMREAD_COLOR)
  8. {
  9. string original_path = cvtest::findDataFile("cv/shared/lena.png");
  10. string mask_path = cvtest::findDataFile("cv/inpaint/mask.png");
  11. Mat original_ = imread(original_path, inputMode);
  12. ASSERT_FALSE(original_.empty()) << "Could not load input image " << original_path;
  13. Mat mask_ = imread(mask_path, IMREAD_GRAYSCALE);
  14. ASSERT_FALSE(mask_.empty()) << "Could not load error mask " << mask_path;
  15. Mat original, mask;
  16. resize(original_, original, inputSize, 0.0, 0.0, INTER_AREA);
  17. resize(mask_, mask, inputSize, 0.0, 0.0, INTER_NEAREST);
  18. Mat mask_valid = (mask == 0);
  19. Mat im_distorted(inputSize, original.type(), Scalar::all(0));
  20. original.copyTo(im_distorted, mask_valid);
  21. Mat reconstructed;
  22. xphoto::inpaint(im_distorted, mask_valid, reconstructed, mode);
  23. double adiff_psnr = cvtest::PSNR(original, reconstructed);
  24. EXPECT_LE(expected_psnr, adiff_psnr);
  25. #if 0
  26. imshow("original", original);
  27. imshow("im_distorted", im_distorted);
  28. imshow("reconstructed", reconstructed);
  29. std::cout << "adiff_psnr=" << adiff_psnr << std::endl;
  30. waitKey();
  31. #endif
  32. }
  33. TEST(xphoto_inpaint, smoke_FSR_FAST) // fast smoke test, input doesn't fit well for tested algorithm
  34. {
  35. test_inpainting(Size(128, 128), INPAINT_FSR_FAST, 30);
  36. }
  37. TEST(xphoto_inpaint, smoke_FSR_BEST) // fast smoke test, input doesn't fit well for tested algorithm
  38. {
  39. applyTestTag(CV_TEST_TAG_LONG);
  40. test_inpainting(Size(128, 128), INPAINT_FSR_BEST, 30);
  41. }
  42. TEST(xphoto_inpaint, smoke_grayscale_FSR_FAST) // fast smoke test, input doesn't fit well for tested algorithm
  43. {
  44. test_inpainting(Size(128, 128), INPAINT_FSR_FAST, 30, IMREAD_GRAYSCALE);
  45. }
  46. TEST(xphoto_inpaint, smoke_grayscale_FSR_BEST) // fast smoke test, input doesn't fit well for tested algorithm
  47. {
  48. test_inpainting(Size(128, 128), INPAINT_FSR_BEST, 30, IMREAD_GRAYSCALE);
  49. }
  50. TEST(xphoto_inpaint, regression_FSR_FAST)
  51. {
  52. test_inpainting(Size(512, 512), INPAINT_FSR_FAST, 39.5);
  53. }
  54. TEST(xphoto_inpaint, regression_FSR_BEST)
  55. {
  56. applyTestTag(CV_TEST_TAG_VERYLONG); // add --test_tag_enable=verylong to run this test
  57. test_inpainting(Size(512, 512), INPAINT_FSR_BEST, 39.6);
  58. }
  59. }} // namespace