test_brisque.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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_BRISQUE
  6. namespace opencv_test
  7. {
  8. namespace quality_test
  9. {
  10. // brisque per channel
  11. const cv::Scalar
  12. BRISQUE_EXPECTED_1 = { 31.866388320922852 } // testfile_1a
  13. , BRISQUE_EXPECTED_2 = { 9.7544803619384766 } // testfile 2a
  14. ;
  15. // default model and range file names
  16. // opencv tests must be installed (cmake var: INSTALL_TESTS), or BRISQUE tests will be skipped
  17. static const char* MODEL_FNAME = "brisque_model_live.yml";
  18. static const char* RANGE_FNAME = "brisque_range_live.yml";
  19. // instantiates a brisque object for testing
  20. inline cv::Ptr<quality::QualityBRISQUE> create_brisque()
  21. {
  22. const auto model = cvtest::findDataFile(MODEL_FNAME, false);
  23. const auto range = cvtest::findDataFile(RANGE_FNAME, false);
  24. return quality::QualityBRISQUE::create(model, range);
  25. }
  26. // static method
  27. TEST(TEST_CASE_NAME, static_ )
  28. {
  29. quality_expect_near(
  30. quality::QualityBRISQUE::compute(
  31. get_testfile_1a()
  32. , cvtest::findDataFile(MODEL_FNAME, false)
  33. , cvtest::findDataFile(RANGE_FNAME, false)
  34. )
  35. , BRISQUE_EXPECTED_1
  36. );
  37. }
  38. // single channel, instance method, with and without opencl
  39. TEST(TEST_CASE_NAME, single_channel )
  40. {
  41. auto fn = []() { quality_test(create_brisque(), get_testfile_1a(), BRISQUE_EXPECTED_1, false, true ); };
  42. OCL_OFF( fn() );
  43. OCL_ON( fn() );
  44. }
  45. // multi-channel
  46. TEST(TEST_CASE_NAME, multi_channel)
  47. {
  48. quality_test(create_brisque(), get_testfile_2a(), BRISQUE_EXPECTED_2, false, true);
  49. }
  50. // check brisque model/range persistence
  51. TEST(TEST_CASE_NAME, model_persistence )
  52. {
  53. auto ptr = create_brisque();
  54. auto fn = [&ptr]() { quality_test(ptr, get_testfile_1a(), BRISQUE_EXPECTED_1, false, true); };
  55. fn();
  56. fn(); // model/range should persist with brisque ptr through multiple invocations
  57. }
  58. // check compute features interface method
  59. TEST(TEST_CASE_NAME, compute_features)
  60. {
  61. auto ptr = create_brisque();
  62. cv::Mat features;
  63. ptr->computeFeatures(get_testfile_1a(), features);
  64. EXPECT_EQ(features.rows, 1);
  65. EXPECT_EQ(features.cols, 36);
  66. }
  67. /*
  68. // internal a/b test
  69. TEST(TEST_CASE_NAME, performance)
  70. {
  71. auto ref = get_testfile_1a();
  72. auto alg = create_brisque();
  73. quality_performance_test("BRISQUE", [&]() { alg->compute(ref); });
  74. }
  75. */
  76. }
  77. } // namespace