vendor: OpenCV 5.0.0 snapshot at 755e50675d97db9b7d449d8bd6b09888646f6c6e

This commit is contained in:
Gitea Mirror Bot
2026-08-22 00:11:13 +08:00
commit 12022378a3
3872 changed files with 2513409 additions and 0 deletions
+91
View File
@@ -0,0 +1,91 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "test_precomp.hpp"
#define TEST_CASE_NAME CV_Quality_BRISQUE
namespace opencv_test
{
namespace quality_test
{
// brisque per channel
const cv::Scalar
BRISQUE_EXPECTED_1 = { 31.866388320922852 } // testfile_1a
, BRISQUE_EXPECTED_2 = { 9.7544803619384766 } // testfile 2a
;
// default model and range file names
// opencv tests must be installed (cmake var: INSTALL_TESTS), or BRISQUE tests will be skipped
static const char* MODEL_FNAME = "brisque_model_live.yml";
static const char* RANGE_FNAME = "brisque_range_live.yml";
// instantiates a brisque object for testing
inline cv::Ptr<quality::QualityBRISQUE> create_brisque()
{
const auto model = cvtest::findDataFile(MODEL_FNAME, false);
const auto range = cvtest::findDataFile(RANGE_FNAME, false);
return quality::QualityBRISQUE::create(model, range);
}
// static method
TEST(TEST_CASE_NAME, static_ )
{
quality_expect_near(
quality::QualityBRISQUE::compute(
get_testfile_1a()
, cvtest::findDataFile(MODEL_FNAME, false)
, cvtest::findDataFile(RANGE_FNAME, false)
)
, BRISQUE_EXPECTED_1
);
}
// single channel, instance method, with and without opencl
TEST(TEST_CASE_NAME, single_channel )
{
auto fn = []() { quality_test(create_brisque(), get_testfile_1a(), BRISQUE_EXPECTED_1, false, true ); };
OCL_OFF( fn() );
OCL_ON( fn() );
}
// multi-channel
TEST(TEST_CASE_NAME, multi_channel)
{
quality_test(create_brisque(), get_testfile_2a(), BRISQUE_EXPECTED_2, false, true);
}
// check brisque model/range persistence
TEST(TEST_CASE_NAME, model_persistence )
{
auto ptr = create_brisque();
auto fn = [&ptr]() { quality_test(ptr, get_testfile_1a(), BRISQUE_EXPECTED_1, false, true); };
fn();
fn(); // model/range should persist with brisque ptr through multiple invocations
}
// check compute features interface method
TEST(TEST_CASE_NAME, compute_features)
{
auto ptr = create_brisque();
cv::Mat features;
ptr->computeFeatures(get_testfile_1a(), features);
EXPECT_EQ(features.rows, 1);
EXPECT_EQ(features.cols, 36);
}
/*
// internal a/b test
TEST(TEST_CASE_NAME, performance)
{
auto ref = get_testfile_1a();
auto alg = create_brisque();
quality_performance_test("BRISQUE", [&]() { alg->compute(ref); });
}
*/
}
} // namespace
+53
View File
@@ -0,0 +1,53 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "test_precomp.hpp"
#define TEST_CASE_NAME CV_Quality_GMSD
namespace opencv_test
{
namespace quality_test
{
// expected gmsd per channel
const cv::Scalar
GMSD_EXPECTED_1 = { .2393 }
, GMSD_EXPECTED_2 = { .0942, .1016, .0995 }
;
// static method
TEST(TEST_CASE_NAME, static_)
{
cv::Mat qMat = {};
quality_expect_near(quality::QualityGMSD::compute(get_testfile_1a(), get_testfile_1a(), qMat), cv::Scalar(0.)); // ref vs ref == 0.
check_quality_map(qMat);
}
// single channel, with and without opencl
TEST(TEST_CASE_NAME, single_channel)
{
auto fn = []() { quality_test(quality::QualityGMSD::create(get_testfile_1a()), get_testfile_1b(), GMSD_EXPECTED_1); };
OCL_OFF(fn());
OCL_ON(fn());
}
// multi-channel
TEST(TEST_CASE_NAME, multi_channel)
{
quality_test(quality::QualityGMSD::create(get_testfile_2a()), get_testfile_2b(), GMSD_EXPECTED_2);
}
// internal A/B test
/*
TEST(TEST_CASE_NAME, performance)
{
auto ref = get_testfile_1a();
auto cmp = get_testfile_1b();
quality_performance_test("GMSD", [&]() { cv::quality::QualityGMSD::compute(ref, cmp, cv::noArray()); });
}
*/
}
} // namespace
+9
View File
@@ -0,0 +1,9 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "test_precomp.hpp"
CV_TEST_MAIN("",
cvtest::addDataSearchSubDirectory("contrib/quality") // for ocv_add_testdata
, cvtest::addDataSearchSubDirectory("quality") // for ${OPENCV_TEST_DATA_PATH}
)
+47
View File
@@ -0,0 +1,47 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "test_precomp.hpp"
#define TEST_CASE_NAME CV_Quality_MSE
namespace opencv_test
{
namespace quality_test
{
// static method
TEST(TEST_CASE_NAME, static_ )
{
cv::Mat qMat = {};
quality_expect_near(quality::QualityMSE::compute(get_testfile_1a(), get_testfile_1a(), qMat), cv::Scalar(0.)); // ref vs ref == 0
check_quality_map(qMat);
}
// single channel, with and without opencl
TEST(TEST_CASE_NAME, single_channel )
{
auto fn = []() { quality_test(quality::QualityMSE::create(get_testfile_1a()), get_testfile_1b(), MSE_EXPECTED_1); };
OCL_OFF( fn() );
OCL_ON( fn() );
}
// multi-channel
TEST(TEST_CASE_NAME, multi_channel)
{
quality_test(quality::QualityMSE::create(get_testfile_2a()), get_testfile_2b(), MSE_EXPECTED_2);
}
// internal a/b test
/*
TEST(TEST_CASE_NAME, performance)
{
auto ref = get_testfile_1a();
auto cmp = get_testfile_1b();
quality_performance_test("MSE", [&]() { cv::quality::QualityMSE::compute(ref, cmp, cv::noArray()); });
}
*/
}
} // namespace
+131
View File
@@ -0,0 +1,131 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#ifndef OPENCV_TEST_PRECOMP_HPP
#define OPENCV_TEST_PRECOMP_HPP
#include <chrono>
#include <opencv2/core.hpp>
#include <opencv2/ts.hpp>
#include <opencv2/ts/ocl_test.hpp> // OCL_ON, OCL_OFF
#include <opencv2/imgcodecs.hpp>
#include <opencv2/quality.hpp>
#include <opencv2/quality/quality_utils.hpp>
namespace opencv_test
{
namespace quality_test
{
const cv::String
dataDir = "cv/optflow/"
, testfile1a = dataDir + "rock_1.bmp"
, testfile1b = dataDir + "rock_2.bmp"
, testfile2a = dataDir + "RubberWhale1.png"
, testfile2b = dataDir + "RubberWhale2.png"
;
const cv::Scalar
MSE_EXPECTED_1 = { 2136.0525 } // matlab: immse('rock_1.bmp', 'rock_2.bmp') == 2.136052552083333e+03
, MSE_EXPECTED_2 = { 92.8235, 109.4104, 121.4 } // matlab: immse('rubberwhale1.png', 'rubberwhale2.png') == {92.8235, 109.4104, 121.4}
;
inline cv::Mat get_testfile(const cv::String& path, int flags = IMREAD_UNCHANGED )
{
auto full_path = TS::ptr()->get_data_path() + path;
auto result = cv::imread( full_path, flags );
if (result.empty())
CV_Error(cv::Error::StsObjectNotFound, "Cannot find file: " + full_path );
return result;
}
inline cv::Mat get_testfile_1a() { return get_testfile(testfile1a, IMREAD_GRAYSCALE); }
inline cv::Mat get_testfile_1b() { return get_testfile(testfile1b, IMREAD_GRAYSCALE); }
inline cv::Mat get_testfile_2a() { return get_testfile(testfile2a); }
inline cv::Mat get_testfile_2b() { return get_testfile(testfile2b); }
const double QUALITY_ERR_TOLERANCE = .002 // allowed margin of error
;
inline void quality_expect_near( const cv::Scalar& a, const cv::Scalar& b, double err_tolerance = QUALITY_ERR_TOLERANCE)
{
for (int i = 0; i < a.rows; ++i)
{
if (std::isinf(a(i)))
EXPECT_EQ(a(i), b(i));
else
EXPECT_NEAR(a(i), b(i), err_tolerance);
}
}
template <typename TMat>
inline void check_quality_map( const TMat& mat, const bool expect_empty = false )
{
EXPECT_EQ( mat.empty(), expect_empty );
if ( !expect_empty )
{
EXPECT_GT(mat.rows, 0);
EXPECT_GT(mat.cols, 0);
}
}
// execute quality test for a pair of images
template <typename TMat>
inline void quality_test(cv::Ptr<quality::QualityBase> ptr, const TMat& cmp, const Scalar& expected, const bool quality_map_expected = true, const bool empty_expected = false )
{
cv::Mat qMat = {};
cv::UMat qUMat = {};
// quality map should return empty in initial state
ptr->getQualityMap(qMat);
EXPECT_TRUE( qMat.empty() );
// compute quality, check result
quality_expect_near( expected, ptr->compute(cmp));
if (empty_expected)
EXPECT_TRUE(ptr->empty());
else
EXPECT_FALSE(ptr->empty());
// getQualityMap to Mat, UMat
ptr->getQualityMap(qMat);
ptr->getQualityMap(qUMat);
// check them
check_quality_map(qMat, !quality_map_expected);
check_quality_map(qUMat, !quality_map_expected);
// reset algorithm, should now be empty
ptr->clear();
EXPECT_TRUE(ptr->empty());
}
/* A/B test benchmarking for development purposes */
/*
template <typename Fn>
inline void quality_performance_test( const char* name, Fn&& op )
{
const auto exec_test = [&]()
{
const int NRUNS = 100;
const auto start_t = std::chrono::high_resolution_clock::now();
for (int i = 0; i < NRUNS; ++i)
op();
const auto end_t = std::chrono::high_resolution_clock::now();
std::cout << name << " performance (OCL=" << cv::ocl::useOpenCL() << "): " << (double)(std::chrono::duration_cast<std::chrono::milliseconds>(end_t - start_t).count()) / (double)NRUNS << "ms\n";
};
// only run tests in NDEBUG mode
#ifdef NDEBUG
OCL_OFF(exec_test());
OCL_ON(exec_test());
#endif
}
*/
}
}
#endif
+51
View File
@@ -0,0 +1,51 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "test_precomp.hpp"
#define TEST_CASE_NAME CV_Quality_PSNR
namespace opencv_test
{
namespace quality_test
{
const cv::Scalar
PSNR_EXPECTED_1 = { 14.8347, INFINITY, INFINITY, INFINITY } // matlab: psnr('rock_1.bmp', 'rock_2.bmp') == 14.8347
, 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
;
// static method
TEST(TEST_CASE_NAME, static_)
{
cv::Mat qMat = {};
quality_expect_near(quality::QualityPSNR::compute(get_testfile_1a(), get_testfile_1a(), qMat), cv::Scalar(INFINITY, INFINITY, INFINITY, INFINITY)); // ref vs ref == inf
check_quality_map(qMat);
}
// single channel, with/without opencl
TEST(TEST_CASE_NAME, single_channel)
{
auto fn = []() { quality_test(quality::QualityPSNR::create(get_testfile_1a()), get_testfile_1b(), PSNR_EXPECTED_1); };
OCL_OFF( fn() );
OCL_ON( fn() );
}
// multi-channel
TEST(TEST_CASE_NAME, multi_channel)
{
quality_test(quality::QualityPSNR::create(get_testfile_2a()), get_testfile_2b(), PSNR_EXPECTED_2);
}
// internal a/b test
/*
TEST(TEST_CASE_NAME, performance)
{
auto ref = get_testfile_1a();
auto cmp = get_testfile_1b();
quality_performance_test("PSNR", [&]() { cv::quality::QualityPSNR::compute(ref, cmp, cv::noArray()); });
}
*/
}
} // namespace
+52
View File
@@ -0,0 +1,52 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "test_precomp.hpp"
#define TEST_CASE_NAME CV_Quality_SSIM
namespace opencv_test
{
namespace quality_test
{
// expected ssim per channel
const cv::Scalar
SSIM_EXPECTED_1 = { .1501 }
, SSIM_EXPECTED_2 = { .7541, .7742, .8095 }
;
// static method
TEST(TEST_CASE_NAME, static_)
{
cv::Mat qMat = {};
quality_expect_near(quality::QualitySSIM::compute(get_testfile_1a(), get_testfile_1a(), qMat), cv::Scalar(1.)); // ref vs ref == 1.
check_quality_map(qMat);
}
// single channel, with/without opencl
TEST(TEST_CASE_NAME, single_channel)
{
auto fn = []() { quality_test(quality::QualitySSIM::create(get_testfile_1a()), get_testfile_1b(), SSIM_EXPECTED_1); };
OCL_OFF(fn());
OCL_ON(fn());
}
// multi-channel
TEST(TEST_CASE_NAME, multi_channel)
{
quality_test(quality::QualitySSIM::create(get_testfile_2a()), get_testfile_2b(), SSIM_EXPECTED_2);
}
// internal a/b test
/*
TEST(TEST_CASE_NAME, performance)
{
auto ref = get_testfile_1a();
auto cmp = get_testfile_1b();
quality_performance_test("SSIM", [&]() { cv::quality::QualitySSIM::compute(ref, cmp, cv::noArray()); });
}
*/
}
} // namespace