test_psnr.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. #define TEST_CASE_NAME CV_Quality_PSNR
  6. namespace opencv_test
  7. {
  8. namespace quality_test
  9. {
  10. const cv::Scalar
  11. PSNR_EXPECTED_1 = { 14.8347, INFINITY, INFINITY, INFINITY } // matlab: psnr('rock_1.bmp', 'rock_2.bmp') == 14.8347
  12. , PSNR_EXPECTED_2 = { 28.4542, 27.7402, 27.2886, INFINITY } // matlab: psnr('rubberwhale1.png', 'rubberwhale2.png') == BGR: 28.4542, 27.7402, 27.2886, avg 27.8015
  13. ;
  14. // static method
  15. TEST(TEST_CASE_NAME, static_)
  16. {
  17. cv::Mat qMat = {};
  18. quality_expect_near(quality::QualityPSNR::compute(get_testfile_1a(), get_testfile_1a(), qMat), cv::Scalar(INFINITY, INFINITY, INFINITY, INFINITY)); // ref vs ref == inf
  19. check_quality_map(qMat);
  20. }
  21. // single channel, with/without opencl
  22. TEST(TEST_CASE_NAME, single_channel)
  23. {
  24. auto fn = []() { quality_test(quality::QualityPSNR::create(get_testfile_1a()), get_testfile_1b(), PSNR_EXPECTED_1); };
  25. OCL_OFF( fn() );
  26. OCL_ON( fn() );
  27. }
  28. // multi-channel
  29. TEST(TEST_CASE_NAME, multi_channel)
  30. {
  31. quality_test(quality::QualityPSNR::create(get_testfile_2a()), get_testfile_2b(), PSNR_EXPECTED_2);
  32. }
  33. // internal a/b test
  34. /*
  35. TEST(TEST_CASE_NAME, performance)
  36. {
  37. auto ref = get_testfile_1a();
  38. auto cmp = get_testfile_1b();
  39. quality_performance_test("PSNR", [&]() { cv::quality::QualityPSNR::compute(ref, cmp, cv::noArray()); });
  40. }
  41. */
  42. }
  43. } // namespace