feat: 切换后端至PaddleOCR-NCNN,切换工程为CMake
1.项目后端整体迁移至PaddleOCR-NCNN算法,已通过基本的兼容性测试 2.工程改为使用CMake组织,后续为了更好地兼容第三方库,不再提供QMake工程 3.重整权利声明文件,重整代码工程,确保最小化侵权风险 Log: 切换后端至PaddleOCR-NCNN,切换工程为CMake Change-Id: I4d5d2c5d37505a4a24b389b1a4c5d12f17bfa38c
This commit is contained in:
		
							
								
								
									
										133
									
								
								3rdparty/opencv-4.5.4/modules/photo/test/ocl/test_denoising.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										133
									
								
								3rdparty/opencv-4.5.4/modules/photo/test/ocl/test_denoising.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,133 @@
 | 
			
		||||
// 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.
 | 
			
		||||
 | 
			
		||||
// Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved.
 | 
			
		||||
// Third party copyrights are property of their respective owners.
 | 
			
		||||
 | 
			
		||||
#include "../test_precomp.hpp"
 | 
			
		||||
#include "opencv2/ts/ocl_test.hpp"
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_OPENCL
 | 
			
		||||
 | 
			
		||||
namespace opencv_test {
 | 
			
		||||
namespace ocl {
 | 
			
		||||
 | 
			
		||||
PARAM_TEST_CASE(FastNlMeansDenoisingTestBase, Channels, int, bool, bool)
 | 
			
		||||
{
 | 
			
		||||
    int cn, normType, templateWindowSize, searchWindowSize;
 | 
			
		||||
    std::vector<float> h;
 | 
			
		||||
    bool use_roi, use_image;
 | 
			
		||||
 | 
			
		||||
    TEST_DECLARE_INPUT_PARAMETER(src);
 | 
			
		||||
    TEST_DECLARE_OUTPUT_PARAMETER(dst);
 | 
			
		||||
 | 
			
		||||
    virtual void SetUp()
 | 
			
		||||
    {
 | 
			
		||||
        cn = GET_PARAM(0);
 | 
			
		||||
        normType = GET_PARAM(1);
 | 
			
		||||
        use_roi = GET_PARAM(2);
 | 
			
		||||
        use_image = GET_PARAM(3);
 | 
			
		||||
 | 
			
		||||
        templateWindowSize = 7;
 | 
			
		||||
        searchWindowSize = 21;
 | 
			
		||||
 | 
			
		||||
        h.resize(cn);
 | 
			
		||||
        for (int i=0; i<cn; i++)
 | 
			
		||||
            h[i] = 3.0f + 0.5f*i;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void generateTestData()
 | 
			
		||||
    {
 | 
			
		||||
        const int type = CV_8UC(cn);
 | 
			
		||||
        Mat image;
 | 
			
		||||
 | 
			
		||||
        if (use_image) {
 | 
			
		||||
            image = readImage("denoising/lena_noised_gaussian_sigma=10.png",
 | 
			
		||||
                                  cn == 1 ? IMREAD_GRAYSCALE : IMREAD_COLOR);
 | 
			
		||||
            ASSERT_FALSE(image.empty());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Size roiSize = use_image ? image.size() : randomSize(1, MAX_VALUE);
 | 
			
		||||
        Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
 | 
			
		||||
        randomSubMat(src, src_roi, roiSize, srcBorder, type, 0, 255);
 | 
			
		||||
        if (use_image) {
 | 
			
		||||
            ASSERT_TRUE(cn > 0 && cn <= 4);
 | 
			
		||||
            if (cn == 2) {
 | 
			
		||||
                int from_to[] = { 0,0, 1,1 };
 | 
			
		||||
                src_roi.create(roiSize, type);
 | 
			
		||||
                mixChannels(&image, 1, &src_roi, 1, from_to, 2);
 | 
			
		||||
            }
 | 
			
		||||
            else if (cn == 4) {
 | 
			
		||||
                int from_to[] = { 0,0, 1,1, 2,2, 1,3};
 | 
			
		||||
                src_roi.create(roiSize, type);
 | 
			
		||||
                mixChannels(&image, 1, &src_roi, 1, from_to, 4);
 | 
			
		||||
            }
 | 
			
		||||
            else image.copyTo(src_roi);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Border dstBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
 | 
			
		||||
        randomSubMat(dst, dst_roi, roiSize, dstBorder, type, 0, 255);
 | 
			
		||||
 | 
			
		||||
        UMAT_UPLOAD_INPUT_PARAMETER(src);
 | 
			
		||||
        UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
typedef FastNlMeansDenoisingTestBase FastNlMeansDenoising;
 | 
			
		||||
 | 
			
		||||
OCL_TEST_P(FastNlMeansDenoising, Mat)
 | 
			
		||||
{
 | 
			
		||||
    for (int j = 0; j < test_loop_times; j++)
 | 
			
		||||
    {
 | 
			
		||||
        generateTestData();
 | 
			
		||||
 | 
			
		||||
        OCL_OFF(cv::fastNlMeansDenoising(src_roi, dst_roi, std::vector<float>(1, h[0]), templateWindowSize, searchWindowSize, normType));
 | 
			
		||||
        OCL_ON(cv::fastNlMeansDenoising(usrc_roi, udst_roi, std::vector<float>(1, h[0]), templateWindowSize, searchWindowSize, normType));
 | 
			
		||||
 | 
			
		||||
        OCL_EXPECT_MATS_NEAR(dst, 1);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
typedef FastNlMeansDenoisingTestBase FastNlMeansDenoising_hsep;
 | 
			
		||||
 | 
			
		||||
OCL_TEST_P(FastNlMeansDenoising_hsep, Mat)
 | 
			
		||||
{
 | 
			
		||||
    for (int j = 0; j < test_loop_times; j++)
 | 
			
		||||
    {
 | 
			
		||||
        generateTestData();
 | 
			
		||||
 | 
			
		||||
        OCL_OFF(cv::fastNlMeansDenoising(src_roi, dst_roi, h, templateWindowSize, searchWindowSize, normType));
 | 
			
		||||
        OCL_ON(cv::fastNlMeansDenoising(usrc_roi, udst_roi, h, templateWindowSize, searchWindowSize, normType));
 | 
			
		||||
 | 
			
		||||
        OCL_EXPECT_MATS_NEAR(dst, 1);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
typedef FastNlMeansDenoisingTestBase FastNlMeansDenoisingColored;
 | 
			
		||||
 | 
			
		||||
OCL_TEST_P(FastNlMeansDenoisingColored, Mat)
 | 
			
		||||
{
 | 
			
		||||
    for (int j = 0; j < test_loop_times; j++)
 | 
			
		||||
    {
 | 
			
		||||
        generateTestData();
 | 
			
		||||
 | 
			
		||||
        OCL_OFF(cv::fastNlMeansDenoisingColored(src_roi, dst_roi, h[0], h[0], templateWindowSize, searchWindowSize));
 | 
			
		||||
        OCL_ON(cv::fastNlMeansDenoisingColored(usrc_roi, udst_roi, h[0], h[0], templateWindowSize, searchWindowSize));
 | 
			
		||||
 | 
			
		||||
        OCL_EXPECT_MATS_NEAR(dst, 1);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
OCL_INSTANTIATE_TEST_CASE_P(Photo, FastNlMeansDenoising,
 | 
			
		||||
                            Combine(Values(1, 2, 3, 4), Values((int)NORM_L2, (int)NORM_L1),
 | 
			
		||||
                                    Bool(), Values(true)));
 | 
			
		||||
OCL_INSTANTIATE_TEST_CASE_P(Photo, FastNlMeansDenoising_hsep,
 | 
			
		||||
                            Combine(Values(1, 2, 3, 4), Values((int)NORM_L2, (int)NORM_L1),
 | 
			
		||||
                                    Bool(), Values(true)));
 | 
			
		||||
OCL_INSTANTIATE_TEST_CASE_P(Photo, FastNlMeansDenoisingColored,
 | 
			
		||||
                            Combine(Values(3, 4), Values((int)NORM_L2), Bool(), Values(false)));
 | 
			
		||||
 | 
			
		||||
} } // namespace opencv_test::ocl
 | 
			
		||||
 | 
			
		||||
#endif // HAVE_OPENCL
 | 
			
		||||
							
								
								
									
										247
									
								
								3rdparty/opencv-4.5.4/modules/photo/test/test_cloning.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										247
									
								
								3rdparty/opencv-4.5.4/modules/photo/test/test_cloning.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,247 @@
 | 
			
		||||
/*M///////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
//
 | 
			
		||||
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
 | 
			
		||||
//
 | 
			
		||||
//  By downloading, copying, installing or using the software you agree to this license.
 | 
			
		||||
//  If you do not agree to this license, do not download, install,
 | 
			
		||||
//  copy or use the software.
 | 
			
		||||
//
 | 
			
		||||
//
 | 
			
		||||
//                           License Agreement
 | 
			
		||||
//                For Open Source Computer Vision Library
 | 
			
		||||
//
 | 
			
		||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
 | 
			
		||||
// Third party copyrights are property of their respective owners.
 | 
			
		||||
//
 | 
			
		||||
// Redistribution and use in source and binary forms, with or without modification,
 | 
			
		||||
// are permitted provided that the following conditions are met:
 | 
			
		||||
//
 | 
			
		||||
//   * Redistribution's of source code must retain the above copyright notice,
 | 
			
		||||
//     this list of conditions and the following disclaimer.
 | 
			
		||||
//
 | 
			
		||||
//   * Redistribution's in binary form must reproduce the above copyright notice,
 | 
			
		||||
//     this list of conditions and the following disclaimer in the documentation
 | 
			
		||||
//     and/or other materials provided with the distribution.
 | 
			
		||||
//
 | 
			
		||||
//   * The name of the copyright holders may not be used to endorse or promote products
 | 
			
		||||
//     derived from this software without specific prior written permission.
 | 
			
		||||
//
 | 
			
		||||
// This software is provided by the copyright holders and contributors "as is" and
 | 
			
		||||
// any express or implied warranties, including, but not limited to, the implied
 | 
			
		||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
 | 
			
		||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
 | 
			
		||||
// indirect, incidental, special, exemplary, or consequential damages
 | 
			
		||||
// (including, but not limited to, procurement of substitute goods or services;
 | 
			
		||||
// loss of use, data, or profits; or business interruption) however caused
 | 
			
		||||
// and on any theory of liability, whether in contract, strict liability,
 | 
			
		||||
// or tort (including negligence or otherwise) arising in any way out of
 | 
			
		||||
// the use of this software, even if advised of the possibility of such damage.
 | 
			
		||||
//
 | 
			
		||||
//M*/
 | 
			
		||||
 | 
			
		||||
#include "test_precomp.hpp"
 | 
			
		||||
 | 
			
		||||
namespace opencv_test { namespace {
 | 
			
		||||
 | 
			
		||||
#define OUTPUT_SAVING 0
 | 
			
		||||
#if OUTPUT_SAVING
 | 
			
		||||
#define SAVE(x) std::vector<int> params;\
 | 
			
		||||
                params.push_back(16);\
 | 
			
		||||
                params.push_back(0);\
 | 
			
		||||
                imwrite(folder + "output.png", x ,params);
 | 
			
		||||
#else
 | 
			
		||||
#define SAVE(x)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
static const double numerical_precision = 0.05; // 95% of pixels should have exact values
 | 
			
		||||
 | 
			
		||||
TEST(Photo_SeamlessClone_normal, regression)
 | 
			
		||||
{
 | 
			
		||||
    string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/Normal_Cloning/";
 | 
			
		||||
    string original_path1 = folder + "source1.png";
 | 
			
		||||
    string original_path2 = folder + "destination1.png";
 | 
			
		||||
    string original_path3 = folder + "mask.png";
 | 
			
		||||
    string reference_path = folder + "reference.png";
 | 
			
		||||
 | 
			
		||||
    Mat source = imread(original_path1, IMREAD_COLOR);
 | 
			
		||||
    Mat destination = imread(original_path2, IMREAD_COLOR);
 | 
			
		||||
    Mat mask = imread(original_path3, IMREAD_COLOR);
 | 
			
		||||
 | 
			
		||||
    ASSERT_FALSE(source.empty()) << "Could not load source image " << original_path1;
 | 
			
		||||
    ASSERT_FALSE(destination.empty()) << "Could not load destination image " << original_path2;
 | 
			
		||||
    ASSERT_FALSE(mask.empty()) << "Could not load mask image " << original_path3;
 | 
			
		||||
 | 
			
		||||
    Mat result;
 | 
			
		||||
    Point p;
 | 
			
		||||
    p.x = destination.size().width/2;
 | 
			
		||||
    p.y = destination.size().height/2;
 | 
			
		||||
    seamlessClone(source, destination, mask, p, result, 1);
 | 
			
		||||
 | 
			
		||||
    Mat reference = imread(reference_path);
 | 
			
		||||
    ASSERT_FALSE(reference.empty()) << "Could not load reference image " << reference_path;
 | 
			
		||||
 | 
			
		||||
    SAVE(result);
 | 
			
		||||
 | 
			
		||||
    double errorINF = cvtest::norm(reference, result, NORM_INF);
 | 
			
		||||
    EXPECT_LE(errorINF, 1);
 | 
			
		||||
    double errorL1 = cvtest::norm(reference, result, NORM_L1);
 | 
			
		||||
    EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();
 | 
			
		||||
 | 
			
		||||
    mask = Scalar(0, 0, 0);
 | 
			
		||||
    seamlessClone(source, destination, mask, p, result, 1);
 | 
			
		||||
 | 
			
		||||
    reference = destination;
 | 
			
		||||
    errorINF = cvtest::norm(reference, result, NORM_INF);
 | 
			
		||||
    EXPECT_LE(errorINF, 1);
 | 
			
		||||
    errorL1 = cvtest::norm(reference, result, NORM_L1);
 | 
			
		||||
    EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(Photo_SeamlessClone_mixed, regression)
 | 
			
		||||
{
 | 
			
		||||
    string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/Mixed_Cloning/";
 | 
			
		||||
    string original_path1 = folder + "source1.png";
 | 
			
		||||
    string original_path2 = folder + "destination1.png";
 | 
			
		||||
    string original_path3 = folder + "mask.png";
 | 
			
		||||
    string reference_path = folder + "reference.png";
 | 
			
		||||
 | 
			
		||||
    Mat source = imread(original_path1, IMREAD_COLOR);
 | 
			
		||||
    Mat destination = imread(original_path2, IMREAD_COLOR);
 | 
			
		||||
    Mat mask = imread(original_path3, IMREAD_COLOR);
 | 
			
		||||
 | 
			
		||||
    ASSERT_FALSE(source.empty()) << "Could not load source image " << original_path1;
 | 
			
		||||
    ASSERT_FALSE(destination.empty()) << "Could not load destination image " << original_path2;
 | 
			
		||||
    ASSERT_FALSE(mask.empty()) << "Could not load mask image " << original_path3;
 | 
			
		||||
 | 
			
		||||
    Mat result;
 | 
			
		||||
    Point p;
 | 
			
		||||
    p.x = destination.size().width/2;
 | 
			
		||||
    p.y = destination.size().height/2;
 | 
			
		||||
    seamlessClone(source, destination, mask, p, result, 2);
 | 
			
		||||
 | 
			
		||||
    SAVE(result);
 | 
			
		||||
 | 
			
		||||
    Mat reference = imread(reference_path);
 | 
			
		||||
    ASSERT_FALSE(reference.empty()) << "Could not load reference image " << reference_path;
 | 
			
		||||
 | 
			
		||||
    double errorINF = cvtest::norm(reference, result, NORM_INF);
 | 
			
		||||
    EXPECT_LE(errorINF, 1);
 | 
			
		||||
    double errorL1 = cvtest::norm(reference, result, NORM_L1);
 | 
			
		||||
    EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(Photo_SeamlessClone_featureExchange, regression)
 | 
			
		||||
{
 | 
			
		||||
    string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/Monochrome_Transfer/";
 | 
			
		||||
    string original_path1 = folder + "source1.png";
 | 
			
		||||
    string original_path2 = folder + "destination1.png";
 | 
			
		||||
    string original_path3 = folder + "mask.png";
 | 
			
		||||
    string reference_path = folder + "reference.png";
 | 
			
		||||
 | 
			
		||||
    Mat source = imread(original_path1, IMREAD_COLOR);
 | 
			
		||||
    Mat destination = imread(original_path2, IMREAD_COLOR);
 | 
			
		||||
    Mat mask = imread(original_path3, IMREAD_COLOR);
 | 
			
		||||
 | 
			
		||||
    ASSERT_FALSE(source.empty()) << "Could not load source image " << original_path1;
 | 
			
		||||
    ASSERT_FALSE(destination.empty()) << "Could not load destination image " << original_path2;
 | 
			
		||||
    ASSERT_FALSE(mask.empty()) << "Could not load mask image " << original_path3;
 | 
			
		||||
 | 
			
		||||
    Mat result;
 | 
			
		||||
    Point p;
 | 
			
		||||
    p.x = destination.size().width/2;
 | 
			
		||||
    p.y = destination.size().height/2;
 | 
			
		||||
    seamlessClone(source, destination, mask, p, result, 3);
 | 
			
		||||
 | 
			
		||||
    SAVE(result);
 | 
			
		||||
 | 
			
		||||
    Mat reference = imread(reference_path);
 | 
			
		||||
    ASSERT_FALSE(reference.empty()) << "Could not load reference image " << reference_path;
 | 
			
		||||
 | 
			
		||||
    double errorINF = cvtest::norm(reference, result, NORM_INF);
 | 
			
		||||
    EXPECT_LE(errorINF, 1);
 | 
			
		||||
    double errorL1 = cvtest::norm(reference, result, NORM_L1);
 | 
			
		||||
    EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(Photo_SeamlessClone_colorChange, regression)
 | 
			
		||||
{
 | 
			
		||||
    string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/color_change/";
 | 
			
		||||
    string original_path1 = folder + "source1.png";
 | 
			
		||||
    string original_path2 = folder + "mask.png";
 | 
			
		||||
    string reference_path = folder + "reference.png";
 | 
			
		||||
 | 
			
		||||
    Mat source = imread(original_path1, IMREAD_COLOR);
 | 
			
		||||
    Mat mask = imread(original_path2, IMREAD_COLOR);
 | 
			
		||||
 | 
			
		||||
    ASSERT_FALSE(source.empty()) << "Could not load source image " << original_path1;
 | 
			
		||||
    ASSERT_FALSE(mask.empty()) << "Could not load mask image " << original_path2;
 | 
			
		||||
 | 
			
		||||
    Mat result;
 | 
			
		||||
    colorChange(source, mask, result, 1.5, .5, .5);
 | 
			
		||||
 | 
			
		||||
    SAVE(result);
 | 
			
		||||
 | 
			
		||||
    Mat reference = imread(reference_path);
 | 
			
		||||
    ASSERT_FALSE(reference.empty()) << "Could not load reference image " << reference_path;
 | 
			
		||||
 | 
			
		||||
    double errorINF = cvtest::norm(reference, result, NORM_INF);
 | 
			
		||||
    EXPECT_LE(errorINF, 1);
 | 
			
		||||
    double errorL1 = cvtest::norm(reference, result, NORM_L1);
 | 
			
		||||
    EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(Photo_SeamlessClone_illuminationChange, regression)
 | 
			
		||||
{
 | 
			
		||||
    string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/Illumination_Change/";
 | 
			
		||||
    string original_path1 = folder + "source1.png";
 | 
			
		||||
    string original_path2 = folder + "mask.png";
 | 
			
		||||
    string reference_path = folder + "reference.png";
 | 
			
		||||
 | 
			
		||||
    Mat source = imread(original_path1, IMREAD_COLOR);
 | 
			
		||||
    Mat mask = imread(original_path2, IMREAD_COLOR);
 | 
			
		||||
 | 
			
		||||
    ASSERT_FALSE(source.empty()) << "Could not load source image " << original_path1;
 | 
			
		||||
    ASSERT_FALSE(mask.empty()) << "Could not load mask image " << original_path2;
 | 
			
		||||
 | 
			
		||||
    Mat result;
 | 
			
		||||
    illuminationChange(source, mask, result, 0.2f, 0.4f);
 | 
			
		||||
 | 
			
		||||
    SAVE(result);
 | 
			
		||||
 | 
			
		||||
    Mat reference = imread(reference_path);
 | 
			
		||||
    ASSERT_FALSE(reference.empty()) << "Could not load reference image " << reference_path;
 | 
			
		||||
 | 
			
		||||
    double errorINF = cvtest::norm(reference, result, NORM_INF);
 | 
			
		||||
    EXPECT_LE(errorINF, 1);
 | 
			
		||||
    double errorL1 = cvtest::norm(reference, result, NORM_L1);
 | 
			
		||||
    EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(Photo_SeamlessClone_textureFlattening, regression)
 | 
			
		||||
{
 | 
			
		||||
    string folder = string(cvtest::TS::ptr()->get_data_path()) + "cloning/Texture_Flattening/";
 | 
			
		||||
    string original_path1 = folder + "source1.png";
 | 
			
		||||
    string original_path2 = folder + "mask.png";
 | 
			
		||||
    string reference_path = folder + "reference.png";
 | 
			
		||||
 | 
			
		||||
    Mat source = imread(original_path1, IMREAD_COLOR);
 | 
			
		||||
    Mat mask = imread(original_path2, IMREAD_COLOR);
 | 
			
		||||
 | 
			
		||||
    ASSERT_FALSE(source.empty()) << "Could not load source image " << original_path1;
 | 
			
		||||
    ASSERT_FALSE(mask.empty()) << "Could not load mask image " << original_path2;
 | 
			
		||||
 | 
			
		||||
    Mat result;
 | 
			
		||||
    textureFlattening(source, mask, result, 30, 45, 3);
 | 
			
		||||
 | 
			
		||||
    SAVE(result);
 | 
			
		||||
 | 
			
		||||
    Mat reference = imread(reference_path);
 | 
			
		||||
    ASSERT_FALSE(reference.empty()) << "Could not load reference image " << reference_path;
 | 
			
		||||
 | 
			
		||||
    double errorINF = cvtest::norm(reference, result, NORM_INF);
 | 
			
		||||
    EXPECT_LE(errorINF, 1);
 | 
			
		||||
    double errorL1 = cvtest::norm(reference, result, NORM_L1);
 | 
			
		||||
    EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}} // namespace
 | 
			
		||||
							
								
								
									
										68
									
								
								3rdparty/opencv-4.5.4/modules/photo/test/test_decolor.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								3rdparty/opencv-4.5.4/modules/photo/test/test_decolor.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,68 @@
 | 
			
		||||
/*M///////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
//
 | 
			
		||||
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
 | 
			
		||||
//
 | 
			
		||||
//  By downloading, copying, installing or using the software you agree to this license.
 | 
			
		||||
//  If you do not agree to this license, do not download, install,
 | 
			
		||||
//  copy or use the software.
 | 
			
		||||
//
 | 
			
		||||
//
 | 
			
		||||
//                           License Agreement
 | 
			
		||||
//                For Open Source Computer Vision Library
 | 
			
		||||
//
 | 
			
		||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
 | 
			
		||||
// Third party copyrights are property of their respective owners.
 | 
			
		||||
//
 | 
			
		||||
// Redistribution and use in source and binary forms, with or without modification,
 | 
			
		||||
// are permitted provided that the following conditions are met:
 | 
			
		||||
//
 | 
			
		||||
//   * Redistribution's of source code must retain the above copyright notice,
 | 
			
		||||
//     this list of conditions and the following disclaimer.
 | 
			
		||||
//
 | 
			
		||||
//   * Redistribution's in binary form must reproduce the above copyright notice,
 | 
			
		||||
//     this list of conditions and the following disclaimer in the documentation
 | 
			
		||||
//     and/or other materials provided with the distribution.
 | 
			
		||||
//
 | 
			
		||||
//   * The name of the copyright holders may not be used to endorse or promote products
 | 
			
		||||
//     derived from this software without specific prior written permission.
 | 
			
		||||
//
 | 
			
		||||
// This software is provided by the copyright holders and contributors "as is" and
 | 
			
		||||
// any express or implied warranties, including, but not limited to, the implied
 | 
			
		||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
 | 
			
		||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
 | 
			
		||||
// indirect, incidental, special, exemplary, or consequential damages
 | 
			
		||||
// (including, but not limited to, procurement of substitute goods or services;
 | 
			
		||||
// loss of use, data, or profits; or business interruption) however caused
 | 
			
		||||
// and on any theory of liability, whether in contract, strict liability,
 | 
			
		||||
// or tort (including negligence or otherwise) arising in any way out of
 | 
			
		||||
// the use of this software, even if advised of the possibility of such damage.
 | 
			
		||||
//
 | 
			
		||||
//M*/
 | 
			
		||||
 | 
			
		||||
#include "test_precomp.hpp"
 | 
			
		||||
 | 
			
		||||
namespace opencv_test { namespace {
 | 
			
		||||
 | 
			
		||||
TEST(Photo_Decolor, regression)
 | 
			
		||||
{
 | 
			
		||||
    string folder = string(cvtest::TS::ptr()->get_data_path()) + "decolor/";
 | 
			
		||||
    string original_path = folder + "color_image_1.png";
 | 
			
		||||
 | 
			
		||||
    Mat original = imread(original_path, IMREAD_COLOR);
 | 
			
		||||
 | 
			
		||||
    ASSERT_FALSE(original.empty()) << "Could not load input image " << original_path;
 | 
			
		||||
    ASSERT_EQ(3, original.channels()) << "Load color input image " << original_path;
 | 
			
		||||
 | 
			
		||||
    Mat grayscale, color_boost;
 | 
			
		||||
    decolor(original, grayscale, color_boost);
 | 
			
		||||
 | 
			
		||||
    Mat reference_grayscale = imread(folder + "grayscale_reference.png", 0 /* == grayscale image*/);
 | 
			
		||||
    double gray_psnr = cvtest::PSNR(reference_grayscale, grayscale);
 | 
			
		||||
    EXPECT_GT(gray_psnr, 60.0);
 | 
			
		||||
 | 
			
		||||
    Mat reference_boost = imread(folder + "boost_reference.png");
 | 
			
		||||
    double boost_psnr = cvtest::PSNR(reference_boost, color_boost);
 | 
			
		||||
    EXPECT_GT(boost_psnr, 60.0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}} // namespace
 | 
			
		||||
							
								
								
									
										129
									
								
								3rdparty/opencv-4.5.4/modules/photo/test/test_denoise_tvl1.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										129
									
								
								3rdparty/opencv-4.5.4/modules/photo/test/test_denoise_tvl1.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,129 @@
 | 
			
		||||
/*M///////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
//
 | 
			
		||||
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
 | 
			
		||||
//
 | 
			
		||||
//  By downloading, copying, installing or using the software you agree to this license.
 | 
			
		||||
//  If you do not agree to this license, do not download, install,
 | 
			
		||||
//  copy or use the software.
 | 
			
		||||
//
 | 
			
		||||
//
 | 
			
		||||
//                           License Agreement
 | 
			
		||||
//                For Open Source Computer Vision Library
 | 
			
		||||
//
 | 
			
		||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
 | 
			
		||||
// Third party copyrights are property of their respective owners.
 | 
			
		||||
//
 | 
			
		||||
// Redistribution and use in source and binary forms, with or without modification,
 | 
			
		||||
// are permitted provided that the following conditions are met:
 | 
			
		||||
//
 | 
			
		||||
//   * Redistribution's of source code must retain the above copyright notice,
 | 
			
		||||
//     this list of conditions and the following disclaimer.
 | 
			
		||||
//
 | 
			
		||||
//   * Redistribution's in binary form must reproduce the above copyright notice,
 | 
			
		||||
//     this list of conditions and the following disclaimer in the documentation
 | 
			
		||||
//     and/or other materials provided with the distribution.
 | 
			
		||||
//
 | 
			
		||||
//   * The name of the copyright holders may not be used to endorse or promote products
 | 
			
		||||
//     derived from this software without specific prior written permission.
 | 
			
		||||
//
 | 
			
		||||
// This software is provided by the copyright holders and contributors "as is" and
 | 
			
		||||
// any express or implied warranties, including, but not limited to, the implied
 | 
			
		||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
 | 
			
		||||
// In no event shall the OpenCV Foundation or contributors be liable for any direct,
 | 
			
		||||
// indirect, incidental, special, exemplary, or consequential damages
 | 
			
		||||
// (including, but not limited to, procurement of substitute goods or services;
 | 
			
		||||
// loss of use, data, or profits; or business interruption) however caused
 | 
			
		||||
// and on any theory of liability, whether in contract, strict liability,
 | 
			
		||||
// or tort (including negligence or otherwise) arising in any way out of
 | 
			
		||||
// the use of this software, even if advised of the possibility of such damage.
 | 
			
		||||
//
 | 
			
		||||
//M*/
 | 
			
		||||
#include "test_precomp.hpp"
 | 
			
		||||
 | 
			
		||||
namespace opencv_test { namespace {
 | 
			
		||||
 | 
			
		||||
void make_noisy(const cv::Mat& img, cv::Mat& noisy, double sigma, double pepper_salt_ratio,cv::RNG& rng)
 | 
			
		||||
{
 | 
			
		||||
    noisy.create(img.size(), img.type());
 | 
			
		||||
    cv::Mat noise(img.size(), img.type()), mask(img.size(), CV_8U);
 | 
			
		||||
    rng.fill(noise,cv::RNG::NORMAL,128.0,sigma);
 | 
			
		||||
    cv::addWeighted(img, 1, noise, 1, -128, noisy);
 | 
			
		||||
    cv::randn(noise, cv::Scalar::all(0), cv::Scalar::all(2));
 | 
			
		||||
    noise *= 255;
 | 
			
		||||
    cv::randu(mask, 0, cvRound(1./pepper_salt_ratio));
 | 
			
		||||
    cv::Mat half = mask.colRange(0, img.cols/2);
 | 
			
		||||
    half = cv::Scalar::all(1);
 | 
			
		||||
    noise.setTo(128, mask);
 | 
			
		||||
    cv::addWeighted(noisy, 1, noise, 1, -128, noisy);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if 0
 | 
			
		||||
void make_spotty(cv::Mat& img,cv::RNG& rng, int r=3,int n=1000)
 | 
			
		||||
{
 | 
			
		||||
    for(int i=0;i<n;i++)
 | 
			
		||||
    {
 | 
			
		||||
        int x=rng(img.cols-r),y=rng(img.rows-r);
 | 
			
		||||
        if(rng(2)==0)
 | 
			
		||||
            img(cv::Range(y,y+r),cv::Range(x,x+r))=(uchar)0;
 | 
			
		||||
        else
 | 
			
		||||
            img(cv::Range(y,y+r),cv::Range(x,x+r))=(uchar)255;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
bool validate_pixel(const cv::Mat& image,int x,int y,uchar val)
 | 
			
		||||
{
 | 
			
		||||
    bool ok = std::abs(image.at<uchar>(x,y) - val) < 10;
 | 
			
		||||
    printf("test: image(%d,%d)=%d vs %d - %s\n",x,y,(int)image.at<uchar>(x,y),val,ok?"ok":"bad");
 | 
			
		||||
    return ok;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(Optim_denoise_tvl1, regression_basic)
 | 
			
		||||
{
 | 
			
		||||
    cv::RNG rng(42);
 | 
			
		||||
    cv::Mat img = cv::imread(cvtest::TS::ptr()->get_data_path() + "shared/lena.png", 0), noisy, res;
 | 
			
		||||
 | 
			
		||||
    ASSERT_FALSE(img.empty()) << "Error: can't open 'lena.png'";
 | 
			
		||||
 | 
			
		||||
    const int obs_num=5;
 | 
			
		||||
    std::vector<cv::Mat> images(obs_num, cv::Mat());
 | 
			
		||||
    for(int i=0;i<(int)images.size();i++)
 | 
			
		||||
    {
 | 
			
		||||
        make_noisy(img,images[i], 20, 0.02,rng);
 | 
			
		||||
        //make_spotty(images[i],rng);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //cv::imshow("test", images[0]);
 | 
			
		||||
    cv::denoise_TVL1(images, res);
 | 
			
		||||
    //cv::imshow("denoised", res);
 | 
			
		||||
    //cv::waitKey();
 | 
			
		||||
 | 
			
		||||
#if 0
 | 
			
		||||
    ASSERT_TRUE(validate_pixel(res,248,334,179));
 | 
			
		||||
    ASSERT_TRUE(validate_pixel(res,489,333,172));
 | 
			
		||||
    ASSERT_TRUE(validate_pixel(res,425,507,104));
 | 
			
		||||
    ASSERT_TRUE(validate_pixel(res,489,486,105));
 | 
			
		||||
    ASSERT_TRUE(validate_pixel(res,223,208,64));
 | 
			
		||||
    ASSERT_TRUE(validate_pixel(res,418,3,78));
 | 
			
		||||
    ASSERT_TRUE(validate_pixel(res,63,76,97));
 | 
			
		||||
    ASSERT_TRUE(validate_pixel(res,29,134,126));
 | 
			
		||||
    ASSERT_TRUE(validate_pixel(res,219,291,174));
 | 
			
		||||
    ASSERT_TRUE(validate_pixel(res,384,124,76));
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if 1
 | 
			
		||||
    ASSERT_TRUE(validate_pixel(res,248,334,194));
 | 
			
		||||
    ASSERT_TRUE(validate_pixel(res,489,333,171));
 | 
			
		||||
    ASSERT_TRUE(validate_pixel(res,425,507,103));
 | 
			
		||||
    ASSERT_TRUE(validate_pixel(res,489,486,109));
 | 
			
		||||
    ASSERT_TRUE(validate_pixel(res,223,208,72));
 | 
			
		||||
    ASSERT_TRUE(validate_pixel(res,418,3,58));
 | 
			
		||||
    ASSERT_TRUE(validate_pixel(res,63,76,93));
 | 
			
		||||
    ASSERT_TRUE(validate_pixel(res,29,134,127));
 | 
			
		||||
    ASSERT_TRUE(validate_pixel(res,219,291,180));
 | 
			
		||||
    ASSERT_TRUE(validate_pixel(res,384,124,80));
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}} // namespace
 | 
			
		||||
							
								
								
									
										168
									
								
								3rdparty/opencv-4.5.4/modules/photo/test/test_denoising.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										168
									
								
								3rdparty/opencv-4.5.4/modules/photo/test/test_denoising.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,168 @@
 | 
			
		||||
/*M///////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
//
 | 
			
		||||
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
 | 
			
		||||
//
 | 
			
		||||
//  By downloading, copying, installing or using the software you agree to this license.
 | 
			
		||||
//  If you do not agree to this license, do not download, install,
 | 
			
		||||
//  copy or use the software.
 | 
			
		||||
//
 | 
			
		||||
//
 | 
			
		||||
//                           License Agreement
 | 
			
		||||
//                For Open Source Computer Vision Library
 | 
			
		||||
//
 | 
			
		||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
 | 
			
		||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
 | 
			
		||||
// Third party copyrights are property of their respective owners.
 | 
			
		||||
//
 | 
			
		||||
// Redistribution and use in source and binary forms, with or without modification,
 | 
			
		||||
// are permitted provided that the following conditions are met:
 | 
			
		||||
//
 | 
			
		||||
//   * Redistribution's of source code must retain the above copyright notice,
 | 
			
		||||
//     this list of conditions and the following disclaimer.
 | 
			
		||||
//
 | 
			
		||||
//   * Redistribution's in binary form must reproduce the above copyright notice,
 | 
			
		||||
//     this list of conditions and the following disclaimer in the documentation
 | 
			
		||||
//     and/or other materials provided with the distribution.
 | 
			
		||||
//
 | 
			
		||||
//   * The name of the copyright holders may not be used to endorse or promote products
 | 
			
		||||
//     derived from this software without specific prior written permission.
 | 
			
		||||
//
 | 
			
		||||
// This software is provided by the copyright holders and contributors "as is" and
 | 
			
		||||
// any express or implied warranties, including, but not limited to, the implied
 | 
			
		||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
 | 
			
		||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
 | 
			
		||||
// indirect, incidental, special, exemplary, or consequential damages
 | 
			
		||||
// (including, but not limited to, procurement of substitute goods or services;
 | 
			
		||||
// loss of use, data, or profits; or business interruption) however caused
 | 
			
		||||
// and on any theory of liability, whether in contract, strict liability,
 | 
			
		||||
// or tort (including negligence or otherwise) arising in any way out of
 | 
			
		||||
// the use of this software, even if advised of the possibility of such damage.
 | 
			
		||||
//
 | 
			
		||||
//M*/
 | 
			
		||||
 | 
			
		||||
#include "test_precomp.hpp"
 | 
			
		||||
 | 
			
		||||
namespace opencv_test { namespace {
 | 
			
		||||
 | 
			
		||||
//#define DUMP_RESULTS
 | 
			
		||||
 | 
			
		||||
#ifdef DUMP_RESULTS
 | 
			
		||||
#  define DUMP(image, path) imwrite(path, image)
 | 
			
		||||
#else
 | 
			
		||||
#  define DUMP(image, path)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
TEST(Photo_DenoisingGrayscale, regression)
 | 
			
		||||
{
 | 
			
		||||
    string folder = string(cvtest::TS::ptr()->get_data_path()) + "denoising/";
 | 
			
		||||
    string original_path = folder + "lena_noised_gaussian_sigma=10.png";
 | 
			
		||||
    string expected_path = folder + "lena_noised_denoised_grayscale_tw=7_sw=21_h=10.png";
 | 
			
		||||
 | 
			
		||||
    Mat original = imread(original_path, IMREAD_GRAYSCALE);
 | 
			
		||||
    Mat expected = imread(expected_path, IMREAD_GRAYSCALE);
 | 
			
		||||
 | 
			
		||||
    ASSERT_FALSE(original.empty()) << "Could not load input image " << original_path;
 | 
			
		||||
    ASSERT_FALSE(expected.empty()) << "Could not load reference image " << expected_path;
 | 
			
		||||
 | 
			
		||||
    Mat result;
 | 
			
		||||
    fastNlMeansDenoising(original, result, 10);
 | 
			
		||||
 | 
			
		||||
    DUMP(result, expected_path + ".res.png");
 | 
			
		||||
 | 
			
		||||
    ASSERT_EQ(0, cvtest::norm(result, expected, NORM_L2));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(Photo_DenoisingColored, regression)
 | 
			
		||||
{
 | 
			
		||||
    string folder = string(cvtest::TS::ptr()->get_data_path()) + "denoising/";
 | 
			
		||||
    string original_path = folder + "lena_noised_gaussian_sigma=10.png";
 | 
			
		||||
    string expected_path = folder + "lena_noised_denoised_lab12_tw=7_sw=21_h=10_h2=10.png";
 | 
			
		||||
 | 
			
		||||
    Mat original = imread(original_path, IMREAD_COLOR);
 | 
			
		||||
    Mat expected = imread(expected_path, IMREAD_COLOR);
 | 
			
		||||
 | 
			
		||||
    ASSERT_FALSE(original.empty()) << "Could not load input image " << original_path;
 | 
			
		||||
    ASSERT_FALSE(expected.empty()) << "Could not load reference image " << expected_path;
 | 
			
		||||
 | 
			
		||||
    Mat result;
 | 
			
		||||
    fastNlMeansDenoisingColored(original, result, 10, 10);
 | 
			
		||||
 | 
			
		||||
    DUMP(result, expected_path + ".res.png");
 | 
			
		||||
 | 
			
		||||
    ASSERT_EQ(0, cvtest::norm(result, expected, NORM_L2));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(Photo_DenoisingGrayscaleMulti, regression)
 | 
			
		||||
{
 | 
			
		||||
    const int imgs_count = 3;
 | 
			
		||||
    string folder = string(cvtest::TS::ptr()->get_data_path()) + "denoising/";
 | 
			
		||||
 | 
			
		||||
    string expected_path = folder + "lena_noised_denoised_multi_tw=7_sw=21_h=15.png";
 | 
			
		||||
    Mat expected = imread(expected_path, IMREAD_GRAYSCALE);
 | 
			
		||||
    ASSERT_FALSE(expected.empty()) << "Could not load reference image " << expected_path;
 | 
			
		||||
 | 
			
		||||
    vector<Mat> original(imgs_count);
 | 
			
		||||
    for (int i = 0; i < imgs_count; i++)
 | 
			
		||||
    {
 | 
			
		||||
        string original_path = format("%slena_noised_gaussian_sigma=20_multi_%d.png", folder.c_str(), i);
 | 
			
		||||
        original[i] = imread(original_path, IMREAD_GRAYSCALE);
 | 
			
		||||
        ASSERT_FALSE(original[i].empty()) << "Could not load input image " << original_path;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Mat result;
 | 
			
		||||
    fastNlMeansDenoisingMulti(original, result, imgs_count / 2, imgs_count, 15);
 | 
			
		||||
 | 
			
		||||
    DUMP(result, expected_path + ".res.png");
 | 
			
		||||
 | 
			
		||||
    ASSERT_EQ(0, cvtest::norm(result, expected, NORM_L2));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(Photo_DenoisingColoredMulti, regression)
 | 
			
		||||
{
 | 
			
		||||
    const int imgs_count = 3;
 | 
			
		||||
    string folder = string(cvtest::TS::ptr()->get_data_path()) + "denoising/";
 | 
			
		||||
 | 
			
		||||
    string expected_path = folder + "lena_noised_denoised_multi_lab12_tw=7_sw=21_h=10_h2=15.png";
 | 
			
		||||
    Mat expected = imread(expected_path, IMREAD_COLOR);
 | 
			
		||||
    ASSERT_FALSE(expected.empty()) << "Could not load reference image " << expected_path;
 | 
			
		||||
 | 
			
		||||
    vector<Mat> original(imgs_count);
 | 
			
		||||
    for (int i = 0; i < imgs_count; i++)
 | 
			
		||||
    {
 | 
			
		||||
        string original_path = format("%slena_noised_gaussian_sigma=20_multi_%d.png", folder.c_str(), i);
 | 
			
		||||
        original[i] = imread(original_path, IMREAD_COLOR);
 | 
			
		||||
        ASSERT_FALSE(original[i].empty()) << "Could not load input image " << original_path;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Mat result;
 | 
			
		||||
    fastNlMeansDenoisingColoredMulti(original, result, imgs_count / 2, imgs_count, 10, 15);
 | 
			
		||||
 | 
			
		||||
    DUMP(result, expected_path + ".res.png");
 | 
			
		||||
 | 
			
		||||
    ASSERT_EQ(0, cvtest::norm(result, expected, NORM_L2));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(Photo_White, issue_2646)
 | 
			
		||||
{
 | 
			
		||||
    cv::Mat img(50, 50, CV_8UC1, cv::Scalar::all(255));
 | 
			
		||||
    cv::Mat filtered;
 | 
			
		||||
    cv::fastNlMeansDenoising(img, filtered);
 | 
			
		||||
 | 
			
		||||
    int nonWhitePixelsCount = (int)img.total() - cv::countNonZero(filtered == img);
 | 
			
		||||
 | 
			
		||||
    ASSERT_EQ(0, nonWhitePixelsCount);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(Photo_Denoising, speed)
 | 
			
		||||
{
 | 
			
		||||
    string imgname = string(cvtest::TS::ptr()->get_data_path()) + "shared/5MP.png";
 | 
			
		||||
    Mat src = imread(imgname, 0), dst;
 | 
			
		||||
 | 
			
		||||
    double t = (double)getTickCount();
 | 
			
		||||
    fastNlMeansDenoising(src, dst, 5, 7, 21);
 | 
			
		||||
    t = (double)getTickCount() - t;
 | 
			
		||||
    printf("execution time: %gms\n", t*1000./getTickFrequency());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}} // namespace
 | 
			
		||||
							
								
								
									
										120
									
								
								3rdparty/opencv-4.5.4/modules/photo/test/test_denoising.cuda.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										120
									
								
								3rdparty/opencv-4.5.4/modules/photo/test/test_denoising.cuda.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,120 @@
 | 
			
		||||
/*M///////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
//
 | 
			
		||||
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
 | 
			
		||||
//
 | 
			
		||||
//  By downloading, copying, installing or using the software you agree to this license.
 | 
			
		||||
//  If you do not agree to this license, do not download, install,
 | 
			
		||||
//  copy or use the software.
 | 
			
		||||
//
 | 
			
		||||
//
 | 
			
		||||
//                           License Agreement
 | 
			
		||||
//                For Open Source Computer Vision Library
 | 
			
		||||
//
 | 
			
		||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
 | 
			
		||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
 | 
			
		||||
// Third party copyrights are property of their respective owners.
 | 
			
		||||
//
 | 
			
		||||
// Redistribution and use in source and binary forms, with or without modification,
 | 
			
		||||
// are permitted provided that the following conditions are met:
 | 
			
		||||
//
 | 
			
		||||
//   * Redistribution's of source code must retain the above copyright notice,
 | 
			
		||||
//     this list of conditions and the following disclaimer.
 | 
			
		||||
//
 | 
			
		||||
//   * Redistribution's in binary form must reproduce the above copyright notice,
 | 
			
		||||
//     this list of conditions and the following disclaimer in the documentation
 | 
			
		||||
//     and/or other materials provided with the distribution.
 | 
			
		||||
//
 | 
			
		||||
//   * The name of the copyright holders may not be used to endorse or promote products
 | 
			
		||||
//     derived from this software without specific prior written permission.
 | 
			
		||||
//
 | 
			
		||||
// This software is provided by the copyright holders and contributors "as is" and
 | 
			
		||||
// any express or implied warranties, including, but not limited to, the implied
 | 
			
		||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
 | 
			
		||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
 | 
			
		||||
// indirect, incidental, special, exemplary, or consequential damages
 | 
			
		||||
// (including, but not limited to, procurement of substitute goods or services;
 | 
			
		||||
// loss of use, data, or profits; or business interruption) however caused
 | 
			
		||||
// and on any theory of liability, whether in contract, strict liability,
 | 
			
		||||
// or tort (including negligence or otherwise) arising in any way out of
 | 
			
		||||
// the use of this software, even if advised of the possibility of such damage.
 | 
			
		||||
//
 | 
			
		||||
//M*/
 | 
			
		||||
 | 
			
		||||
#include "test_precomp.hpp"
 | 
			
		||||
 | 
			
		||||
#include "opencv2/photo/cuda.hpp"
 | 
			
		||||
#include "opencv2/ts/cuda_test.hpp"
 | 
			
		||||
 | 
			
		||||
#include "opencv2/opencv_modules.hpp"
 | 
			
		||||
#include "cvconfig.h"
 | 
			
		||||
 | 
			
		||||
#if defined (HAVE_CUDA) && defined(HAVE_OPENCV_CUDAARITHM) && defined(HAVE_OPENCV_CUDAIMGPROC)
 | 
			
		||||
 | 
			
		||||
namespace opencv_test { namespace {
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////
 | 
			
		||||
// Brute Force Non local means
 | 
			
		||||
 | 
			
		||||
TEST(CUDA_BruteForceNonLocalMeans, Regression)
 | 
			
		||||
{
 | 
			
		||||
    using cv::cuda::GpuMat;
 | 
			
		||||
 | 
			
		||||
    cv::Mat bgr  = readImage("../gpu/denoising/lena_noised_gaussian_sigma=20_multi_0.png", cv::IMREAD_COLOR);
 | 
			
		||||
    ASSERT_FALSE(bgr.empty());
 | 
			
		||||
    cv::resize(bgr, bgr, cv::Size(256, 256));
 | 
			
		||||
 | 
			
		||||
    cv::Mat gray;
 | 
			
		||||
    cv::cvtColor(bgr, gray, cv::COLOR_BGR2GRAY);
 | 
			
		||||
 | 
			
		||||
    GpuMat dbgr, dgray;
 | 
			
		||||
    cv::cuda::nonLocalMeans(GpuMat(bgr),  dbgr, 20);
 | 
			
		||||
    cv::cuda::nonLocalMeans(GpuMat(gray), dgray, 20);
 | 
			
		||||
 | 
			
		||||
#if 0
 | 
			
		||||
    dumpImage("../gpu/denoising/nlm_denoised_lena_bgr.png", cv::Mat(dbgr));
 | 
			
		||||
    dumpImage("../gpu/denoising/nlm_denoised_lena_gray.png", cv::Mat(dgray));
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    cv::Mat bgr_gold  = readImage("../gpu/denoising/nlm_denoised_lena_bgr.png", cv::IMREAD_COLOR);
 | 
			
		||||
    cv::Mat gray_gold  = readImage("../gpu/denoising/nlm_denoised_lena_gray.png", cv::IMREAD_GRAYSCALE);
 | 
			
		||||
    ASSERT_FALSE(bgr_gold.empty() || gray_gold.empty());
 | 
			
		||||
    cv::resize(bgr_gold, bgr_gold, cv::Size(256, 256));
 | 
			
		||||
    cv::resize(gray_gold, gray_gold, cv::Size(256, 256));
 | 
			
		||||
 | 
			
		||||
    EXPECT_MAT_NEAR(bgr_gold, dbgr, 1);
 | 
			
		||||
    EXPECT_MAT_NEAR(gray_gold, dgray, 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////
 | 
			
		||||
// Fast Force Non local means
 | 
			
		||||
 | 
			
		||||
TEST(CUDA_FastNonLocalMeans, Regression)
 | 
			
		||||
{
 | 
			
		||||
    using cv::cuda::GpuMat;
 | 
			
		||||
 | 
			
		||||
    cv::Mat bgr  = readImage("../gpu/denoising/lena_noised_gaussian_sigma=20_multi_0.png", cv::IMREAD_COLOR);
 | 
			
		||||
    ASSERT_FALSE(bgr.empty());
 | 
			
		||||
 | 
			
		||||
    cv::Mat gray;
 | 
			
		||||
    cv::cvtColor(bgr, gray, cv::COLOR_BGR2GRAY);
 | 
			
		||||
 | 
			
		||||
    GpuMat dbgr, dgray;
 | 
			
		||||
 | 
			
		||||
    cv::cuda::fastNlMeansDenoising(GpuMat(gray),  dgray, 20);
 | 
			
		||||
    cv::cuda::fastNlMeansDenoisingColored(GpuMat(bgr),  dbgr, 20, 10);
 | 
			
		||||
 | 
			
		||||
#if 0
 | 
			
		||||
    dumpImage("../gpu/denoising/fnlm_denoised_lena_bgr.png", cv::Mat(dbgr));
 | 
			
		||||
    dumpImage("../gpu/denoising/fnlm_denoised_lena_gray.png", cv::Mat(dgray));
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    cv::Mat bgr_gold  = readImage("../gpu/denoising/fnlm_denoised_lena_bgr.png", cv::IMREAD_COLOR);
 | 
			
		||||
    cv::Mat gray_gold  = readImage("../gpu/denoising/fnlm_denoised_lena_gray.png", cv::IMREAD_GRAYSCALE);
 | 
			
		||||
    ASSERT_FALSE(bgr_gold.empty() || gray_gold.empty());
 | 
			
		||||
 | 
			
		||||
    EXPECT_MAT_NEAR(bgr_gold, dbgr, 1);
 | 
			
		||||
    EXPECT_MAT_NEAR(gray_gold, dgray, 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}} // namespace
 | 
			
		||||
#endif // HAVE_CUDA
 | 
			
		||||
							
								
								
									
										269
									
								
								3rdparty/opencv-4.5.4/modules/photo/test/test_hdr.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										269
									
								
								3rdparty/opencv-4.5.4/modules/photo/test/test_hdr.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,269 @@
 | 
			
		||||
 /*M///////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
//
 | 
			
		||||
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
 | 
			
		||||
//
 | 
			
		||||
//  By downloading, copying, installing or using the software you agree to this license.
 | 
			
		||||
//  If you do not agree to this license, do not download, install,
 | 
			
		||||
//  copy or use the software.
 | 
			
		||||
//
 | 
			
		||||
//
 | 
			
		||||
//                           License Agreement
 | 
			
		||||
//                For Open Source Computer Vision Library
 | 
			
		||||
//
 | 
			
		||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
 | 
			
		||||
// Third party copyrights are property of their respective owners.
 | 
			
		||||
//
 | 
			
		||||
// Redistribution and use in source and binary forms, with or without modification,
 | 
			
		||||
// are permitted provided that the following conditions are met:
 | 
			
		||||
//
 | 
			
		||||
//   * Redistribution's of source code must retain the above copyright notice,
 | 
			
		||||
//     this list of conditions and the following disclaimer.
 | 
			
		||||
//
 | 
			
		||||
//   * Redistribution's in binary form must reproduce the above copyright notice,
 | 
			
		||||
//     this list of conditions and the following disclaimer in the documentation
 | 
			
		||||
//     and/or other materials provided with the distribution.
 | 
			
		||||
//
 | 
			
		||||
//   * The name of the copyright holders may not be used to endorse or promote products
 | 
			
		||||
//     derived from this software without specific prior written permission.
 | 
			
		||||
//
 | 
			
		||||
// This software is provided by the copyright holders and contributors "as is" and
 | 
			
		||||
// any express or implied warranties, including, but not limited to, the implied
 | 
			
		||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
 | 
			
		||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
 | 
			
		||||
// indirect, incidental, special, exemplary, or consequential damages
 | 
			
		||||
// (including, but not limited to, procurement of substitute goods or services;
 | 
			
		||||
// loss of use, data, or profits; or business interruption) however caused
 | 
			
		||||
// and on any theory of liability, whether in contract, strict liability,
 | 
			
		||||
// or tort (including negligence or otherwise) arising in any way out of
 | 
			
		||||
// the use of this software, even if advised of the possibility of such damage.
 | 
			
		||||
//
 | 
			
		||||
//M*/
 | 
			
		||||
 | 
			
		||||
#include "test_precomp.hpp"
 | 
			
		||||
 | 
			
		||||
namespace opencv_test { namespace {
 | 
			
		||||
 | 
			
		||||
void loadImage(string path, Mat &img)
 | 
			
		||||
{
 | 
			
		||||
    img = imread(path, -1);
 | 
			
		||||
    ASSERT_FALSE(img.empty()) << "Could not load input image " << path;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void checkEqual(Mat img0, Mat img1, double threshold, const string& name)
 | 
			
		||||
{
 | 
			
		||||
    double max = 1.0;
 | 
			
		||||
    minMaxLoc(abs(img0 - img1), NULL, &max);
 | 
			
		||||
    ASSERT_FALSE(max > threshold) << "max=" << max << " threshold=" << threshold << " method=" << name;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static vector<float> DEFAULT_VECTOR;
 | 
			
		||||
void loadExposureSeq(String path, vector<Mat>& images, vector<float>& times = DEFAULT_VECTOR)
 | 
			
		||||
{
 | 
			
		||||
    std::ifstream list_file((path + "list.txt").c_str());
 | 
			
		||||
    ASSERT_TRUE(list_file.is_open());
 | 
			
		||||
    string name;
 | 
			
		||||
    float val;
 | 
			
		||||
    while(list_file >> name >> val) {
 | 
			
		||||
        Mat img = imread(path + name);
 | 
			
		||||
        ASSERT_FALSE(img.empty()) << "Could not load input image " << path + name;
 | 
			
		||||
        images.push_back(img);
 | 
			
		||||
        times.push_back(1 / val);
 | 
			
		||||
    }
 | 
			
		||||
    list_file.close();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loadResponseCSV(String path, Mat& response)
 | 
			
		||||
{
 | 
			
		||||
    response = Mat(256, 1, CV_32FC3);
 | 
			
		||||
    std::ifstream resp_file(path.c_str());
 | 
			
		||||
    for(int i = 0; i < 256; i++) {
 | 
			
		||||
        for(int c = 0; c < 3; c++) {
 | 
			
		||||
            resp_file >> response.at<Vec3f>(i)[c];
 | 
			
		||||
            resp_file.ignore(1);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    resp_file.close();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(Photo_Tonemap, regression)
 | 
			
		||||
{
 | 
			
		||||
    string test_path = string(cvtest::TS::ptr()->get_data_path()) + "hdr/tonemap/";
 | 
			
		||||
 | 
			
		||||
    Mat img, expected, result;
 | 
			
		||||
    loadImage(test_path + "image.hdr", img);
 | 
			
		||||
    float gamma = 2.2f;
 | 
			
		||||
 | 
			
		||||
    Ptr<Tonemap> linear = createTonemap(gamma);
 | 
			
		||||
    linear->process(img, result);
 | 
			
		||||
    loadImage(test_path + "linear.png", expected);
 | 
			
		||||
    result.convertTo(result, CV_8UC3, 255);
 | 
			
		||||
    checkEqual(result, expected, 3, "Simple");
 | 
			
		||||
 | 
			
		||||
    Ptr<TonemapDrago> drago = createTonemapDrago(gamma);
 | 
			
		||||
    drago->process(img, result);
 | 
			
		||||
    loadImage(test_path + "drago.png", expected);
 | 
			
		||||
    result.convertTo(result, CV_8UC3, 255);
 | 
			
		||||
    checkEqual(result, expected, 3, "Drago");
 | 
			
		||||
 | 
			
		||||
    Ptr<TonemapReinhard> reinhard = createTonemapReinhard(gamma);
 | 
			
		||||
    reinhard->process(img, result);
 | 
			
		||||
    loadImage(test_path + "reinhard.png", expected);
 | 
			
		||||
    result.convertTo(result, CV_8UC3, 255);
 | 
			
		||||
    checkEqual(result, expected, 3, "Reinhard");
 | 
			
		||||
 | 
			
		||||
    Ptr<TonemapMantiuk> mantiuk = createTonemapMantiuk(gamma);
 | 
			
		||||
    mantiuk->process(img, result);
 | 
			
		||||
    loadImage(test_path + "mantiuk.png", expected);
 | 
			
		||||
    result.convertTo(result, CV_8UC3, 255);
 | 
			
		||||
    checkEqual(result, expected, 3, "Mantiuk");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(Photo_AlignMTB, regression)
 | 
			
		||||
{
 | 
			
		||||
    const int TESTS_COUNT = 100;
 | 
			
		||||
    string folder = string(cvtest::TS::ptr()->get_data_path()) + "shared/";
 | 
			
		||||
 | 
			
		||||
    string file_name = folder + "lena.png";
 | 
			
		||||
    Mat img;
 | 
			
		||||
    loadImage(file_name, img);
 | 
			
		||||
    cvtColor(img, img, COLOR_RGB2GRAY);
 | 
			
		||||
 | 
			
		||||
    int max_bits = 5;
 | 
			
		||||
    int max_shift = 32;
 | 
			
		||||
    srand(static_cast<unsigned>(time(0)));
 | 
			
		||||
    int errors = 0;
 | 
			
		||||
 | 
			
		||||
    Ptr<AlignMTB> align = createAlignMTB(max_bits);
 | 
			
		||||
    RNG rng = theRNG();
 | 
			
		||||
 | 
			
		||||
    for(int i = 0; i < TESTS_COUNT; i++) {
 | 
			
		||||
        Point shift(rng.uniform(0, max_shift), rng.uniform(0, max_shift));
 | 
			
		||||
        Mat res;
 | 
			
		||||
        align->shiftMat(img, res, shift);
 | 
			
		||||
        Point calc = align->calculateShift(img, res);
 | 
			
		||||
        errors += (calc != -shift);
 | 
			
		||||
    }
 | 
			
		||||
    ASSERT_TRUE(errors < 5) << errors << " errors";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(Photo_MergeMertens, regression)
 | 
			
		||||
{
 | 
			
		||||
    string test_path = string(cvtest::TS::ptr()->get_data_path()) + "hdr/";
 | 
			
		||||
 | 
			
		||||
    vector<Mat> images;
 | 
			
		||||
    loadExposureSeq((test_path + "exposures/").c_str() , images);
 | 
			
		||||
 | 
			
		||||
    Ptr<MergeMertens> merge = createMergeMertens();
 | 
			
		||||
 | 
			
		||||
    Mat result, expected;
 | 
			
		||||
    loadImage(test_path + "merge/mertens.png", expected);
 | 
			
		||||
    merge->process(images, result);
 | 
			
		||||
    result.convertTo(result, CV_8UC3, 255);
 | 
			
		||||
    checkEqual(expected, result, 3, "Mertens");
 | 
			
		||||
 | 
			
		||||
    Mat uniform(100, 100, CV_8UC3);
 | 
			
		||||
    uniform = Scalar(0, 255, 0);
 | 
			
		||||
 | 
			
		||||
    images.clear();
 | 
			
		||||
    images.push_back(uniform);
 | 
			
		||||
 | 
			
		||||
    merge->process(images, result);
 | 
			
		||||
    result.convertTo(result, CV_8UC3, 255);
 | 
			
		||||
    checkEqual(uniform, result, 1e-2f, "Mertens");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(Photo_MergeDebevec, regression)
 | 
			
		||||
{
 | 
			
		||||
    string test_path = string(cvtest::TS::ptr()->get_data_path()) + "hdr/";
 | 
			
		||||
 | 
			
		||||
    vector<Mat> images;
 | 
			
		||||
    vector<float> times;
 | 
			
		||||
    Mat response;
 | 
			
		||||
    loadExposureSeq(test_path + "exposures/", images, times);
 | 
			
		||||
    loadResponseCSV(test_path + "exposures/response.csv", response);
 | 
			
		||||
 | 
			
		||||
    Ptr<MergeDebevec> merge = createMergeDebevec();
 | 
			
		||||
 | 
			
		||||
    Mat result, expected;
 | 
			
		||||
    loadImage(test_path + "merge/debevec.hdr", expected);
 | 
			
		||||
    merge->process(images, result, times, response);
 | 
			
		||||
 | 
			
		||||
    Ptr<Tonemap> map = createTonemap();
 | 
			
		||||
    map->process(result, result);
 | 
			
		||||
    map->process(expected, expected);
 | 
			
		||||
 | 
			
		||||
    checkEqual(expected, result, 1e-2f, "Debevec");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(Photo_MergeRobertson, regression)
 | 
			
		||||
{
 | 
			
		||||
    string test_path = string(cvtest::TS::ptr()->get_data_path()) + "hdr/";
 | 
			
		||||
 | 
			
		||||
    vector<Mat> images;
 | 
			
		||||
    vector<float> times;
 | 
			
		||||
    loadExposureSeq(test_path + "exposures/", images, times);
 | 
			
		||||
    Ptr<MergeRobertson> merge = createMergeRobertson();
 | 
			
		||||
    Mat result, expected;
 | 
			
		||||
    loadImage(test_path + "merge/robertson.hdr", expected);
 | 
			
		||||
    merge->process(images, result, times);
 | 
			
		||||
 | 
			
		||||
    const float eps = 6.f;
 | 
			
		||||
    checkEqual(expected, result, eps, "MergeRobertson");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(Photo_CalibrateDebevec, regression)
 | 
			
		||||
{
 | 
			
		||||
    string test_path = string(cvtest::TS::ptr()->get_data_path()) + "hdr/";
 | 
			
		||||
 | 
			
		||||
    vector<Mat> images;
 | 
			
		||||
    vector<float> times;
 | 
			
		||||
    Mat response, expected;
 | 
			
		||||
    loadExposureSeq(test_path + "exposures/", images, times);
 | 
			
		||||
    loadResponseCSV(test_path + "calibrate/debevec.csv", expected);
 | 
			
		||||
    Ptr<CalibrateDebevec> calibrate = createCalibrateDebevec();
 | 
			
		||||
 | 
			
		||||
    calibrate->process(images, response, times);
 | 
			
		||||
    Mat diff = abs(response - expected);
 | 
			
		||||
    diff = diff.mul(1.0f / response);
 | 
			
		||||
    double max;
 | 
			
		||||
    minMaxLoc(diff, NULL, &max);
 | 
			
		||||
#if defined(__arm__) || defined(__aarch64__)
 | 
			
		||||
    ASSERT_LT(max, 0.131);
 | 
			
		||||
#else
 | 
			
		||||
    ASSERT_LT(max, 0.1);
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(Photo_CalibrateRobertson, regression)
 | 
			
		||||
{
 | 
			
		||||
    string test_path = string(cvtest::TS::ptr()->get_data_path()) + "hdr/";
 | 
			
		||||
 | 
			
		||||
    vector<Mat> images;
 | 
			
		||||
    vector<float> times;
 | 
			
		||||
    Mat response, expected;
 | 
			
		||||
    loadExposureSeq(test_path + "exposures/", images, times);
 | 
			
		||||
    loadResponseCSV(test_path + "calibrate/robertson.csv", expected);
 | 
			
		||||
 | 
			
		||||
    Ptr<CalibrateRobertson> calibrate = createCalibrateRobertson();
 | 
			
		||||
    calibrate->process(images, response, times);
 | 
			
		||||
    checkEqual(expected, response, 1e-1f, "CalibrateRobertson");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(Photo_CalibrateRobertson, bug_18180)
 | 
			
		||||
{
 | 
			
		||||
    vector<Mat> images;
 | 
			
		||||
    vector<cv::String> fn;
 | 
			
		||||
    string test_path = cvtest::TS::ptr()->get_data_path() + "hdr/exposures/bug_18180/";
 | 
			
		||||
    for(int i = 1; i <= 4; ++i)
 | 
			
		||||
        images.push_back(imread(test_path + std::to_string(i) + ".jpg"));
 | 
			
		||||
    vector<float> times {15.0f, 2.5f, 0.25f, 0.33f};
 | 
			
		||||
    Mat response, expected;
 | 
			
		||||
    Ptr<CalibrateRobertson> calibrate = createCalibrateRobertson(2, 0.01f);
 | 
			
		||||
    calibrate->process(images, response, times);
 | 
			
		||||
    Mat response_no_nans = response.clone();
 | 
			
		||||
    patchNaNs(response_no_nans);
 | 
			
		||||
    // since there should be no NaNs, original response vs. response with NaNs patched should be identical
 | 
			
		||||
    EXPECT_EQ(0.0, cv::norm(response, response_no_nans, NORM_L2));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}} // namespace
 | 
			
		||||
							
								
								
									
										160
									
								
								3rdparty/opencv-4.5.4/modules/photo/test/test_inpaint.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										160
									
								
								3rdparty/opencv-4.5.4/modules/photo/test/test_inpaint.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,160 @@
 | 
			
		||||
/*M///////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
//
 | 
			
		||||
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
 | 
			
		||||
//
 | 
			
		||||
//  By downloading, copying, installing or using the software you agree to this license.
 | 
			
		||||
//  If you do not agree to this license, do not download, install,
 | 
			
		||||
//  copy or use the software.
 | 
			
		||||
//
 | 
			
		||||
//
 | 
			
		||||
//                           License Agreement
 | 
			
		||||
//                For Open Source Computer Vision Library
 | 
			
		||||
//
 | 
			
		||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
 | 
			
		||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
 | 
			
		||||
// Third party copyrights are property of their respective owners.
 | 
			
		||||
//
 | 
			
		||||
// Redistribution and use in source and binary forms, with or without modification,
 | 
			
		||||
// are permitted provided that the following conditions are met:
 | 
			
		||||
//
 | 
			
		||||
//   * Redistribution's of source code must retain the above copyright notice,
 | 
			
		||||
//     this list of conditions and the following disclaimer.
 | 
			
		||||
//
 | 
			
		||||
//   * Redistribution's in binary form must reproduce the above copyright notice,
 | 
			
		||||
//     this list of conditions and the following disclaimer in the documentation
 | 
			
		||||
//     and/or other materials provided with the distribution.
 | 
			
		||||
//
 | 
			
		||||
//   * The name of the copyright holders may not be used to endorse or promote products
 | 
			
		||||
//     derived from this software without specific prior written permission.
 | 
			
		||||
//
 | 
			
		||||
// This software is provided by the copyright holders and contributors "as is" and
 | 
			
		||||
// any express or implied warranties, including, but not limited to, the implied
 | 
			
		||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
 | 
			
		||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
 | 
			
		||||
// indirect, incidental, special, exemplary, or consequential damages
 | 
			
		||||
// (including, but not limited to, procurement of substitute goods or services;
 | 
			
		||||
// loss of use, data, or profits; or business interruption) however caused
 | 
			
		||||
// and on any theory of liability, whether in contract, strict liability,
 | 
			
		||||
// or tort (including negligence or otherwise) arising in any way out of
 | 
			
		||||
// the use of this software, even if advised of the possibility of such damage.
 | 
			
		||||
//
 | 
			
		||||
//M*/
 | 
			
		||||
 | 
			
		||||
#include "test_precomp.hpp"
 | 
			
		||||
 | 
			
		||||
namespace opencv_test { namespace {
 | 
			
		||||
 | 
			
		||||
class CV_InpaintTest : public cvtest::BaseTest
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    CV_InpaintTest();
 | 
			
		||||
    ~CV_InpaintTest();
 | 
			
		||||
protected:
 | 
			
		||||
    void run(int);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
CV_InpaintTest::CV_InpaintTest()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
CV_InpaintTest::~CV_InpaintTest() {}
 | 
			
		||||
 | 
			
		||||
void CV_InpaintTest::run( int )
 | 
			
		||||
{
 | 
			
		||||
    string folder = string(ts->get_data_path()) + "inpaint/";
 | 
			
		||||
    Mat orig = imread(folder + "orig.png");
 | 
			
		||||
    Mat exp1 = imread(folder + "exp1.png");
 | 
			
		||||
    Mat exp2 = imread(folder + "exp2.png");
 | 
			
		||||
    Mat mask = imread(folder + "mask.png");
 | 
			
		||||
 | 
			
		||||
    if (orig.empty() || exp1.empty() || exp2.empty() || mask.empty())
 | 
			
		||||
    {
 | 
			
		||||
        ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Mat inv_mask;
 | 
			
		||||
    mask.convertTo(inv_mask, CV_8UC3, -1.0, 255.0);
 | 
			
		||||
 | 
			
		||||
    Mat mask1ch;
 | 
			
		||||
    cv::cvtColor(mask, mask1ch, COLOR_BGR2GRAY);
 | 
			
		||||
 | 
			
		||||
    Mat test = orig.clone();
 | 
			
		||||
    test.setTo(Scalar::all(255), mask1ch);
 | 
			
		||||
 | 
			
		||||
    Mat res1, res2;
 | 
			
		||||
    inpaint( test, mask1ch, res1, 5, INPAINT_NS );
 | 
			
		||||
    inpaint( test, mask1ch, res2, 5, INPAINT_TELEA );
 | 
			
		||||
 | 
			
		||||
    Mat diff1, diff2;
 | 
			
		||||
    absdiff( orig, res1, diff1 );
 | 
			
		||||
    absdiff( orig, res2, diff2 );
 | 
			
		||||
 | 
			
		||||
    double n1 = cvtest::norm(diff1.reshape(1), NORM_INF, inv_mask.reshape(1));
 | 
			
		||||
    double n2 = cvtest::norm(diff2.reshape(1), NORM_INF, inv_mask.reshape(1));
 | 
			
		||||
 | 
			
		||||
    if (n1 != 0 || n2 != 0)
 | 
			
		||||
    {
 | 
			
		||||
        ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH );
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    absdiff( exp1, res1, diff1 );
 | 
			
		||||
    absdiff( exp2, res2, diff2 );
 | 
			
		||||
 | 
			
		||||
    n1 = cvtest::norm(diff1.reshape(1), NORM_INF, mask.reshape(1));
 | 
			
		||||
    n2 = cvtest::norm(diff2.reshape(1), NORM_INF, mask.reshape(1));
 | 
			
		||||
 | 
			
		||||
    const int jpeg_thres = 3;
 | 
			
		||||
    if (n1 > jpeg_thres || n2 > jpeg_thres)
 | 
			
		||||
    {
 | 
			
		||||
        ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ts->set_failed_test_info(cvtest::TS::OK);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(Photo_Inpaint, regression) { CV_InpaintTest test; test.safe_run(); }
 | 
			
		||||
 | 
			
		||||
typedef testing::TestWithParam<tuple<int> > formats;
 | 
			
		||||
 | 
			
		||||
TEST_P(formats, 1c)
 | 
			
		||||
{
 | 
			
		||||
    const int type = get<0>(GetParam());
 | 
			
		||||
    Mat src(100, 100, type);
 | 
			
		||||
    src.setTo(Scalar::all(128));
 | 
			
		||||
    Mat ref = src.clone();
 | 
			
		||||
    Mat dst, mask = Mat::zeros(src.size(), CV_8U);
 | 
			
		||||
 | 
			
		||||
    circle(src, Point(50, 50), 5, Scalar(200), 6);
 | 
			
		||||
    circle(mask, Point(50, 50), 5, Scalar(200), 6);
 | 
			
		||||
    inpaint(src, mask, dst, 10, INPAINT_NS);
 | 
			
		||||
 | 
			
		||||
    Mat dst2;
 | 
			
		||||
    inpaint(src, mask, dst2, 10, INPAINT_TELEA);
 | 
			
		||||
 | 
			
		||||
    ASSERT_LE(cv::norm(dst, ref, NORM_INF), 3.);
 | 
			
		||||
    ASSERT_LE(cv::norm(dst2, ref, NORM_INF), 3.);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
INSTANTIATE_TEST_CASE_P(Photo_Inpaint, formats, testing::Values(CV_32F, CV_16U, CV_8U));
 | 
			
		||||
 | 
			
		||||
TEST(Photo_InpaintBorders, regression)
 | 
			
		||||
{
 | 
			
		||||
    Mat img(64, 64, CV_8U);
 | 
			
		||||
    img = 128;
 | 
			
		||||
    img(Rect(0, 0, 16, 64)) = 0;
 | 
			
		||||
 | 
			
		||||
    Mat mask(64, 64, CV_8U);
 | 
			
		||||
    mask = 0;
 | 
			
		||||
    mask(Rect(0, 0, 16, 64)) = 255;
 | 
			
		||||
 | 
			
		||||
    Mat inpainted;
 | 
			
		||||
    inpaint(img, mask, inpainted, 1, INPAINT_TELEA);
 | 
			
		||||
 | 
			
		||||
    Mat diff;
 | 
			
		||||
    cv::absdiff(inpainted, 128*Mat::ones(inpainted.size(), inpainted.type()), diff);
 | 
			
		||||
    ASSERT_TRUE(countNonZero(diff) == 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}} // namespace
 | 
			
		||||
							
								
								
									
										10
									
								
								3rdparty/opencv-4.5.4/modules/photo/test/test_main.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								3rdparty/opencv-4.5.4/modules/photo/test/test_main.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,10 @@
 | 
			
		||||
// 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"
 | 
			
		||||
 | 
			
		||||
#if defined(HAVE_HPX)
 | 
			
		||||
    #include <hpx/hpx_main.hpp>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
CV_TEST_MAIN("cv")
 | 
			
		||||
							
								
								
									
										140
									
								
								3rdparty/opencv-4.5.4/modules/photo/test/test_npr.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										140
									
								
								3rdparty/opencv-4.5.4/modules/photo/test/test_npr.cpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,140 @@
 | 
			
		||||
/*M///////////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
//
 | 
			
		||||
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
 | 
			
		||||
//
 | 
			
		||||
//  By downloading, copying, installing or using the software you agree to this license.
 | 
			
		||||
//  If you do not agree to this license, do not download, install,
 | 
			
		||||
//  copy or use the software.
 | 
			
		||||
//
 | 
			
		||||
//
 | 
			
		||||
//                           License Agreement
 | 
			
		||||
//                For Open Source Computer Vision Library
 | 
			
		||||
//
 | 
			
		||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
 | 
			
		||||
// Third party copyrights are property of their respective owners.
 | 
			
		||||
//
 | 
			
		||||
// Redistribution and use in source and binary forms, with or without modification,
 | 
			
		||||
// are permitted provided that the following conditions are met:
 | 
			
		||||
//
 | 
			
		||||
//   * Redistribution's of source code must retain the above copyright notice,
 | 
			
		||||
//     this list of conditions and the following disclaimer.
 | 
			
		||||
//
 | 
			
		||||
//   * Redistribution's in binary form must reproduce the above copyright notice,
 | 
			
		||||
//     this list of conditions and the following disclaimer in the documentation
 | 
			
		||||
//     and/or other materials provided with the distribution.
 | 
			
		||||
//
 | 
			
		||||
//   * The name of the copyright holders may not be used to endorse or promote products
 | 
			
		||||
//     derived from this software without specific prior written permission.
 | 
			
		||||
//
 | 
			
		||||
// This software is provided by the copyright holders and contributors "as is" and
 | 
			
		||||
// any express or implied warranties, including, but not limited to, the implied
 | 
			
		||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
 | 
			
		||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
 | 
			
		||||
// indirect, incidental, special, exemplary, or consequential damages
 | 
			
		||||
// (including, but not limited to, procurement of substitute goods or services;
 | 
			
		||||
// loss of use, data, or profits; or business interruption) however caused
 | 
			
		||||
// and on any theory of liability, whether in contract, strict liability,
 | 
			
		||||
// or tort (including negligence or otherwise) arising in any way out of
 | 
			
		||||
// the use of this software, even if advised of the possibility of such damage.
 | 
			
		||||
//
 | 
			
		||||
//M*/
 | 
			
		||||
 | 
			
		||||
#include "test_precomp.hpp"
 | 
			
		||||
 | 
			
		||||
namespace opencv_test { namespace {
 | 
			
		||||
 | 
			
		||||
static const double numerical_precision = 100.;
 | 
			
		||||
 | 
			
		||||
TEST(Photo_NPR_EdgePreserveSmoothing_RecursiveFilter, regression)
 | 
			
		||||
{
 | 
			
		||||
    string folder = string(cvtest::TS::ptr()->get_data_path()) + "npr/";
 | 
			
		||||
    string original_path = folder + "test1.png";
 | 
			
		||||
 | 
			
		||||
    Mat source = imread(original_path, IMREAD_COLOR);
 | 
			
		||||
 | 
			
		||||
    ASSERT_FALSE(source.empty()) << "Could not load input image " << original_path;
 | 
			
		||||
 | 
			
		||||
    Mat result;
 | 
			
		||||
    edgePreservingFilter(source,result,1);
 | 
			
		||||
 | 
			
		||||
    Mat reference = imread(folder + "smoothened_RF_reference.png");
 | 
			
		||||
 | 
			
		||||
    double psnr = cvtest::PSNR(reference, result);
 | 
			
		||||
    EXPECT_GT(psnr, 60.0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(Photo_NPR_EdgePreserveSmoothing_NormConvFilter, regression)
 | 
			
		||||
{
 | 
			
		||||
    string folder = string(cvtest::TS::ptr()->get_data_path()) + "npr/";
 | 
			
		||||
    string original_path = folder + "test1.png";
 | 
			
		||||
 | 
			
		||||
    Mat source = imread(original_path, IMREAD_COLOR);
 | 
			
		||||
 | 
			
		||||
    ASSERT_FALSE(source.empty()) << "Could not load input image " << original_path;
 | 
			
		||||
 | 
			
		||||
    Mat result;
 | 
			
		||||
    edgePreservingFilter(source,result,2);
 | 
			
		||||
 | 
			
		||||
    Mat reference = imread(folder + "smoothened_NCF_reference.png");
 | 
			
		||||
 | 
			
		||||
    double psnr = cvtest::PSNR(reference, result);
 | 
			
		||||
    EXPECT_GT(psnr, 60.0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(Photo_NPR_DetailEnhance, regression)
 | 
			
		||||
{
 | 
			
		||||
    string folder = string(cvtest::TS::ptr()->get_data_path()) + "npr/";
 | 
			
		||||
    string original_path = folder + "test1.png";
 | 
			
		||||
 | 
			
		||||
    Mat source = imread(original_path, IMREAD_COLOR);
 | 
			
		||||
 | 
			
		||||
    ASSERT_FALSE(source.empty()) << "Could not load input image " << original_path;
 | 
			
		||||
 | 
			
		||||
    Mat result;
 | 
			
		||||
    detailEnhance(source,result);
 | 
			
		||||
 | 
			
		||||
    Mat reference = imread(folder + "detail_enhanced_reference.png");
 | 
			
		||||
    double psnr = cvtest::PSNR(reference, result);
 | 
			
		||||
    EXPECT_GT(psnr, 60.0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(Photo_NPR_PencilSketch, regression)
 | 
			
		||||
{
 | 
			
		||||
    string folder = string(cvtest::TS::ptr()->get_data_path()) + "npr/";
 | 
			
		||||
    string original_path = folder + "test1.png";
 | 
			
		||||
 | 
			
		||||
    Mat source = imread(original_path, IMREAD_COLOR);
 | 
			
		||||
 | 
			
		||||
    ASSERT_FALSE(source.empty()) << "Could not load input image " << original_path;
 | 
			
		||||
 | 
			
		||||
    Mat pencil_result, color_pencil_result;
 | 
			
		||||
    pencilSketch(source,pencil_result, color_pencil_result, 10, 0.1f, 0.03f);
 | 
			
		||||
 | 
			
		||||
    Mat pencil_reference = imread(folder + "pencil_sketch_reference.png", 0 /* == grayscale*/);
 | 
			
		||||
    double pencil_error = cvtest::norm(pencil_reference, pencil_result, NORM_L1);
 | 
			
		||||
    EXPECT_LE(pencil_error, numerical_precision);
 | 
			
		||||
 | 
			
		||||
    Mat color_pencil_reference = imread(folder + "color_pencil_sketch_reference.png");
 | 
			
		||||
    double color_pencil_error = cvtest::norm(color_pencil_reference, color_pencil_result, NORM_L1);
 | 
			
		||||
    EXPECT_LE(color_pencil_error, numerical_precision);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST(Photo_NPR_Stylization, regression)
 | 
			
		||||
{
 | 
			
		||||
    string folder = string(cvtest::TS::ptr()->get_data_path()) + "npr/";
 | 
			
		||||
    string original_path = folder + "test1.png";
 | 
			
		||||
 | 
			
		||||
    Mat source = imread(original_path, IMREAD_COLOR);
 | 
			
		||||
 | 
			
		||||
    ASSERT_FALSE(source.empty()) << "Could not load input image " << original_path;
 | 
			
		||||
 | 
			
		||||
    Mat result;
 | 
			
		||||
    stylization(source,result);
 | 
			
		||||
 | 
			
		||||
    Mat stylized_reference = imread(folder + "stylized_reference.png");
 | 
			
		||||
    double stylized_error = cvtest::norm(stylized_reference, result, NORM_L1);
 | 
			
		||||
    EXPECT_LE(stylized_error, numerical_precision);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}} // namespace
 | 
			
		||||
							
								
								
									
										10
									
								
								3rdparty/opencv-4.5.4/modules/photo/test/test_precomp.hpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								3rdparty/opencv-4.5.4/modules/photo/test/test_precomp.hpp
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,10 @@
 | 
			
		||||
// 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 "opencv2/ts.hpp"
 | 
			
		||||
#include "opencv2/photo.hpp"
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
		Reference in New Issue
	
	Block a user