feat: 切换后端至PaddleOCR-NCNN,切换工程为CMake
1.项目后端整体迁移至PaddleOCR-NCNN算法,已通过基本的兼容性测试 2.工程改为使用CMake组织,后续为了更好地兼容第三方库,不再提供QMake工程 3.重整权利声明文件,重整代码工程,确保最小化侵权风险 Log: 切换后端至PaddleOCR-NCNN,切换工程为CMake Change-Id: I4d5d2c5d37505a4a24b389b1a4c5d12f17bfa38c
This commit is contained in:
239
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_accumulate.cpp
vendored
Normal file
239
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_accumulate.cpp
vendored
Normal file
@@ -0,0 +1,239 @@
|
||||
/*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) 2010-2012, Multicoreware, Inc., all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// @Authors
|
||||
// Nathan, liujun@multicorewareinc.com
|
||||
//
|
||||
// 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/ts/ocl_test.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
namespace opencv_test {
|
||||
namespace ocl {
|
||||
|
||||
PARAM_TEST_CASE(AccumulateBase, std::pair<MatDepth, MatDepth>, Channels, bool)
|
||||
{
|
||||
int sdepth, ddepth, channels;
|
||||
bool useRoi;
|
||||
double alpha;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src);
|
||||
TEST_DECLARE_INPUT_PARAMETER(mask);
|
||||
TEST_DECLARE_INPUT_PARAMETER(src2);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(dst);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
const std::pair<MatDepth, MatDepth> depths = GET_PARAM(0);
|
||||
sdepth = depths.first, ddepth = depths.second;
|
||||
channels = GET_PARAM(1);
|
||||
useRoi = GET_PARAM(2);
|
||||
}
|
||||
|
||||
void random_roi()
|
||||
{
|
||||
const int stype = CV_MAKE_TYPE(sdepth, channels),
|
||||
dtype = CV_MAKE_TYPE(ddepth, channels);
|
||||
|
||||
Size roiSize = randomSize(1, 10);
|
||||
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(src, src_roi, roiSize, srcBorder, stype, -MAX_VALUE, MAX_VALUE);
|
||||
|
||||
Border maskBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(mask, mask_roi, roiSize, maskBorder, CV_8UC1, -MAX_VALUE, MAX_VALUE);
|
||||
cvtest::threshold(mask, mask, 80, 255, THRESH_BINARY);
|
||||
|
||||
Border src2Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(src2, src2_roi, roiSize, src2Border, stype, -MAX_VALUE, MAX_VALUE);
|
||||
|
||||
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(dst, dst_roi, roiSize, dstBorder, dtype, -MAX_VALUE, MAX_VALUE);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(mask);
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src2);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
|
||||
alpha = randomDouble(-5, 5);
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////// Accumulate ///////////////////////////////////
|
||||
|
||||
typedef AccumulateBase Accumulate;
|
||||
|
||||
OCL_TEST_P(Accumulate, Mat)
|
||||
{
|
||||
for (int i = 0; i < test_loop_times; ++i)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::accumulate(src_roi, dst_roi));
|
||||
OCL_ON(cv::accumulate(usrc_roi, udst_roi));
|
||||
|
||||
OCL_EXPECT_MATS_NEAR(dst, 1e-6);
|
||||
}
|
||||
}
|
||||
|
||||
OCL_TEST_P(Accumulate, Mask)
|
||||
{
|
||||
for (int i = 0; i < test_loop_times; ++i)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::accumulate(src_roi, dst_roi, mask_roi));
|
||||
OCL_ON(cv::accumulate(usrc_roi, udst_roi, umask_roi));
|
||||
|
||||
OCL_EXPECT_MATS_NEAR(dst, 1e-6);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////// AccumulateSquare ///////////////////////////////////
|
||||
|
||||
typedef AccumulateBase AccumulateSquare;
|
||||
|
||||
OCL_TEST_P(AccumulateSquare, Mat)
|
||||
{
|
||||
for (int i = 0; i < test_loop_times; ++i)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::accumulateSquare(src_roi, dst_roi));
|
||||
OCL_ON(cv::accumulateSquare(usrc_roi, udst_roi));
|
||||
|
||||
OCL_EXPECT_MATS_NEAR(dst, 1e-2);
|
||||
}
|
||||
}
|
||||
|
||||
OCL_TEST_P(AccumulateSquare, Mask)
|
||||
{
|
||||
for (int i = 0; i < test_loop_times; ++i)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::accumulateSquare(src_roi, dst_roi, mask_roi));
|
||||
OCL_ON(cv::accumulateSquare(usrc_roi, udst_roi, umask_roi));
|
||||
|
||||
OCL_EXPECT_MATS_NEAR(dst, 1e-2);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////// AccumulateProduct ///////////////////////////////////
|
||||
|
||||
typedef AccumulateBase AccumulateProduct;
|
||||
|
||||
OCL_TEST_P(AccumulateProduct, Mat)
|
||||
{
|
||||
for (int i = 0; i < test_loop_times; ++i)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::accumulateProduct(src_roi, src2_roi, dst_roi));
|
||||
OCL_ON(cv::accumulateProduct(usrc_roi, usrc2_roi, udst_roi));
|
||||
|
||||
OCL_EXPECT_MATS_NEAR(dst, 1e-2);
|
||||
}
|
||||
}
|
||||
|
||||
OCL_TEST_P(AccumulateProduct, Mask)
|
||||
{
|
||||
for (int i = 0; i < test_loop_times; ++i)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::accumulateProduct(src_roi, src2_roi, dst_roi, mask_roi));
|
||||
OCL_ON(cv::accumulateProduct(usrc_roi, usrc2_roi, udst_roi, umask_roi));
|
||||
|
||||
OCL_EXPECT_MATS_NEAR(dst, 1e-2);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////// AccumulateWeighted ///////////////////////////////////
|
||||
|
||||
typedef AccumulateBase AccumulateWeighted;
|
||||
|
||||
OCL_TEST_P(AccumulateWeighted, Mat)
|
||||
{
|
||||
for (int i = 0; i < test_loop_times; ++i)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::accumulateWeighted(src_roi, dst_roi, alpha));
|
||||
OCL_ON(cv::accumulateWeighted(usrc_roi, udst_roi, alpha));
|
||||
|
||||
OCL_EXPECT_MATS_NEAR(dst, 1e-2);
|
||||
}
|
||||
}
|
||||
|
||||
OCL_TEST_P(AccumulateWeighted, Mask)
|
||||
{
|
||||
for (int i = 0; i < test_loop_times; ++i)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::accumulateWeighted(src_roi, dst_roi, alpha));
|
||||
OCL_ON(cv::accumulateWeighted(usrc_roi, udst_roi, alpha));
|
||||
|
||||
OCL_EXPECT_MATS_NEAR(dst, 1e-2);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////// Instantiation ///////////////////////////////////
|
||||
|
||||
#define OCL_DEPTH_ALL_COMBINATIONS \
|
||||
testing::Values(std::make_pair<MatDepth, MatDepth>(CV_8U, CV_32F), \
|
||||
std::make_pair<MatDepth, MatDepth>(CV_16U, CV_32F), \
|
||||
std::make_pair<MatDepth, MatDepth>(CV_32F, CV_32F), \
|
||||
std::make_pair<MatDepth, MatDepth>(CV_8U, CV_64F), \
|
||||
std::make_pair<MatDepth, MatDepth>(CV_16U, CV_64F), \
|
||||
std::make_pair<MatDepth, MatDepth>(CV_32F, CV_64F), \
|
||||
std::make_pair<MatDepth, MatDepth>(CV_64F, CV_64F))
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImgProc, Accumulate, Combine(OCL_DEPTH_ALL_COMBINATIONS, OCL_ALL_CHANNELS, Bool()));
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImgProc, AccumulateSquare, Combine(OCL_DEPTH_ALL_COMBINATIONS, OCL_ALL_CHANNELS, Bool()));
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImgProc, AccumulateProduct, Combine(OCL_DEPTH_ALL_COMBINATIONS, OCL_ALL_CHANNELS, Bool()));
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImgProc, AccumulateWeighted, Combine(OCL_DEPTH_ALL_COMBINATIONS, OCL_ALL_CHANNELS, Bool()));
|
||||
|
||||
} } // namespace opencv_test::ocl
|
||||
|
||||
#endif
|
||||
127
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_blend.cpp
vendored
Normal file
127
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_blend.cpp
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
/*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) 2010-2012, Multicoreware, Inc., all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// @Authors
|
||||
// Nathan, liujun@multicorewareinc.com
|
||||
//
|
||||
// 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/ts/ocl_test.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
namespace opencv_test {
|
||||
namespace ocl {
|
||||
|
||||
PARAM_TEST_CASE(BlendLinear, MatDepth, Channels, bool)
|
||||
{
|
||||
int depth, channels;
|
||||
bool useRoi;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src1);
|
||||
TEST_DECLARE_INPUT_PARAMETER(src2);
|
||||
TEST_DECLARE_INPUT_PARAMETER(weights2);
|
||||
TEST_DECLARE_INPUT_PARAMETER(weights1);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(dst);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
depth = GET_PARAM(0);
|
||||
channels = GET_PARAM(1);
|
||||
useRoi = GET_PARAM(2);
|
||||
}
|
||||
|
||||
void random_roi()
|
||||
{
|
||||
const int type = CV_MAKE_TYPE(depth, channels);
|
||||
const double upValue = 256;
|
||||
|
||||
Size roiSize = randomSize(1, MAX_VALUE);
|
||||
Border src1Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(src1, src1_roi, roiSize, src1Border, type, -upValue, upValue);
|
||||
|
||||
Border src2Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(src2, src2_roi, roiSize, src2Border, type, -upValue, upValue);
|
||||
|
||||
Border weights1Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(weights1, weights1_roi, roiSize, weights1Border, CV_32FC1, -upValue, upValue);
|
||||
|
||||
Border weights2Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(weights2, weights2_roi, roiSize, weights2Border, CV_32FC1, 1e-2, upValue);
|
||||
|
||||
weights2_roi -= weights1_roi;
|
||||
CV_Assert(checkNorm2(weights2_roi, weights2(Rect(weights2Border.lef, weights2Border.top,
|
||||
roiSize.width, roiSize.height))) < 1e-6);
|
||||
|
||||
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(dst, dst_roi, roiSize, dstBorder, type, 5, 16);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src1);
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src2);
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(weights1);
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(weights2);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
}
|
||||
|
||||
void Near(double eps = 0.0)
|
||||
{
|
||||
OCL_EXPECT_MATS_NEAR(dst, eps);
|
||||
}
|
||||
};
|
||||
|
||||
OCL_TEST_P(BlendLinear, Accuracy)
|
||||
{
|
||||
for (int i = 0; i < test_loop_times; ++i)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::blendLinear(src1_roi, src2_roi, weights1_roi, weights2_roi, dst_roi));
|
||||
OCL_ON(cv::blendLinear(usrc1_roi, usrc2_roi, uweights1_roi, uweights2_roi, udst_roi));
|
||||
|
||||
Near(depth <= CV_32S ? 1.0 : 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImgProc, BlendLinear, Combine(testing::Values(CV_8U, CV_32F), OCL_ALL_CHANNELS, Bool()));
|
||||
|
||||
} } // namespace opencv_test::ocl
|
||||
|
||||
#endif
|
||||
236
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_boxfilter.cpp
vendored
Normal file
236
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_boxfilter.cpp
vendored
Normal file
@@ -0,0 +1,236 @@
|
||||
/*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) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Copyright (C) 2010-2012, Multicoreware, 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/ts/ocl_test.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
namespace opencv_test {
|
||||
namespace ocl {
|
||||
|
||||
////////////////////////////////////////// boxFilter ///////////////////////////////////////////////////////
|
||||
|
||||
PARAM_TEST_CASE(BoxFilterBase, MatDepth, Channels, BorderType, bool, bool)
|
||||
{
|
||||
static const int kernelMinSize = 2;
|
||||
static const int kernelMaxSize = 10;
|
||||
|
||||
int depth, cn, borderType;
|
||||
Size ksize, dsize;
|
||||
Point anchor;
|
||||
bool normalize, useRoi;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(dst);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
depth = GET_PARAM(0);
|
||||
cn = GET_PARAM(1);
|
||||
borderType = GET_PARAM(2); // only not isolated border tested, because CPU module doesn't support isolated border case.
|
||||
normalize = GET_PARAM(3);
|
||||
useRoi = GET_PARAM(4);
|
||||
}
|
||||
|
||||
void random_roi()
|
||||
{
|
||||
int type = CV_MAKE_TYPE(depth, cn);
|
||||
ksize = randomSize(kernelMinSize, kernelMaxSize);
|
||||
|
||||
Size roiSize = randomSize(ksize.width, MAX_VALUE, ksize.height, MAX_VALUE);
|
||||
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(src, src_roi, roiSize, srcBorder, type, -MAX_VALUE, MAX_VALUE);
|
||||
|
||||
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(dst, dst_roi, roiSize, dstBorder, type, -MAX_VALUE, MAX_VALUE);
|
||||
|
||||
anchor.x = randomInt(-1, ksize.width);
|
||||
anchor.y = randomInt(-1, ksize.height);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
}
|
||||
|
||||
void Near(double threshold = 0.0)
|
||||
{
|
||||
OCL_EXPECT_MATS_NEAR(dst, threshold);
|
||||
}
|
||||
};
|
||||
|
||||
typedef BoxFilterBase BoxFilter;
|
||||
|
||||
OCL_TEST_P(BoxFilter, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::boxFilter(src_roi, dst_roi, -1, ksize, anchor, normalize, borderType));
|
||||
OCL_ON(cv::boxFilter(usrc_roi, udst_roi, -1, ksize, anchor, normalize, borderType));
|
||||
|
||||
Near(depth <= CV_32S ? 1 : 3e-3);
|
||||
}
|
||||
}
|
||||
|
||||
typedef BoxFilterBase SqrBoxFilter;
|
||||
|
||||
OCL_TEST_P(SqrBoxFilter, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
int ddepth = depth == CV_8U ? CV_32S : CV_64F;
|
||||
|
||||
OCL_OFF(cv::sqrBoxFilter(src_roi, dst_roi, ddepth, ksize, anchor, normalize, borderType));
|
||||
OCL_ON(cv::sqrBoxFilter(usrc_roi, udst_roi, ddepth, ksize, anchor, normalize, borderType));
|
||||
|
||||
Near(depth <= CV_32S ? 1 : 7e-2);
|
||||
}
|
||||
}
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImageProc, BoxFilter,
|
||||
Combine(
|
||||
Values(CV_8U, CV_16U, CV_16S, CV_32S, CV_32F),
|
||||
OCL_ALL_CHANNELS,
|
||||
Values((BorderType)BORDER_CONSTANT,
|
||||
(BorderType)BORDER_REPLICATE,
|
||||
(BorderType)BORDER_REFLECT,
|
||||
(BorderType)BORDER_REFLECT_101),
|
||||
Bool(),
|
||||
Bool() // ROI
|
||||
)
|
||||
);
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImageProc, SqrBoxFilter,
|
||||
Combine(
|
||||
Values(CV_8U, CV_16U, CV_16S, CV_32F, CV_64F),
|
||||
OCL_ALL_CHANNELS,
|
||||
Values((BorderType)BORDER_CONSTANT,
|
||||
(BorderType)BORDER_REPLICATE,
|
||||
(BorderType)BORDER_REFLECT,
|
||||
(BorderType)BORDER_REFLECT_101),
|
||||
Bool(),
|
||||
Bool() // ROI
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
PARAM_TEST_CASE(BoxFilter3x3_cols16_rows2_Base, MatDepth, Channels, BorderType, bool, bool)
|
||||
{
|
||||
int depth, cn, borderType;
|
||||
Size ksize, dsize;
|
||||
Point anchor;
|
||||
bool normalize, useRoi;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(dst);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
depth = GET_PARAM(0);
|
||||
cn = GET_PARAM(1);
|
||||
borderType = GET_PARAM(2); // only not isolated border tested, because CPU module doesn't support isolated border case.
|
||||
normalize = GET_PARAM(3);
|
||||
useRoi = GET_PARAM(4);
|
||||
}
|
||||
|
||||
void random_roi()
|
||||
{
|
||||
int type = CV_MAKE_TYPE(depth, cn);
|
||||
ksize = Size(3,3);
|
||||
|
||||
Size roiSize = randomSize(ksize.width, MAX_VALUE, ksize.height, MAX_VALUE);
|
||||
roiSize.width = std::max(ksize.width + 13, roiSize.width & (~0xf));
|
||||
roiSize.height = std::max(ksize.height + 1, roiSize.height & (~0x1));
|
||||
Border srcBorder = {0, 0, 0, 0};
|
||||
randomSubMat(src, src_roi, roiSize, srcBorder, type, -MAX_VALUE, MAX_VALUE);
|
||||
|
||||
Border dstBorder = {0, 0, 0, 0};
|
||||
randomSubMat(dst, dst_roi, roiSize, dstBorder, type, -MAX_VALUE, MAX_VALUE);
|
||||
|
||||
anchor.x = -1;
|
||||
anchor.y = -1;
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
}
|
||||
|
||||
void Near(double threshold = 0.0)
|
||||
{
|
||||
OCL_EXPECT_MATS_NEAR(dst, threshold);
|
||||
}
|
||||
};
|
||||
|
||||
typedef BoxFilter3x3_cols16_rows2_Base BoxFilter3x3_cols16_rows2;
|
||||
|
||||
OCL_TEST_P(BoxFilter3x3_cols16_rows2, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::boxFilter(src_roi, dst_roi, -1, ksize, anchor, normalize, borderType));
|
||||
OCL_ON(cv::boxFilter(usrc_roi, udst_roi, -1, ksize, anchor, normalize, borderType));
|
||||
|
||||
Near(depth <= CV_32S ? 1 : 3e-3);
|
||||
}
|
||||
}
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImageProc, BoxFilter3x3_cols16_rows2,
|
||||
Combine(
|
||||
Values((MatDepth)CV_8U),
|
||||
Values((Channels)1),
|
||||
Values((BorderType)BORDER_CONSTANT,
|
||||
(BorderType)BORDER_REPLICATE,
|
||||
(BorderType)BORDER_REFLECT,
|
||||
(BorderType)BORDER_REFLECT_101),
|
||||
Bool(),
|
||||
Values(false) // ROI
|
||||
)
|
||||
);
|
||||
|
||||
} } // namespace opencv_test::ocl
|
||||
|
||||
#endif // HAVE_OPENCL
|
||||
140
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_canny.cpp
vendored
Normal file
140
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_canny.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) 2010-2012, Multicoreware, Inc., all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// @Authors
|
||||
// Peng Xiao, pengxiao@multicorewareinc.com
|
||||
//
|
||||
// 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/ts/ocl_test.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
namespace opencv_test {
|
||||
namespace ocl {
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// Canny
|
||||
|
||||
IMPLEMENT_PARAM_CLASS(ApertureSize, int)
|
||||
IMPLEMENT_PARAM_CLASS(L2gradient, bool)
|
||||
IMPLEMENT_PARAM_CLASS(UseRoi, bool)
|
||||
|
||||
PARAM_TEST_CASE(Canny, Channels, ApertureSize, L2gradient, UseRoi)
|
||||
{
|
||||
int cn, aperture_size;
|
||||
bool useL2gradient, use_roi;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(dst);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
cn = GET_PARAM(0);
|
||||
aperture_size = GET_PARAM(1);
|
||||
useL2gradient = GET_PARAM(2);
|
||||
use_roi = GET_PARAM(3);
|
||||
}
|
||||
|
||||
void generateTestData()
|
||||
{
|
||||
Mat img = readImageType("shared/fruits.png", CV_8UC(cn));
|
||||
ASSERT_FALSE(img.empty()) << "can't load shared/fruits.png";
|
||||
|
||||
Size roiSize = img.size();
|
||||
int type = img.type();
|
||||
|
||||
Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
|
||||
randomSubMat(src, src_roi, roiSize, srcBorder, type, 2, 100);
|
||||
img.copyTo(src_roi);
|
||||
|
||||
Border dstBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
|
||||
randomSubMat(dst, dst_roi, roiSize, dstBorder, type, 5, 16);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
}
|
||||
};
|
||||
|
||||
OCL_TEST_P(Canny, Accuracy)
|
||||
{
|
||||
generateTestData();
|
||||
|
||||
const double low_thresh = 50.0, high_thresh = 100.0;
|
||||
double eps = 0.03;
|
||||
|
||||
OCL_OFF(cv::Canny(src_roi, dst_roi, low_thresh, high_thresh, aperture_size, useL2gradient));
|
||||
OCL_ON(cv::Canny(usrc_roi, udst_roi, low_thresh, high_thresh, aperture_size, useL2gradient));
|
||||
|
||||
EXPECT_MAT_SIMILAR(dst_roi, udst_roi, eps);
|
||||
EXPECT_MAT_SIMILAR(dst, udst, eps);
|
||||
}
|
||||
|
||||
OCL_TEST_P(Canny, AccuracyCustomGradient)
|
||||
{
|
||||
generateTestData();
|
||||
|
||||
const double low_thresh = 50.0, high_thresh = 100.0;
|
||||
double eps = 0.03;
|
||||
|
||||
OCL_OFF(cv::Canny(src_roi, dst_roi, low_thresh, high_thresh, aperture_size, useL2gradient));
|
||||
OCL_ON(
|
||||
UMat dx, dy;
|
||||
Sobel(usrc_roi, dx, CV_16S, 1, 0, aperture_size, 1, 0, BORDER_REPLICATE);
|
||||
Sobel(usrc_roi, dy, CV_16S, 0, 1, aperture_size, 1, 0, BORDER_REPLICATE);
|
||||
cv::Canny(dx, dy, udst_roi, low_thresh, high_thresh, useL2gradient);
|
||||
);
|
||||
|
||||
EXPECT_MAT_SIMILAR(dst_roi, udst_roi, eps);
|
||||
EXPECT_MAT_SIMILAR(dst, udst, eps);
|
||||
}
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImgProc, Canny, testing::Combine(
|
||||
testing::Values(1, 3),
|
||||
testing::Values(ApertureSize(3), ApertureSize(5)),
|
||||
testing::Values(L2gradient(false), L2gradient(true)),
|
||||
testing::Values(UseRoi(false), UseRoi(true))));
|
||||
|
||||
} // namespace ocl
|
||||
|
||||
} // namespace opencv_test
|
||||
|
||||
#endif // HAVE_OPENCL
|
||||
490
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_color.cpp
vendored
Normal file
490
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_color.cpp
vendored
Normal file
@@ -0,0 +1,490 @@
|
||||
/*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) 2010-2012, Multicoreware, Inc., all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// @Authors
|
||||
// Peng Xiao, pengxiao@multicorewareinc.com
|
||||
//
|
||||
// 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/ts/ocl_test.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
namespace opencv_test {
|
||||
namespace ocl {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// cvtColor
|
||||
|
||||
PARAM_TEST_CASE(CvtColor, MatDepth, bool)
|
||||
{
|
||||
int depth;
|
||||
bool use_roi;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(dst);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
depth = GET_PARAM(0);
|
||||
use_roi = GET_PARAM(1);
|
||||
}
|
||||
|
||||
virtual void generateTestData(int channelsIn, int channelsOut)
|
||||
{
|
||||
const int srcType = CV_MAKE_TYPE(depth, channelsIn);
|
||||
const int dstType = CV_MAKE_TYPE(depth, channelsOut);
|
||||
|
||||
Size roiSize = randomSize(1, MAX_VALUE);
|
||||
Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
|
||||
randomSubMat(src, src_roi, roiSize, srcBorder, srcType, 2, 100);
|
||||
|
||||
Border dstBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
|
||||
randomSubMat(dst, dst_roi, roiSize, dstBorder, dstType, 5, 16);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
}
|
||||
|
||||
void Near(double threshold)
|
||||
{
|
||||
OCL_EXPECT_MATS_NEAR(dst, threshold);
|
||||
}
|
||||
|
||||
void performTest(int channelsIn, int channelsOut, int code, double threshold = 1e-3)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
generateTestData(channelsIn, channelsOut);
|
||||
|
||||
OCL_OFF(cv::cvtColor(src_roi, dst_roi, code, channelsOut));
|
||||
OCL_ON(cv::cvtColor(usrc_roi, udst_roi, code, channelsOut));
|
||||
|
||||
int h_limit = 256;
|
||||
switch (code)
|
||||
{
|
||||
case COLOR_RGB2HLS: case COLOR_BGR2HLS:
|
||||
h_limit = 180;
|
||||
/* fallthrough */
|
||||
case COLOR_RGB2HLS_FULL: case COLOR_BGR2HLS_FULL:
|
||||
{
|
||||
ASSERT_EQ(dst_roi.type(), udst_roi.type());
|
||||
ASSERT_EQ(dst_roi.size(), udst_roi.size());
|
||||
Mat gold, actual;
|
||||
dst_roi.convertTo(gold, CV_32FC3);
|
||||
udst_roi.getMat(ACCESS_READ).convertTo(actual, CV_32FC3);
|
||||
Mat absdiff1, absdiff2, absdiff3;
|
||||
cv::absdiff(gold, actual, absdiff1);
|
||||
cv::absdiff(gold, actual + h_limit, absdiff2);
|
||||
cv::absdiff(gold, actual - h_limit, absdiff3);
|
||||
Mat diff = cv::min(cv::min(absdiff1, absdiff2), absdiff3);
|
||||
EXPECT_LE(cvtest::norm(diff, NORM_INF), threshold);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
Near(threshold);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#define CVTCODE(name) COLOR_ ## name
|
||||
|
||||
// RGB[A] <-> BGR[A]
|
||||
|
||||
OCL_TEST_P(CvtColor, BGR2BGRA) { performTest(3, 4, CVTCODE(BGR2BGRA)); }
|
||||
OCL_TEST_P(CvtColor, RGB2RGBA) { performTest(3, 4, CVTCODE(RGB2RGBA)); }
|
||||
OCL_TEST_P(CvtColor, BGRA2BGR) { performTest(4, 3, CVTCODE(BGRA2BGR)); }
|
||||
OCL_TEST_P(CvtColor, RGBA2RGB) { performTest(4, 3, CVTCODE(RGBA2RGB)); }
|
||||
OCL_TEST_P(CvtColor, BGR2RGBA) { performTest(3, 4, CVTCODE(BGR2RGBA)); }
|
||||
OCL_TEST_P(CvtColor, RGB2BGRA) { performTest(3, 4, CVTCODE(RGB2BGRA)); }
|
||||
OCL_TEST_P(CvtColor, RGBA2BGR) { performTest(4, 3, CVTCODE(RGBA2BGR)); }
|
||||
OCL_TEST_P(CvtColor, BGRA2RGB) { performTest(4, 3, CVTCODE(BGRA2RGB)); }
|
||||
OCL_TEST_P(CvtColor, BGR2RGB) { performTest(3, 3, CVTCODE(BGR2RGB)); }
|
||||
OCL_TEST_P(CvtColor, RGB2BGR) { performTest(3, 3, CVTCODE(RGB2BGR)); }
|
||||
OCL_TEST_P(CvtColor, BGRA2RGBA) { performTest(4, 4, CVTCODE(BGRA2RGBA)); }
|
||||
OCL_TEST_P(CvtColor, RGBA2BGRA) { performTest(4, 4, CVTCODE(RGBA2BGRA)); }
|
||||
|
||||
// RGB <-> Gray
|
||||
|
||||
OCL_TEST_P(CvtColor, RGB2GRAY) { performTest(3, 1, CVTCODE(RGB2GRAY)); }
|
||||
OCL_TEST_P(CvtColor, GRAY2RGB) { performTest(1, 3, CVTCODE(GRAY2RGB)); }
|
||||
OCL_TEST_P(CvtColor, BGR2GRAY) { performTest(3, 1, CVTCODE(BGR2GRAY)); }
|
||||
OCL_TEST_P(CvtColor, GRAY2BGR) { performTest(1, 3, CVTCODE(GRAY2BGR)); }
|
||||
OCL_TEST_P(CvtColor, RGBA2GRAY) { performTest(4, 1, CVTCODE(RGBA2GRAY)); }
|
||||
OCL_TEST_P(CvtColor, GRAY2RGBA) { performTest(1, 4, CVTCODE(GRAY2RGBA)); }
|
||||
OCL_TEST_P(CvtColor, BGRA2GRAY) { performTest(4, 1, CVTCODE(BGRA2GRAY), cv::ocl::Device::getDefault().isNVidia() ? 1 : 1e-3); }
|
||||
OCL_TEST_P(CvtColor, GRAY2BGRA) { performTest(1, 4, CVTCODE(GRAY2BGRA)); }
|
||||
|
||||
// RGB <-> YUV
|
||||
|
||||
OCL_TEST_P(CvtColor, RGB2YUV) { performTest(3, 3, CVTCODE(RGB2YUV)); }
|
||||
OCL_TEST_P(CvtColor, BGR2YUV) { performTest(3, 3, CVTCODE(BGR2YUV)); }
|
||||
OCL_TEST_P(CvtColor, RGBA2YUV) { performTest(4, 3, CVTCODE(RGB2YUV)); }
|
||||
OCL_TEST_P(CvtColor, BGRA2YUV) { performTest(4, 3, CVTCODE(BGR2YUV)); }
|
||||
OCL_TEST_P(CvtColor, YUV2RGB) { performTest(3, 3, CVTCODE(YUV2RGB)); }
|
||||
OCL_TEST_P(CvtColor, YUV2BGR) { performTest(3, 3, CVTCODE(YUV2BGR)); }
|
||||
OCL_TEST_P(CvtColor, YUV2RGBA) { performTest(3, 4, CVTCODE(YUV2RGB)); }
|
||||
OCL_TEST_P(CvtColor, YUV2BGRA) { performTest(3, 4, CVTCODE(YUV2BGR)); }
|
||||
|
||||
// RGB <-> YCrCb
|
||||
|
||||
#define EPS_FOR_FLOATING_POINT(e) (CV_32F <= depth ? e : 1)
|
||||
|
||||
OCL_TEST_P(CvtColor, RGB2YCrCb) { performTest(3, 3, CVTCODE(RGB2YCrCb), EPS_FOR_FLOATING_POINT(1e-3)); }
|
||||
OCL_TEST_P(CvtColor, BGR2YCrCb) { performTest(3, 3, CVTCODE(BGR2YCrCb), EPS_FOR_FLOATING_POINT(1e-3)); }
|
||||
OCL_TEST_P(CvtColor, RGBA2YCrCb) { performTest(4, 3, CVTCODE(RGB2YCrCb), EPS_FOR_FLOATING_POINT(1e-3)); }
|
||||
OCL_TEST_P(CvtColor, BGRA2YCrCb) { performTest(4, 3, CVTCODE(BGR2YCrCb), EPS_FOR_FLOATING_POINT(1e-3)); }
|
||||
OCL_TEST_P(CvtColor, YCrCb2RGB) { performTest(3, 3, CVTCODE(YCrCb2RGB)); }
|
||||
OCL_TEST_P(CvtColor, YCrCb2BGR) { performTest(3, 3, CVTCODE(YCrCb2BGR)); }
|
||||
OCL_TEST_P(CvtColor, YCrCb2RGBA) { performTest(3, 4, CVTCODE(YCrCb2RGB)); }
|
||||
OCL_TEST_P(CvtColor, YCrCb2BGRA) { performTest(3, 4, CVTCODE(YCrCb2BGR)); }
|
||||
|
||||
// RGB <-> XYZ
|
||||
|
||||
#ifdef HAVE_IPP
|
||||
#define IPP_EPS depth <= CV_32S ? 1 : 5e-5
|
||||
#else
|
||||
#define IPP_EPS 1e-3
|
||||
#endif
|
||||
|
||||
OCL_TEST_P(CvtColor, RGB2XYZ) { performTest(3, 3, CVTCODE(RGB2XYZ), IPP_EPS); }
|
||||
OCL_TEST_P(CvtColor, BGR2XYZ) { performTest(3, 3, CVTCODE(BGR2XYZ), IPP_EPS); }
|
||||
OCL_TEST_P(CvtColor, RGBA2XYZ) { performTest(4, 3, CVTCODE(RGB2XYZ), IPP_EPS); }
|
||||
OCL_TEST_P(CvtColor, BGRA2XYZ) { performTest(4, 3, CVTCODE(BGR2XYZ), IPP_EPS); }
|
||||
|
||||
OCL_TEST_P(CvtColor, XYZ2RGB) { performTest(3, 3, CVTCODE(XYZ2RGB), IPP_EPS); }
|
||||
OCL_TEST_P(CvtColor, XYZ2BGR) { performTest(3, 3, CVTCODE(XYZ2BGR), IPP_EPS); }
|
||||
OCL_TEST_P(CvtColor, XYZ2RGBA) { performTest(3, 4, CVTCODE(XYZ2RGB), IPP_EPS); }
|
||||
OCL_TEST_P(CvtColor, XYZ2BGRA) { performTest(3, 4, CVTCODE(XYZ2BGR), IPP_EPS); }
|
||||
|
||||
#undef IPP_EPS
|
||||
|
||||
// RGB <-> HSV
|
||||
|
||||
#ifdef HAVE_IPP
|
||||
#define IPP_EPS depth <= CV_32S ? 1 : 4e-5
|
||||
#else
|
||||
#define IPP_EPS EPS_FOR_FLOATING_POINT(1e-3)
|
||||
#endif
|
||||
|
||||
typedef CvtColor CvtColor8u32f;
|
||||
|
||||
OCL_TEST_P(CvtColor8u32f, RGB2HSV) { performTest(3, 3, CVTCODE(RGB2HSV), IPP_EPS); }
|
||||
OCL_TEST_P(CvtColor8u32f, BGR2HSV) { performTest(3, 3, CVTCODE(BGR2HSV), IPP_EPS); }
|
||||
OCL_TEST_P(CvtColor8u32f, RGBA2HSV) { performTest(4, 3, CVTCODE(RGB2HSV), IPP_EPS); }
|
||||
OCL_TEST_P(CvtColor8u32f, BGRA2HSV) { performTest(4, 3, CVTCODE(BGR2HSV), IPP_EPS); }
|
||||
|
||||
OCL_TEST_P(CvtColor8u32f, RGB2HSV_FULL) { performTest(3, 3, CVTCODE(RGB2HSV_FULL), IPP_EPS); }
|
||||
OCL_TEST_P(CvtColor8u32f, BGR2HSV_FULL) { performTest(3, 3, CVTCODE(BGR2HSV_FULL), IPP_EPS); }
|
||||
OCL_TEST_P(CvtColor8u32f, RGBA2HSV_FULL) { performTest(4, 3, CVTCODE(RGB2HSV_FULL), IPP_EPS); }
|
||||
OCL_TEST_P(CvtColor8u32f, BGRA2HSV_FULL) { performTest(4, 3, CVTCODE(BGR2HSV_FULL), IPP_EPS); }
|
||||
|
||||
#undef IPP_EPS
|
||||
|
||||
OCL_TEST_P(CvtColor8u32f, HSV2RGB) { performTest(3, 3, CVTCODE(HSV2RGB), depth == CV_8U ? 1 : 4e-1); }
|
||||
OCL_TEST_P(CvtColor8u32f, HSV2BGR) { performTest(3, 3, CVTCODE(HSV2BGR), depth == CV_8U ? 1 : 4e-1); }
|
||||
OCL_TEST_P(CvtColor8u32f, HSV2RGBA) { performTest(3, 4, CVTCODE(HSV2RGB), depth == CV_8U ? 1 : 4e-1); }
|
||||
OCL_TEST_P(CvtColor8u32f, HSV2BGRA) { performTest(3, 4, CVTCODE(HSV2BGR), depth == CV_8U ? 1 : 4e-1); }
|
||||
|
||||
OCL_TEST_P(CvtColor8u32f, HSV2RGB_FULL) { performTest(3, 3, CVTCODE(HSV2RGB_FULL), depth == CV_8U ? 1 : 4e-1); }
|
||||
OCL_TEST_P(CvtColor8u32f, HSV2BGR_FULL) { performTest(3, 3, CVTCODE(HSV2BGR_FULL), depth == CV_8U ? 1 : 4e-1); }
|
||||
OCL_TEST_P(CvtColor8u32f, HSV2RGBA_FULL) { performTest(3, 4, CVTCODE(HSV2BGR_FULL), depth == CV_8U ? 1 : 4e-1); }
|
||||
OCL_TEST_P(CvtColor8u32f, HSV2BGRA_FULL) { performTest(3, 4, CVTCODE(HSV2BGR_FULL), depth == CV_8U ? 1 : 4e-1); }
|
||||
|
||||
// RGB <-> HLS
|
||||
|
||||
#ifdef HAVE_IPP
|
||||
#define IPP_EPS depth == CV_8U ? 2 : 1e-3
|
||||
#else
|
||||
#define IPP_EPS depth == CV_8U ? 1 : 1e-3
|
||||
#endif
|
||||
|
||||
OCL_TEST_P(CvtColor8u32f, RGB2HLS) { performTest(3, 3, CVTCODE(RGB2HLS), depth == CV_8U ? 1 : 1e-3); }
|
||||
OCL_TEST_P(CvtColor8u32f, BGR2HLS) { performTest(3, 3, CVTCODE(BGR2HLS), depth == CV_8U ? 1 : 1e-3); }
|
||||
OCL_TEST_P(CvtColor8u32f, RGBA2HLS) { performTest(4, 3, CVTCODE(RGB2HLS), depth == CV_8U ? 1 : 1e-3); }
|
||||
OCL_TEST_P(CvtColor8u32f, BGRA2HLS) { performTest(4, 3, CVTCODE(BGR2HLS), depth == CV_8U ? 1 : 1e-3); }
|
||||
|
||||
OCL_TEST_P(CvtColor8u32f, RGB2HLS_FULL) { performTest(3, 3, CVTCODE(RGB2HLS_FULL), IPP_EPS); }
|
||||
OCL_TEST_P(CvtColor8u32f, BGR2HLS_FULL) { performTest(3, 3, CVTCODE(BGR2HLS_FULL), IPP_EPS); }
|
||||
OCL_TEST_P(CvtColor8u32f, RGBA2HLS_FULL) { performTest(4, 3, CVTCODE(RGB2HLS_FULL), IPP_EPS); }
|
||||
OCL_TEST_P(CvtColor8u32f, BGRA2HLS_FULL) { performTest(4, 3, CVTCODE(BGR2HLS_FULL), IPP_EPS); }
|
||||
|
||||
OCL_TEST_P(CvtColor8u32f, HLS2RGB) { performTest(3, 3, CVTCODE(HLS2RGB), 1); }
|
||||
OCL_TEST_P(CvtColor8u32f, HLS2BGR) { performTest(3, 3, CVTCODE(HLS2BGR), 1); }
|
||||
OCL_TEST_P(CvtColor8u32f, HLS2RGBA) { performTest(3, 4, CVTCODE(HLS2RGB), 1); }
|
||||
OCL_TEST_P(CvtColor8u32f, HLS2BGRA) { performTest(3, 4, CVTCODE(HLS2BGR), 1); }
|
||||
|
||||
OCL_TEST_P(CvtColor8u32f, HLS2RGB_FULL) { performTest(3, 3, CVTCODE(HLS2RGB_FULL), 1); }
|
||||
OCL_TEST_P(CvtColor8u32f, HLS2BGR_FULL) { performTest(3, 3, CVTCODE(HLS2BGR_FULL), 1); }
|
||||
OCL_TEST_P(CvtColor8u32f, HLS2RGBA_FULL) { performTest(3, 4, CVTCODE(HLS2RGB_FULL), 1); }
|
||||
OCL_TEST_P(CvtColor8u32f, HLS2BGRA_FULL) { performTest(3, 4, CVTCODE(HLS2BGR_FULL), 1); }
|
||||
|
||||
#undef IPP_EPS
|
||||
|
||||
// RGB5x5 <-> RGB
|
||||
|
||||
typedef CvtColor CvtColor8u;
|
||||
|
||||
OCL_TEST_P(CvtColor8u, BGR5652BGR) { performTest(2, 3, CVTCODE(BGR5652BGR)); }
|
||||
OCL_TEST_P(CvtColor8u, BGR5652RGB) { performTest(2, 3, CVTCODE(BGR5652RGB)); }
|
||||
OCL_TEST_P(CvtColor8u, BGR5652BGRA) { performTest(2, 4, CVTCODE(BGR5652BGRA)); }
|
||||
OCL_TEST_P(CvtColor8u, BGR5652RGBA) { performTest(2, 4, CVTCODE(BGR5652RGBA)); }
|
||||
|
||||
OCL_TEST_P(CvtColor8u, BGR5552BGR) { performTest(2, 3, CVTCODE(BGR5552BGR)); }
|
||||
OCL_TEST_P(CvtColor8u, BGR5552RGB) { performTest(2, 3, CVTCODE(BGR5552RGB)); }
|
||||
OCL_TEST_P(CvtColor8u, BGR5552BGRA) { performTest(2, 4, CVTCODE(BGR5552BGRA)); }
|
||||
OCL_TEST_P(CvtColor8u, BGR5552RGBA) { performTest(2, 4, CVTCODE(BGR5552RGBA)); }
|
||||
|
||||
OCL_TEST_P(CvtColor8u, BGR2BGR565) { performTest(3, 2, CVTCODE(BGR2BGR565)); }
|
||||
OCL_TEST_P(CvtColor8u, RGB2BGR565) { performTest(3, 2, CVTCODE(RGB2BGR565)); }
|
||||
OCL_TEST_P(CvtColor8u, BGRA2BGR565) { performTest(4, 2, CVTCODE(BGRA2BGR565)); }
|
||||
OCL_TEST_P(CvtColor8u, RGBA2BGR565) { performTest(4, 2, CVTCODE(RGBA2BGR565)); }
|
||||
|
||||
OCL_TEST_P(CvtColor8u, BGR2BGR555) { performTest(3, 2, CVTCODE(BGR2BGR555)); }
|
||||
OCL_TEST_P(CvtColor8u, RGB2BGR555) { performTest(3, 2, CVTCODE(RGB2BGR555)); }
|
||||
OCL_TEST_P(CvtColor8u, BGRA2BGR555) { performTest(4, 2, CVTCODE(BGRA2BGR555)); }
|
||||
OCL_TEST_P(CvtColor8u, RGBA2BGR555) { performTest(4, 2, CVTCODE(RGBA2BGR555)); }
|
||||
|
||||
// RGB5x5 <-> Gray
|
||||
|
||||
OCL_TEST_P(CvtColor8u, BGR5652GRAY) { performTest(2, 1, CVTCODE(BGR5652GRAY)); }
|
||||
OCL_TEST_P(CvtColor8u, BGR5552GRAY) { performTest(2, 1, CVTCODE(BGR5552GRAY)); }
|
||||
|
||||
OCL_TEST_P(CvtColor8u, GRAY2BGR565) { performTest(1, 2, CVTCODE(GRAY2BGR565)); }
|
||||
OCL_TEST_P(CvtColor8u, GRAY2BGR555) { performTest(1, 2, CVTCODE(GRAY2BGR555)); }
|
||||
|
||||
// RGBA <-> mRGBA
|
||||
|
||||
#if defined(HAVE_IPP) || defined(__arm__)
|
||||
#define IPP_EPS depth <= CV_32S ? 1 : 1e-3
|
||||
#else
|
||||
#define IPP_EPS 1e-3
|
||||
#endif
|
||||
|
||||
OCL_TEST_P(CvtColor8u, RGBA2mRGBA) { performTest(4, 4, CVTCODE(RGBA2mRGBA), IPP_EPS); }
|
||||
OCL_TEST_P(CvtColor8u, mRGBA2RGBA) { performTest(4, 4, CVTCODE(mRGBA2RGBA), IPP_EPS); }
|
||||
|
||||
// RGB <-> Lab
|
||||
|
||||
OCL_TEST_P(CvtColor8u32f, BGR2Lab) { performTest(3, 3, CVTCODE(BGR2Lab)); }
|
||||
OCL_TEST_P(CvtColor8u32f, RGB2Lab) { performTest(3, 3, CVTCODE(RGB2Lab)); }
|
||||
OCL_TEST_P(CvtColor8u32f, LBGR2Lab) { performTest(3, 3, CVTCODE(LBGR2Lab), IPP_EPS); }
|
||||
OCL_TEST_P(CvtColor8u32f, LRGB2Lab) { performTest(3, 3, CVTCODE(LRGB2Lab), IPP_EPS); }
|
||||
OCL_TEST_P(CvtColor8u32f, BGRA2Lab) { performTest(4, 3, CVTCODE(BGR2Lab)); }
|
||||
OCL_TEST_P(CvtColor8u32f, RGBA2Lab) { performTest(4, 3, CVTCODE(RGB2Lab)); }
|
||||
OCL_TEST_P(CvtColor8u32f, LBGRA2Lab) { performTest(4, 3, CVTCODE(LBGR2Lab), IPP_EPS); }
|
||||
OCL_TEST_P(CvtColor8u32f, LRGBA2Lab) { performTest(4, 3, CVTCODE(LRGB2Lab), IPP_EPS); }
|
||||
|
||||
#undef IPP_EPS
|
||||
|
||||
OCL_TEST_P(CvtColor8u32f, Lab2BGR) { performTest(3, 3, CVTCODE(Lab2BGR), depth == CV_8U ? 1 : 1e-5); }
|
||||
OCL_TEST_P(CvtColor8u32f, Lab2RGB) { performTest(3, 3, CVTCODE(Lab2RGB), depth == CV_8U ? 1 : 1e-5); }
|
||||
OCL_TEST_P(CvtColor8u32f, Lab2LBGR) { performTest(3, 3, CVTCODE(Lab2LBGR), depth == CV_8U ? 1 : 1e-5); }
|
||||
OCL_TEST_P(CvtColor8u32f, Lab2LRGB) { performTest(3, 3, CVTCODE(Lab2LRGB), depth == CV_8U ? 1 : 1e-5); }
|
||||
OCL_TEST_P(CvtColor8u32f, Lab2BGRA) { performTest(3, 4, CVTCODE(Lab2BGR), depth == CV_8U ? 1 : 1e-5); }
|
||||
OCL_TEST_P(CvtColor8u32f, Lab2RGBA) { performTest(3, 4, CVTCODE(Lab2RGB), depth == CV_8U ? 1 : 1e-5); }
|
||||
OCL_TEST_P(CvtColor8u32f, Lab2LBGRA) { performTest(3, 4, CVTCODE(Lab2LBGR), depth == CV_8U ? 1 : 1e-5); }
|
||||
OCL_TEST_P(CvtColor8u32f, Lab2LRGBA) { performTest(3, 4, CVTCODE(Lab2LRGB), depth == CV_8U ? 1 : 1e-5); }
|
||||
|
||||
// RGB -> Luv
|
||||
|
||||
OCL_TEST_P(CvtColor8u32f, BGR2Luv) { performTest(3, 3, CVTCODE(BGR2Luv), depth == CV_8U ? 1 : 1.5e-2); }
|
||||
OCL_TEST_P(CvtColor8u32f, RGB2Luv) { performTest(3, 3, CVTCODE(RGB2Luv), depth == CV_8U ? 1 : 1.5e-2); }
|
||||
OCL_TEST_P(CvtColor8u32f, LBGR2Luv) { performTest(3, 3, CVTCODE(LBGR2Luv), depth == CV_8U ? 1 : 6e-3); }
|
||||
OCL_TEST_P(CvtColor8u32f, LRGB2Luv) { performTest(3, 3, CVTCODE(LRGB2Luv), depth == CV_8U ? 1 : 6e-3); }
|
||||
OCL_TEST_P(CvtColor8u32f, BGRA2Luv) { performTest(4, 3, CVTCODE(BGR2Luv), depth == CV_8U ? 1 : 2e-2); }
|
||||
OCL_TEST_P(CvtColor8u32f, RGBA2Luv) { performTest(4, 3, CVTCODE(RGB2Luv), depth == CV_8U ? 1 : 2e-2); }
|
||||
OCL_TEST_P(CvtColor8u32f, LBGRA2Luv) { performTest(4, 3, CVTCODE(LBGR2Luv), depth == CV_8U ? 1 : 6e-3); }
|
||||
OCL_TEST_P(CvtColor8u32f, LRGBA2Luv) { performTest(4, 3, CVTCODE(LRGB2Luv), depth == CV_8U ? 1 : 6e-3); }
|
||||
|
||||
OCL_TEST_P(CvtColor8u32f, Luv2BGR) { performTest(3, 3, CVTCODE(Luv2BGR), depth == CV_8U ? 1 : 7e-5); }
|
||||
OCL_TEST_P(CvtColor8u32f, Luv2RGB) { performTest(3, 3, CVTCODE(Luv2RGB), depth == CV_8U ? 1 : 7e-5); }
|
||||
OCL_TEST_P(CvtColor8u32f, Luv2LBGR) { performTest(3, 3, CVTCODE(Luv2LBGR), depth == CV_8U ? 1 : 1e-5); }
|
||||
OCL_TEST_P(CvtColor8u32f, Luv2LRGB) { performTest(3, 3, CVTCODE(Luv2LRGB), depth == CV_8U ? 1 : 1e-5); }
|
||||
OCL_TEST_P(CvtColor8u32f, Luv2BGRA) { performTest(3, 4, CVTCODE(Luv2BGR), depth == CV_8U ? 1 : 7e-5); }
|
||||
OCL_TEST_P(CvtColor8u32f, Luv2RGBA) { performTest(3, 4, CVTCODE(Luv2RGB), depth == CV_8U ? 1 : 7e-5); }
|
||||
OCL_TEST_P(CvtColor8u32f, Luv2LBGRA) { performTest(3, 4, CVTCODE(Luv2LBGR), depth == CV_8U ? 1 : 1e-5); }
|
||||
OCL_TEST_P(CvtColor8u32f, Luv2LRGBA) { performTest(3, 4, CVTCODE(Luv2LRGB), depth == CV_8U ? 1 : 1e-5); }
|
||||
|
||||
// YUV420 -> RGBA
|
||||
|
||||
struct CvtColor_YUV2RGB_420 :
|
||||
public CvtColor
|
||||
{
|
||||
void generateTestData(int channelsIn, int channelsOut)
|
||||
{
|
||||
const int srcType = CV_MAKE_TYPE(depth, channelsIn);
|
||||
const int dstType = CV_MAKE_TYPE(depth, channelsOut);
|
||||
|
||||
Size roiSize = randomSize(1, MAX_VALUE);
|
||||
roiSize.width *= 2;
|
||||
roiSize.height *= 3;
|
||||
Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
|
||||
randomSubMat(src, src_roi, roiSize, srcBorder, srcType, 2, 100);
|
||||
|
||||
Border dstBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
|
||||
randomSubMat(dst, dst_roi, roiSize, dstBorder, dstType, 5, 16);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
}
|
||||
};
|
||||
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_420, YUV2RGBA_NV12) { performTest(1, 4, CVTCODE(YUV2RGBA_NV12), EPS_FOR_FLOATING_POINT(1e-3)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_420, YUV2BGRA_NV12) { performTest(1, 4, CVTCODE(YUV2BGRA_NV12), EPS_FOR_FLOATING_POINT(1e-3)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_420, YUV2RGB_NV12) { performTest(1, 3, CVTCODE(YUV2RGB_NV12), EPS_FOR_FLOATING_POINT(1e-3)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_420, YUV2BGR_NV12) { performTest(1, 3, CVTCODE(YUV2BGR_NV12), EPS_FOR_FLOATING_POINT(1e-3)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_420, YUV2RGBA_NV21) { performTest(1, 4, CVTCODE(YUV2RGBA_NV21), EPS_FOR_FLOATING_POINT(1e-3)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_420, YUV2BGRA_NV21) { performTest(1, 4, CVTCODE(YUV2BGRA_NV21), EPS_FOR_FLOATING_POINT(1e-3)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_420, YUV2RGB_NV21) { performTest(1, 3, CVTCODE(YUV2RGB_NV21), EPS_FOR_FLOATING_POINT(1e-3)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_420, YUV2BGR_NV21) { performTest(1, 3, CVTCODE(YUV2BGR_NV21), EPS_FOR_FLOATING_POINT(1e-3)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_420, YUV2RGBA_YV12) { performTest(1, 4, CVTCODE(YUV2RGBA_YV12)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_420, YUV2BGRA_YV12) { performTest(1, 4, CVTCODE(YUV2BGRA_YV12)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_420, YUV2RGB_YV12) { performTest(1, 3, CVTCODE(YUV2RGB_YV12)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_420, YUV2BGR_YV12) { performTest(1, 3, CVTCODE(YUV2BGR_YV12)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_420, YUV2RGBA_IYUV) { performTest(1, 4, CVTCODE(YUV2RGBA_IYUV)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_420, YUV2BGRA_IYUV) { performTest(1, 4, CVTCODE(YUV2BGRA_IYUV)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_420, YUV2RGB_IYUV) { performTest(1, 3, CVTCODE(YUV2RGB_IYUV)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_420, YUV2BGR_IYUV) { performTest(1, 3, CVTCODE(YUV2BGR_IYUV)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_420, YUV2GRAY_420) { performTest(1, 1, CVTCODE(YUV2GRAY_420)); }
|
||||
|
||||
// RGBA -> YUV420
|
||||
|
||||
struct CvtColor_RGB2YUV_420 :
|
||||
public CvtColor
|
||||
{
|
||||
void generateTestData(int channelsIn, int channelsOut)
|
||||
{
|
||||
const int srcType = CV_MAKE_TYPE(depth, channelsIn);
|
||||
const int dstType = CV_MAKE_TYPE(depth, channelsOut);
|
||||
|
||||
Size srcRoiSize = randomSize(1, MAX_VALUE);
|
||||
srcRoiSize.width *= 2;
|
||||
srcRoiSize.height *= 2;
|
||||
Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
|
||||
randomSubMat(src, src_roi, srcRoiSize, srcBorder, srcType, 2, 100);
|
||||
|
||||
Size dstRoiSize(srcRoiSize.width, srcRoiSize.height / 2 * 3);
|
||||
Border dstBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
|
||||
randomSubMat(dst, dst_roi, dstRoiSize, dstBorder, dstType, 5, 16);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
}
|
||||
};
|
||||
|
||||
OCL_TEST_P(CvtColor_RGB2YUV_420, RGBA2YUV_YV12) { performTest(4, 1, CVTCODE(RGBA2YUV_YV12), 1); }
|
||||
OCL_TEST_P(CvtColor_RGB2YUV_420, BGRA2YUV_YV12) { performTest(4, 1, CVTCODE(BGRA2YUV_YV12), 1); }
|
||||
OCL_TEST_P(CvtColor_RGB2YUV_420, RGB2YUV_YV12) { performTest(3, 1, CVTCODE(RGB2YUV_YV12), 1); }
|
||||
OCL_TEST_P(CvtColor_RGB2YUV_420, BGR2YUV_YV12) { performTest(3, 1, CVTCODE(BGR2YUV_YV12), 1); }
|
||||
OCL_TEST_P(CvtColor_RGB2YUV_420, RGBA2YUV_IYUV) { performTest(4, 1, CVTCODE(RGBA2YUV_IYUV), 1); }
|
||||
OCL_TEST_P(CvtColor_RGB2YUV_420, BGRA2YUV_IYUV) { performTest(4, 1, CVTCODE(BGRA2YUV_IYUV), 1); }
|
||||
OCL_TEST_P(CvtColor_RGB2YUV_420, RGB2YUV_IYUV) { performTest(3, 1, CVTCODE(RGB2YUV_IYUV), 1); }
|
||||
OCL_TEST_P(CvtColor_RGB2YUV_420, BGR2YUV_IYUV) { performTest(3, 1, CVTCODE(BGR2YUV_IYUV), 1); }
|
||||
|
||||
// YUV422 -> RGBA
|
||||
|
||||
struct CvtColor_YUV2RGB_422 :
|
||||
public CvtColor
|
||||
{
|
||||
void generateTestData(int channelsIn, int channelsOut)
|
||||
{
|
||||
const int srcType = CV_MAKE_TYPE(depth, channelsIn);
|
||||
const int dstType = CV_MAKE_TYPE(depth, channelsOut);
|
||||
|
||||
Size roiSize = randomSize(1, MAX_VALUE);
|
||||
roiSize.width *= 2;
|
||||
|
||||
Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
|
||||
randomSubMat(src, src_roi, roiSize, srcBorder, srcType, 2, 100);
|
||||
|
||||
Border dstBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
|
||||
randomSubMat(dst, dst_roi, roiSize, dstBorder, dstType, 5, 16);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
}
|
||||
};
|
||||
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_422, YUV2RGB_UYVY) { performTest(2, 3, CVTCODE(YUV2RGB_UYVY)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_422, YUV2BGR_UYVY) { performTest(2, 3, CVTCODE(YUV2BGR_UYVY)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_422, YUV2RGBA_UYVY) { performTest(2, 4, CVTCODE(YUV2RGBA_UYVY)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_422, YUV2BGRA_UYVY) { performTest(2, 4, CVTCODE(YUV2BGRA_UYVY)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_422, YUV2RGB_YUY2) { performTest(2, 3, CVTCODE(YUV2RGB_YUY2)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_422, YUV2BGR_YUY2) { performTest(2, 3, CVTCODE(YUV2BGR_YUY2)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_422, YUV2RGBA_YUY2) { performTest(2, 4, CVTCODE(YUV2RGBA_YUY2)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_422, YUV2BGRA_YUY2) { performTest(2, 4, CVTCODE(YUV2BGRA_YUY2)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_422, YUV2RGB_YVYU) { performTest(2, 3, CVTCODE(YUV2RGB_YVYU)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_422, YUV2BGR_YVYU) { performTest(2, 3, CVTCODE(YUV2BGR_YVYU)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_422, YUV2RGBA_YVYU) { performTest(2, 4, CVTCODE(YUV2RGBA_YVYU)); }
|
||||
OCL_TEST_P(CvtColor_YUV2RGB_422, YUV2BGRA_YVYU) { performTest(2, 4, CVTCODE(YUV2BGRA_YVYU)); }
|
||||
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImgProc, CvtColor8u,
|
||||
testing::Combine(testing::Values(MatDepth(CV_8U)), Bool()));
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImgProc, CvtColor8u32f,
|
||||
testing::Combine(testing::Values(MatDepth(CV_8U), MatDepth(CV_32F)), Bool()));
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImgProc, CvtColor,
|
||||
testing::Combine(
|
||||
testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_32F)),
|
||||
Bool()));
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImgProc, CvtColor_YUV2RGB_420,
|
||||
testing::Combine(
|
||||
testing::Values(MatDepth(CV_8U)),
|
||||
Bool()));
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImgProc, CvtColor_RGB2YUV_420,
|
||||
testing::Combine(
|
||||
testing::Values(MatDepth(CV_8U)),
|
||||
Bool()));
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImgProc, CvtColor_YUV2RGB_422,
|
||||
testing::Combine(
|
||||
testing::Values(MatDepth(CV_8U)),
|
||||
Bool()));
|
||||
|
||||
} } // namespace opencv_test::ocl
|
||||
|
||||
#endif
|
||||
142
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_filter2d.cpp
vendored
Normal file
142
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_filter2d.cpp
vendored
Normal file
@@ -0,0 +1,142 @@
|
||||
/*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) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Copyright (C) 2010-2012, Multicoreware, 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/ts/ocl_test.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
namespace opencv_test {
|
||||
namespace ocl {
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Filter2D
|
||||
PARAM_TEST_CASE(Filter2D, MatDepth, Channels, int, int, BorderType, bool, bool)
|
||||
{
|
||||
static const int kernelMinSize = 2;
|
||||
static const int kernelMaxSize = 10;
|
||||
|
||||
int type;
|
||||
Size size;
|
||||
Point anchor;
|
||||
int borderType;
|
||||
int widthMultiple;
|
||||
bool useRoi;
|
||||
Mat kernel;
|
||||
double delta;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(dst);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
type = CV_MAKE_TYPE(GET_PARAM(0), GET_PARAM(1));
|
||||
Size ksize(GET_PARAM(2), GET_PARAM(2));
|
||||
widthMultiple = GET_PARAM(3);
|
||||
borderType = GET_PARAM(4) | (GET_PARAM(5) ? BORDER_ISOLATED : 0);
|
||||
useRoi = GET_PARAM(6);
|
||||
Mat temp = randomMat(ksize, CV_MAKE_TYPE(((CV_64F == CV_MAT_DEPTH(type)) ? CV_64F : CV_32F), 1), -MAX_VALUE, MAX_VALUE);
|
||||
cv::normalize(temp, kernel, 1.0, 0.0, NORM_L1);
|
||||
}
|
||||
|
||||
void random_roi()
|
||||
{
|
||||
size = randomSize(1, MAX_VALUE);
|
||||
// Make sure the width is a multiple of the requested value, and no more.
|
||||
size.width &= ~((widthMultiple * 2) - 1);
|
||||
size.width += widthMultiple;
|
||||
|
||||
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(src, src_roi, size, srcBorder, type, -MAX_VALUE, MAX_VALUE);
|
||||
|
||||
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(dst, dst_roi, size, dstBorder, type, -MAX_VALUE, MAX_VALUE);
|
||||
|
||||
anchor.x = randomInt(-1, kernel.size[0]);
|
||||
anchor.y = randomInt(-1, kernel.size[1]);
|
||||
|
||||
delta = randomDouble(-100, 100);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
}
|
||||
|
||||
void Near(double threshold = 0.0)
|
||||
{
|
||||
EXPECT_MAT_NEAR(dst, udst, threshold);
|
||||
EXPECT_MAT_NEAR(dst_roi, udst_roi, threshold);
|
||||
}
|
||||
};
|
||||
|
||||
OCL_TEST_P(Filter2D, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::filter2D(src_roi, dst_roi, -1, kernel, anchor, delta, borderType));
|
||||
OCL_ON(cv::filter2D(usrc_roi, udst_roi, -1, kernel, anchor, delta, borderType));
|
||||
|
||||
Near(1.0);
|
||||
}
|
||||
}
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImageProc, Filter2D,
|
||||
Combine(
|
||||
Values(CV_8U, CV_16U, CV_32F),
|
||||
OCL_ALL_CHANNELS,
|
||||
Values(3, 5, 7), // Kernel size
|
||||
Values(1, 4, 8), // Width multiple
|
||||
Values((BorderType)BORDER_CONSTANT,
|
||||
(BorderType)BORDER_REPLICATE,
|
||||
(BorderType)BORDER_REFLECT,
|
||||
(BorderType)BORDER_REFLECT_101),
|
||||
Bool(), // BORDER_ISOLATED
|
||||
Bool() // ROI
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
} } // namespace opencv_test::ocl
|
||||
|
||||
#endif // HAVE_OPENCL
|
||||
766
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_filters.cpp
vendored
Normal file
766
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_filters.cpp
vendored
Normal file
@@ -0,0 +1,766 @@
|
||||
/*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) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// @Authors
|
||||
// Niko Li, newlife20080214@gmail.com
|
||||
// Jia Haipeng, jiahaipeng95@gmail.com
|
||||
// Zero Lin, Zero.Lin@amd.com
|
||||
// Zhang Ying, zhangying913@gmail.com
|
||||
// Yao Wang, bitwangyaoyao@gmail.com
|
||||
//
|
||||
// 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 "cvconfig.h"
|
||||
#include "opencv2/ts/ocl_test.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
namespace opencv_test {
|
||||
namespace ocl {
|
||||
|
||||
PARAM_TEST_CASE(FilterTestBase, MatType,
|
||||
int, // kernel size
|
||||
Size, // dx, dy
|
||||
BorderType, // border type
|
||||
double, // optional parameter
|
||||
bool, // roi or not
|
||||
int) // width multiplier
|
||||
{
|
||||
int type, borderType, ksize;
|
||||
Size size;
|
||||
double param;
|
||||
bool useRoi;
|
||||
int widthMultiple;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(dst);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
type = GET_PARAM(0);
|
||||
ksize = GET_PARAM(1);
|
||||
size = GET_PARAM(2);
|
||||
borderType = GET_PARAM(3);
|
||||
param = GET_PARAM(4);
|
||||
useRoi = GET_PARAM(5);
|
||||
widthMultiple = GET_PARAM(6);
|
||||
}
|
||||
|
||||
void random_roi(int minSize = 1)
|
||||
{
|
||||
if (minSize == 0)
|
||||
minSize = ksize;
|
||||
|
||||
Size roiSize = randomSize(minSize, MAX_VALUE);
|
||||
roiSize.width &= ~((widthMultiple * 2) - 1);
|
||||
roiSize.width += widthMultiple;
|
||||
|
||||
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(src, src_roi, roiSize, srcBorder, type, 5, 256);
|
||||
|
||||
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(dst, dst_roi, roiSize, dstBorder, type, -60, 70);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
}
|
||||
|
||||
void Near()
|
||||
{
|
||||
int depth = CV_MAT_DEPTH(type);
|
||||
bool isFP = depth >= CV_32F;
|
||||
|
||||
if (isFP)
|
||||
Near(1e-6, true);
|
||||
else
|
||||
Near(1, false);
|
||||
}
|
||||
|
||||
void Near(double threshold, bool relative)
|
||||
{
|
||||
if (relative)
|
||||
OCL_EXPECT_MATS_NEAR_RELATIVE(dst, threshold);
|
||||
else
|
||||
OCL_EXPECT_MATS_NEAR(dst, threshold);
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Bilateral
|
||||
|
||||
typedef FilterTestBase Bilateral;
|
||||
|
||||
OCL_TEST_P(Bilateral, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
double sigmacolor = rng.uniform(20, 100);
|
||||
double sigmaspace = rng.uniform(10, 40);
|
||||
|
||||
OCL_OFF(cv::bilateralFilter(src_roi, dst_roi, ksize, sigmacolor, sigmaspace, borderType));
|
||||
OCL_ON(cv::bilateralFilter(usrc_roi, udst_roi, ksize, sigmacolor, sigmaspace, borderType));
|
||||
|
||||
Near();
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Laplacian
|
||||
|
||||
typedef FilterTestBase LaplacianTest;
|
||||
|
||||
OCL_TEST_P(LaplacianTest, Accuracy)
|
||||
{
|
||||
double scale = param;
|
||||
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::Laplacian(src_roi, dst_roi, -1, ksize, scale, 10, borderType));
|
||||
OCL_ON(cv::Laplacian(usrc_roi, udst_roi, -1, ksize, scale, 10, borderType));
|
||||
|
||||
Near();
|
||||
}
|
||||
}
|
||||
|
||||
PARAM_TEST_CASE(Deriv3x3_cols16_rows2_Base, MatType,
|
||||
int, // kernel size
|
||||
Size, // dx, dy
|
||||
BorderType, // border type
|
||||
double, // optional parameter
|
||||
bool, // roi or not
|
||||
int) // width multiplier
|
||||
{
|
||||
int type, borderType, ksize;
|
||||
Size size;
|
||||
double param;
|
||||
bool useRoi;
|
||||
int widthMultiple;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(dst);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
type = GET_PARAM(0);
|
||||
ksize = GET_PARAM(1);
|
||||
size = GET_PARAM(2);
|
||||
borderType = GET_PARAM(3);
|
||||
param = GET_PARAM(4);
|
||||
useRoi = GET_PARAM(5);
|
||||
widthMultiple = GET_PARAM(6);
|
||||
}
|
||||
|
||||
void random_roi()
|
||||
{
|
||||
size = Size(3, 3);
|
||||
|
||||
Size roiSize = randomSize(size.width, MAX_VALUE, size.height, MAX_VALUE);
|
||||
roiSize.width = std::max(size.width + 13, roiSize.width & (~0xf));
|
||||
roiSize.height = std::max(size.height + 1, roiSize.height & (~0x1));
|
||||
|
||||
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(src, src_roi, roiSize, srcBorder, type, 5, 256);
|
||||
|
||||
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(dst, dst_roi, roiSize, dstBorder, type, -60, 70);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
}
|
||||
|
||||
void Near()
|
||||
{
|
||||
Near(1, false);
|
||||
}
|
||||
|
||||
void Near(double threshold, bool relative)
|
||||
{
|
||||
if (relative)
|
||||
OCL_EXPECT_MATS_NEAR_RELATIVE(dst, threshold);
|
||||
else
|
||||
OCL_EXPECT_MATS_NEAR(dst, threshold);
|
||||
}
|
||||
};
|
||||
|
||||
typedef Deriv3x3_cols16_rows2_Base Laplacian3_cols16_rows2;
|
||||
|
||||
OCL_TEST_P(Laplacian3_cols16_rows2, Accuracy)
|
||||
{
|
||||
double scale = param;
|
||||
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::Laplacian(src_roi, dst_roi, -1, ksize, scale, 10, borderType));
|
||||
OCL_ON(cv::Laplacian(usrc_roi, udst_roi, -1, ksize, scale, 10, borderType));
|
||||
|
||||
Near();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Sobel
|
||||
|
||||
typedef FilterTestBase SobelTest;
|
||||
|
||||
OCL_TEST_P(SobelTest, Mat)
|
||||
{
|
||||
int dx = size.width, dy = size.height;
|
||||
double scale = param;
|
||||
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::Sobel(src_roi, dst_roi, -1, dx, dy, ksize, scale, /* delta */0, borderType));
|
||||
OCL_ON(cv::Sobel(usrc_roi, udst_roi, -1, dx, dy, ksize, scale, /* delta */0, borderType));
|
||||
|
||||
Near();
|
||||
}
|
||||
}
|
||||
|
||||
typedef Deriv3x3_cols16_rows2_Base Sobel3x3_cols16_rows2;
|
||||
|
||||
OCL_TEST_P(Sobel3x3_cols16_rows2, Mat)
|
||||
{
|
||||
int dx = size.width, dy = size.height;
|
||||
double scale = param;
|
||||
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::Sobel(src_roi, dst_roi, -1, dx, dy, ksize, scale, /* delta */0, borderType));
|
||||
OCL_ON(cv::Sobel(usrc_roi, udst_roi, -1, dx, dy, ksize, scale, /* delta */0, borderType));
|
||||
|
||||
Near();
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Scharr
|
||||
|
||||
typedef FilterTestBase ScharrTest;
|
||||
|
||||
OCL_TEST_P(ScharrTest, Mat)
|
||||
{
|
||||
int dx = size.width, dy = size.height;
|
||||
double scale = param;
|
||||
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::Scharr(src_roi, dst_roi, -1, dx, dy, scale, /* delta */ 0, borderType));
|
||||
OCL_ON(cv::Scharr(usrc_roi, udst_roi, -1, dx, dy, scale, /* delta */ 0, borderType));
|
||||
|
||||
Near();
|
||||
}
|
||||
}
|
||||
|
||||
typedef Deriv3x3_cols16_rows2_Base Scharr3x3_cols16_rows2;
|
||||
|
||||
OCL_TEST_P(Scharr3x3_cols16_rows2, Mat)
|
||||
{
|
||||
int dx = size.width, dy = size.height;
|
||||
double scale = param;
|
||||
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::Scharr(src_roi, dst_roi, -1, dx, dy, scale, /* delta */ 0, borderType));
|
||||
OCL_ON(cv::Scharr(usrc_roi, udst_roi, -1, dx, dy, scale, /* delta */ 0, borderType));
|
||||
|
||||
Near();
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// GaussianBlur
|
||||
|
||||
typedef FilterTestBase GaussianBlurTest;
|
||||
|
||||
OCL_TEST_P(GaussianBlurTest, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times + 1; j++)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
double sigma1 = rng.uniform(0.1, 1.0);
|
||||
double sigma2 = j % 2 == 0 ? sigma1 : rng.uniform(0.1, 1.0);
|
||||
|
||||
OCL_OFF(cv::GaussianBlur(src_roi, dst_roi, Size(ksize, ksize), sigma1, sigma2, borderType));
|
||||
OCL_ON(cv::GaussianBlur(usrc_roi, udst_roi, Size(ksize, ksize), sigma1, sigma2, borderType));
|
||||
|
||||
Near(CV_MAT_DEPTH(type) >= CV_32F ? 1e-3 : 4, CV_MAT_DEPTH(type) >= CV_32F);
|
||||
}
|
||||
}
|
||||
|
||||
PARAM_TEST_CASE(GaussianBlur_multicols_Base, MatType,
|
||||
int, // kernel size
|
||||
Size, // dx, dy
|
||||
BorderType, // border type
|
||||
double, // optional parameter
|
||||
bool, // roi or not
|
||||
int) // width multiplier
|
||||
{
|
||||
int type, borderType, ksize;
|
||||
Size size;
|
||||
double param;
|
||||
bool useRoi;
|
||||
int widthMultiple;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(dst);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
type = GET_PARAM(0);
|
||||
ksize = GET_PARAM(1);
|
||||
size = GET_PARAM(2);
|
||||
borderType = GET_PARAM(3);
|
||||
param = GET_PARAM(4);
|
||||
useRoi = GET_PARAM(5);
|
||||
widthMultiple = GET_PARAM(6);
|
||||
}
|
||||
|
||||
void random_roi()
|
||||
{
|
||||
size = Size(ksize, ksize);
|
||||
|
||||
Size roiSize = randomSize(size.width, MAX_VALUE, size.height, MAX_VALUE);
|
||||
if (ksize == 3)
|
||||
{
|
||||
roiSize.width = std::max((size.width + 15) & 0x10, roiSize.width & (~0xf));
|
||||
roiSize.height = std::max(size.height + 1, roiSize.height & (~0x1));
|
||||
}
|
||||
else if (ksize == 5)
|
||||
{
|
||||
roiSize.width = std::max((size.width + 3) & 0x4, roiSize.width & (~0x3));
|
||||
}
|
||||
|
||||
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(src, src_roi, roiSize, srcBorder, type, 5, 256);
|
||||
|
||||
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(dst, dst_roi, roiSize, dstBorder, type, -60, 70);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
}
|
||||
|
||||
void Near()
|
||||
{
|
||||
Near(1, false);
|
||||
}
|
||||
|
||||
void Near(double threshold, bool relative)
|
||||
{
|
||||
if (relative)
|
||||
OCL_EXPECT_MATS_NEAR_RELATIVE(dst, threshold);
|
||||
else
|
||||
OCL_EXPECT_MATS_NEAR(dst, threshold);
|
||||
}
|
||||
};
|
||||
|
||||
typedef GaussianBlur_multicols_Base GaussianBlur_multicols;
|
||||
|
||||
OCL_TEST_P(GaussianBlur_multicols, Mat)
|
||||
{
|
||||
Size kernelSize(ksize, ksize);
|
||||
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
double sigma1 = rng.uniform(0.1, 1.0);
|
||||
double sigma2 = j % 2 == 0 ? sigma1 : rng.uniform(0.1, 1.0);
|
||||
|
||||
OCL_OFF(cv::GaussianBlur(src_roi, dst_roi, Size(ksize, ksize), sigma1, sigma2, borderType));
|
||||
OCL_ON(cv::GaussianBlur(usrc_roi, udst_roi, Size(ksize, ksize), sigma1, sigma2, borderType));
|
||||
|
||||
Near(CV_MAT_DEPTH(type) >= CV_32F ? 1e-3 : 4, CV_MAT_DEPTH(type) >= CV_32F);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Erode
|
||||
|
||||
typedef FilterTestBase Erode;
|
||||
|
||||
OCL_TEST_P(Erode, Mat)
|
||||
{
|
||||
Size kernelSize(ksize, ksize);
|
||||
int iterations = (int)param;
|
||||
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
Mat kernel = ksize==0 ? Mat() : randomMat(kernelSize, CV_8UC1, 0, 2);
|
||||
|
||||
OCL_OFF(cv::erode(src_roi, dst_roi, kernel, Point(-1, -1), iterations) );
|
||||
OCL_ON(cv::erode(usrc_roi, udst_roi, kernel, Point(-1, -1), iterations) );
|
||||
|
||||
Near();
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Dilate
|
||||
|
||||
typedef FilterTestBase Dilate;
|
||||
|
||||
OCL_TEST_P(Dilate, Mat)
|
||||
{
|
||||
Size kernelSize(ksize, ksize);
|
||||
int iterations = (int)param;
|
||||
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
Mat kernel = ksize==0 ? Mat() : randomMat(kernelSize, CV_8UC1, 0, 2);
|
||||
|
||||
OCL_OFF(cv::dilate(src_roi, dst_roi, kernel, Point(-1, -1), iterations) );
|
||||
OCL_ON(cv::dilate(usrc_roi, udst_roi, kernel, Point(-1, -1), iterations) );
|
||||
|
||||
Near();
|
||||
}
|
||||
}
|
||||
|
||||
PARAM_TEST_CASE(MorphFilter3x3_cols16_rows2_Base, MatType,
|
||||
int, // kernel size
|
||||
Size, // dx, dy
|
||||
BorderType, // border type
|
||||
double, // optional parameter
|
||||
bool, // roi or not
|
||||
int) // width multiplier
|
||||
{
|
||||
int type, borderType, ksize;
|
||||
Size size;
|
||||
double param;
|
||||
bool useRoi;
|
||||
int widthMultiple;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(dst);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
type = GET_PARAM(0);
|
||||
ksize = GET_PARAM(1);
|
||||
size = GET_PARAM(2);
|
||||
borderType = GET_PARAM(3);
|
||||
param = GET_PARAM(4);
|
||||
useRoi = GET_PARAM(5);
|
||||
widthMultiple = GET_PARAM(6);
|
||||
}
|
||||
|
||||
void random_roi()
|
||||
{
|
||||
size = Size(3, 3);
|
||||
|
||||
Size roiSize = randomSize(size.width, MAX_VALUE, size.height, MAX_VALUE);
|
||||
roiSize.width = std::max(size.width + 13, roiSize.width & (~0xf));
|
||||
roiSize.height = std::max(size.height + 1, roiSize.height & (~0x1));
|
||||
|
||||
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(src, src_roi, roiSize, srcBorder, type, 5, 256);
|
||||
|
||||
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(dst, dst_roi, roiSize, dstBorder, type, -60, 70);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
}
|
||||
|
||||
void Near()
|
||||
{
|
||||
Near(1, false);
|
||||
}
|
||||
|
||||
void Near(double threshold, bool relative)
|
||||
{
|
||||
if (relative)
|
||||
OCL_EXPECT_MATS_NEAR_RELATIVE(dst, threshold);
|
||||
else
|
||||
OCL_EXPECT_MATS_NEAR(dst, threshold);
|
||||
}
|
||||
};
|
||||
|
||||
typedef MorphFilter3x3_cols16_rows2_Base MorphFilter3x3_cols16_rows2;
|
||||
|
||||
OCL_TEST_P(MorphFilter3x3_cols16_rows2, Mat)
|
||||
{
|
||||
Size kernelSize(ksize, ksize);
|
||||
int iterations = (int)param;
|
||||
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
Mat kernel = ksize==0 ? Mat() : randomMat(kernelSize, CV_8UC1, 0, 3);
|
||||
|
||||
OCL_OFF(cv::dilate(src_roi, dst_roi, kernel, Point(-1, -1), iterations) );
|
||||
OCL_ON(cv::dilate(usrc_roi, udst_roi, kernel, Point(-1, -1), iterations) );
|
||||
|
||||
Near();
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// MorphologyEx
|
||||
IMPLEMENT_PARAM_CLASS(MorphOp, int)
|
||||
PARAM_TEST_CASE(MorphologyEx, MatType,
|
||||
int, // kernel size
|
||||
MorphOp, // MORPH_OP
|
||||
int, // iterations
|
||||
bool)
|
||||
{
|
||||
int type, ksize, op, iterations;
|
||||
bool useRoi;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(dst);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
type = GET_PARAM(0);
|
||||
ksize = GET_PARAM(1);
|
||||
op = GET_PARAM(2);
|
||||
iterations = GET_PARAM(3);
|
||||
useRoi = GET_PARAM(4);
|
||||
}
|
||||
|
||||
void random_roi(int minSize = 1)
|
||||
{
|
||||
if (minSize == 0)
|
||||
minSize = ksize;
|
||||
|
||||
Size roiSize = randomSize(minSize, MAX_VALUE);
|
||||
|
||||
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(src, src_roi, roiSize, srcBorder, type, 5, 256);
|
||||
|
||||
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(dst, dst_roi, roiSize, dstBorder, type, -60, 70);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
}
|
||||
|
||||
void Near()
|
||||
{
|
||||
int depth = CV_MAT_DEPTH(type);
|
||||
bool isFP = depth >= CV_32F;
|
||||
|
||||
if (isFP)
|
||||
Near(1e-6, true);
|
||||
else
|
||||
Near(1, false);
|
||||
}
|
||||
|
||||
void Near(double threshold, bool relative)
|
||||
{
|
||||
if (relative)
|
||||
OCL_EXPECT_MATS_NEAR_RELATIVE(dst, threshold);
|
||||
else
|
||||
OCL_EXPECT_MATS_NEAR(dst, threshold);
|
||||
}
|
||||
};
|
||||
|
||||
OCL_TEST_P(MorphologyEx, Mat)
|
||||
{
|
||||
Size kernelSize(ksize, ksize);
|
||||
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
Mat kernel = randomMat(kernelSize, CV_8UC1, 0, 3);
|
||||
|
||||
OCL_OFF(cv::morphologyEx(src_roi, dst_roi, op, kernel, Point(-1, -1), iterations) );
|
||||
OCL_ON(cv::morphologyEx(usrc_roi, udst_roi, op, kernel, Point(-1, -1), iterations) );
|
||||
|
||||
Near();
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define FILTER_BORDER_SET_NO_ISOLATED \
|
||||
Values((BorderType)BORDER_CONSTANT, (BorderType)BORDER_REPLICATE, (BorderType)BORDER_REFLECT, (BorderType)BORDER_WRAP, (BorderType)BORDER_REFLECT_101/*, \
|
||||
(int)BORDER_CONSTANT|BORDER_ISOLATED, (int)BORDER_REPLICATE|BORDER_ISOLATED, \
|
||||
(int)BORDER_REFLECT|BORDER_ISOLATED, (int)BORDER_WRAP|BORDER_ISOLATED, \
|
||||
(int)BORDER_REFLECT_101|BORDER_ISOLATED*/) // WRAP and ISOLATED are not supported by cv:: version
|
||||
|
||||
#define FILTER_BORDER_SET_NO_WRAP_NO_ISOLATED \
|
||||
Values((BorderType)BORDER_CONSTANT, (BorderType)BORDER_REPLICATE, (BorderType)BORDER_REFLECT, /*(int)BORDER_WRAP,*/ (BorderType)BORDER_REFLECT_101/*, \
|
||||
(int)BORDER_CONSTANT|BORDER_ISOLATED, (int)BORDER_REPLICATE|BORDER_ISOLATED, \
|
||||
(int)BORDER_REFLECT|BORDER_ISOLATED, (int)BORDER_WRAP|BORDER_ISOLATED, \
|
||||
(int)BORDER_REFLECT_101|BORDER_ISOLATED*/) // WRAP and ISOLATED are not supported by cv:: version
|
||||
|
||||
#define FILTER_TYPES Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_16UC1, CV_16UC3, CV_16UC4, CV_32FC1, CV_32FC3, CV_32FC4)
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Filter, Bilateral, Combine(
|
||||
Values(CV_8UC1, CV_8UC3),
|
||||
Values(5, 9), // kernel size
|
||||
Values(Size(0, 0)), // not used
|
||||
FILTER_BORDER_SET_NO_ISOLATED,
|
||||
Values(0.0), // not used
|
||||
Bool(),
|
||||
Values(1, 4)));
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Filter, LaplacianTest, Combine(
|
||||
FILTER_TYPES,
|
||||
Values(1, 3, 5), // kernel size
|
||||
Values(Size(0, 0)), // not used
|
||||
FILTER_BORDER_SET_NO_WRAP_NO_ISOLATED,
|
||||
Values(1.0, 0.2, 3.0), // kernel scale
|
||||
Bool(),
|
||||
Values(1))); // not used
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Filter, Laplacian3_cols16_rows2, Combine(
|
||||
Values((MatType)CV_8UC1),
|
||||
Values(3), // kernel size
|
||||
Values(Size(0, 0)), // not used
|
||||
FILTER_BORDER_SET_NO_WRAP_NO_ISOLATED,
|
||||
Values(1.0, 0.2, 3.0), // kernel scale
|
||||
Bool(),
|
||||
Values(1))); // not used
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Filter, SobelTest, Combine(
|
||||
FILTER_TYPES,
|
||||
Values(3, 5), // kernel size
|
||||
Values(Size(1, 0), Size(1, 1), Size(2, 0), Size(2, 1)), // dx, dy
|
||||
FILTER_BORDER_SET_NO_WRAP_NO_ISOLATED,
|
||||
Values(0.0), // not used
|
||||
Bool(),
|
||||
Values(1))); // not used
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Filter, Sobel3x3_cols16_rows2, Combine(
|
||||
Values((MatType)CV_8UC1),
|
||||
Values(3), // kernel size
|
||||
Values(Size(1, 0), Size(1, 1), Size(2, 0), Size(2, 1)), // dx, dy
|
||||
FILTER_BORDER_SET_NO_WRAP_NO_ISOLATED,
|
||||
Values(0.0), // not used
|
||||
Bool(),
|
||||
Values(1))); // not used
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Filter, ScharrTest, Combine(
|
||||
FILTER_TYPES,
|
||||
Values(0), // not used
|
||||
Values(Size(0, 1), Size(1, 0)), // dx, dy
|
||||
FILTER_BORDER_SET_NO_WRAP_NO_ISOLATED,
|
||||
Values(1.0, 0.2), // kernel scale
|
||||
Bool(),
|
||||
Values(1))); // not used
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Filter, Scharr3x3_cols16_rows2, Combine(
|
||||
FILTER_TYPES,
|
||||
Values(0), // not used
|
||||
Values(Size(0, 1), Size(1, 0)), // dx, dy
|
||||
FILTER_BORDER_SET_NO_WRAP_NO_ISOLATED,
|
||||
Values(1.0, 0.2), // kernel scale
|
||||
Bool(),
|
||||
Values(1))); // not used
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Filter, GaussianBlurTest, Combine(
|
||||
FILTER_TYPES,
|
||||
Values(3, 5), // kernel size
|
||||
Values(Size(0, 0)), // not used
|
||||
FILTER_BORDER_SET_NO_WRAP_NO_ISOLATED,
|
||||
Values(0.0), // not used
|
||||
Bool(),
|
||||
Values(1))); // not used
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Filter, GaussianBlur_multicols, Combine(
|
||||
Values((MatType)CV_8UC1),
|
||||
Values(3, 5), // kernel size
|
||||
Values(Size(0, 0)), // not used
|
||||
FILTER_BORDER_SET_NO_WRAP_NO_ISOLATED,
|
||||
Values(0.0), // not used
|
||||
Bool(),
|
||||
Values(1))); // not used
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Filter, Erode, Combine(
|
||||
Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4, CV_64FC1, CV_64FC4),
|
||||
Values(0, 5, 7, 9), // kernel size, 0 means kernel = Mat()
|
||||
Values(Size(0, 0)), //not used
|
||||
Values((BorderType)BORDER_CONSTANT),
|
||||
Values(1.0, 2.0, 3.0, 4.0),
|
||||
Bool(),
|
||||
Values(1))); // not used
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Filter, Dilate, Combine(
|
||||
Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4, CV_64FC1, CV_64FC4),
|
||||
Values(0, 3, 5, 7, 9), // kernel size, 0 means kernel = Mat()
|
||||
Values(Size(0, 0)), // not used
|
||||
Values((BorderType)BORDER_CONSTANT),
|
||||
Values(1.0, 2.0, 3.0, 4.0),
|
||||
Bool(),
|
||||
Values(1))); // not used
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Filter, MorphFilter3x3_cols16_rows2, Combine(
|
||||
Values((MatType)CV_8UC1),
|
||||
Values(0, 3), // kernel size, 0 means kernel = Mat()
|
||||
Values(Size(0, 0)), // not used
|
||||
Values((BorderType)BORDER_CONSTANT),
|
||||
Values(1.0, 2.0, 3.0),
|
||||
Bool(),
|
||||
Values(1))); // not used
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Filter, MorphologyEx, Combine(
|
||||
Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4),
|
||||
Values(3, 5, 7), // kernel size
|
||||
Values((MorphOp)MORPH_OPEN, (MorphOp)MORPH_CLOSE, (MorphOp)MORPH_GRADIENT, (MorphOp)MORPH_TOPHAT, (MorphOp)MORPH_BLACKHAT), // used as generator of operations
|
||||
Values(1, 2, 3),
|
||||
Bool()));
|
||||
|
||||
|
||||
} } // namespace opencv_test::ocl
|
||||
|
||||
#endif // HAVE_OPENCL
|
||||
149
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_gftt.cpp
vendored
Normal file
149
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_gftt.cpp
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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) 2010-2012, Multicoreware, Inc., all rights reserved.
|
||||
// Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, 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/ts/ocl_test.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
namespace opencv_test {
|
||||
namespace ocl {
|
||||
|
||||
//////////////////////////// GoodFeaturesToTrack //////////////////////////
|
||||
|
||||
|
||||
PARAM_TEST_CASE(GoodFeaturesToTrack, double, bool)
|
||||
{
|
||||
double minDistance;
|
||||
bool useRoi;
|
||||
|
||||
static const int maxCorners;
|
||||
static const double qualityLevel;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src);
|
||||
UMat points, upoints;
|
||||
std::vector<float> quality, uquality;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
minDistance = GET_PARAM(0);
|
||||
useRoi = GET_PARAM(1);
|
||||
}
|
||||
|
||||
void generateTestData()
|
||||
{
|
||||
Mat frame = readImage("../gpu/opticalflow/rubberwhale1.png", IMREAD_GRAYSCALE);
|
||||
ASSERT_FALSE(frame.empty()) << "could not load gpu/opticalflow/rubberwhale1.png";
|
||||
|
||||
Size roiSize = frame.size();
|
||||
Border srcBorder = randomBorder(0, useRoi ? 2 : 0);
|
||||
randomSubMat(src, src_roi, roiSize, srcBorder, frame.type(), 5, 256);
|
||||
src_roi.copyTo(frame);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
}
|
||||
|
||||
void UMatToVector(const UMat & um, std::vector<Point2f> & v) const
|
||||
{
|
||||
v.resize(um.size().area());
|
||||
um.copyTo(Mat(um.size(), CV_32FC2, &v[0]));
|
||||
}
|
||||
};
|
||||
|
||||
const int GoodFeaturesToTrack::maxCorners = 1000;
|
||||
const double GoodFeaturesToTrack::qualityLevel = 0.01;
|
||||
|
||||
OCL_TEST_P(GoodFeaturesToTrack, Accuracy)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; ++j)
|
||||
{
|
||||
generateTestData();
|
||||
|
||||
std::vector<Point2f> upts, pts;
|
||||
|
||||
OCL_OFF(cv::goodFeaturesToTrack(src_roi, points, maxCorners, qualityLevel, minDistance, noArray(), quality));
|
||||
ASSERT_FALSE(points.empty());
|
||||
UMatToVector(points, pts);
|
||||
|
||||
OCL_ON(cv::goodFeaturesToTrack(usrc_roi, upoints, maxCorners, qualityLevel, minDistance, noArray(), uquality));
|
||||
ASSERT_FALSE(upoints.empty());
|
||||
UMatToVector(upoints, upts);
|
||||
|
||||
ASSERT_EQ(pts.size(), quality.size());
|
||||
ASSERT_EQ(upts.size(), uquality.size());
|
||||
ASSERT_EQ(upts.size(), pts.size());
|
||||
|
||||
int mistmatch = 0;
|
||||
for (size_t i = 0; i < pts.size(); ++i)
|
||||
{
|
||||
Point2i a = upts[i], b = pts[i];
|
||||
|
||||
bool eq = std::abs(a.x - b.x) < 1 && std::abs(a.y - b.y) < 1 &&
|
||||
std::abs(quality[i] - uquality[i]) <= 3.f * FLT_EPSILON * std::max(quality[i], uquality[i]);
|
||||
|
||||
if (!eq)
|
||||
++mistmatch;
|
||||
}
|
||||
|
||||
double bad_ratio = static_cast<double>(mistmatch) / pts.size();
|
||||
ASSERT_GE(1e-2, bad_ratio);
|
||||
}
|
||||
}
|
||||
|
||||
OCL_TEST_P(GoodFeaturesToTrack, EmptyCorners)
|
||||
{
|
||||
generateTestData();
|
||||
usrc_roi.setTo(Scalar::all(0));
|
||||
|
||||
OCL_ON(cv::goodFeaturesToTrack(usrc_roi, upoints, maxCorners, qualityLevel, minDistance, noArray(), uquality));
|
||||
|
||||
ASSERT_TRUE(upoints.empty());
|
||||
ASSERT_TRUE(uquality.empty());
|
||||
}
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, GoodFeaturesToTrack,
|
||||
::testing::Combine(testing::Values(0.0, 3.0), Bool()));
|
||||
|
||||
} } // namespace opencv_test::ocl
|
||||
|
||||
#endif
|
||||
276
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_histogram.cpp
vendored
Normal file
276
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_histogram.cpp
vendored
Normal file
@@ -0,0 +1,276 @@
|
||||
/*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) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
|
||||
// Copyright (C) 2014, Itseez, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// @Authors
|
||||
// Niko Li, newlife20080214@gmail.com
|
||||
// Jia Haipeng, jiahaipeng95@gmail.com
|
||||
// Shengen Yan, yanshengen@gmail.com
|
||||
// Jiang Liyuan, lyuan001.good@163.com
|
||||
// Rock Li, Rock.Li@amd.com
|
||||
// Wu Zailong, bullet@yeah.net
|
||||
// Xu Pang, pangxu010@163.com
|
||||
// Sen Liu, swjtuls1987@126.com
|
||||
//
|
||||
// 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/ts/ocl_test.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
namespace opencv_test {
|
||||
namespace ocl {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PARAM_TEST_CASE(CalcBackProject, MatDepth, int, bool)
|
||||
{
|
||||
int depth, N;
|
||||
bool useRoi;
|
||||
|
||||
std::vector<float> ranges;
|
||||
std::vector<int> channels;
|
||||
double scale;
|
||||
|
||||
std::vector<Mat> images;
|
||||
std::vector<Mat> images_roi;
|
||||
std::vector<UMat> uimages;
|
||||
std::vector<UMat> uimages_roi;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(hist);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(dst);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
depth = GET_PARAM(0);
|
||||
N = GET_PARAM(1);
|
||||
useRoi = GET_PARAM(2);
|
||||
|
||||
ASSERT_GE(2, N);
|
||||
|
||||
images.resize(N);
|
||||
images_roi.resize(N);
|
||||
uimages.resize(N);
|
||||
uimages_roi.resize(N);
|
||||
}
|
||||
|
||||
void random_roi()
|
||||
{
|
||||
Size roiSize = randomSize(1, MAX_VALUE);
|
||||
|
||||
int totalChannels = 0;
|
||||
|
||||
ranges.clear();
|
||||
channels.clear();
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
int cn = randomInt(1, 5);
|
||||
randomSubMat(images[i], images_roi[i], roiSize, srcBorder, CV_MAKE_TYPE(depth, cn), 0, 125);
|
||||
|
||||
ranges.push_back(10);
|
||||
ranges.push_back(100);
|
||||
|
||||
channels.push_back(randomInt(0, cn) + totalChannels);
|
||||
totalChannels += cn;
|
||||
}
|
||||
|
||||
Mat tmpHist;
|
||||
{
|
||||
std::vector<int> hist_size(N);
|
||||
for (int i = 0 ; i < N; ++i)
|
||||
hist_size[i] = randomInt(10, 50);
|
||||
|
||||
cv::calcHist(images_roi, channels, noArray(), tmpHist, hist_size, ranges);
|
||||
ASSERT_EQ(CV_32FC1, tmpHist.type());
|
||||
}
|
||||
|
||||
Border histBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(hist, hist_roi, tmpHist.size(), histBorder, tmpHist.type(), 0, MAX_VALUE);
|
||||
tmpHist.copyTo(hist_roi);
|
||||
|
||||
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(dst, dst_roi, roiSize, dstBorder, CV_MAKE_TYPE(depth, 1), 5, 16);
|
||||
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
images[i].copyTo(uimages[i]);
|
||||
|
||||
Size _wholeSize;
|
||||
Point ofs;
|
||||
images_roi[i].locateROI(_wholeSize, ofs);
|
||||
|
||||
uimages_roi[i] = uimages[i](Rect(ofs.x, ofs.y, images_roi[i].cols, images_roi[i].rows));
|
||||
}
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(hist);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
|
||||
scale = randomDouble(0.1, 1);
|
||||
}
|
||||
|
||||
void test_by_pict()
|
||||
{
|
||||
Mat frame1 = readImage("optflow/RubberWhale1.png", IMREAD_GRAYSCALE);
|
||||
|
||||
UMat usrc;
|
||||
frame1.copyTo(usrc);
|
||||
int histSize = randomInt(3, 29);
|
||||
float hue_range[] = { 0, 180 };
|
||||
const float* ranges1 = { hue_range };
|
||||
Mat hist1;
|
||||
|
||||
//compute histogram
|
||||
calcHist(&frame1, 1, 0, Mat(), hist1, 1, &histSize, &ranges1, true, false);
|
||||
normalize(hist1, hist1, 0, 255, NORM_MINMAX, -1, Mat());
|
||||
|
||||
Mat dst1;
|
||||
UMat udst1, src, uhist1;
|
||||
hist1.copyTo(uhist1);
|
||||
std::vector<UMat> uims;
|
||||
uims.push_back(usrc);
|
||||
std::vector<float> urngs;
|
||||
urngs.push_back(0);
|
||||
urngs.push_back(180);
|
||||
std::vector<int> chs;
|
||||
chs.push_back(0);
|
||||
|
||||
OCL_OFF(calcBackProject(&frame1, 1, 0, hist1, dst1, &ranges1, 1, true));
|
||||
OCL_ON(calcBackProject(uims, chs, uhist1, udst1, urngs, 1.0));
|
||||
|
||||
if (cv::ocl::useOpenCL() && cv::ocl::Device::getDefault().isAMD())
|
||||
{
|
||||
Size dstSize = dst1.size();
|
||||
int nDiffs = (int)(0.03f*dstSize.height*dstSize.width);
|
||||
|
||||
//check if the dst mats are the same except 3% difference
|
||||
EXPECT_MAT_N_DIFF(dst1, udst1, nDiffs);
|
||||
}
|
||||
else
|
||||
{
|
||||
EXPECT_MAT_NEAR(dst1, udst1, 0.0);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////// CalcBackProject //////////////////////////////////////////////
|
||||
|
||||
OCL_TEST_P(CalcBackProject, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::calcBackProject(images_roi, channels, hist_roi, dst_roi, ranges, scale));
|
||||
OCL_ON(cv::calcBackProject(uimages_roi, channels, uhist_roi, udst_roi, ranges, scale));
|
||||
|
||||
Size dstSize = dst_roi.size();
|
||||
int nDiffs = std::max((int)(0.07f*dstSize.area()), 1);
|
||||
|
||||
//check if the dst mats are the same except 7% difference
|
||||
EXPECT_MAT_N_DIFF(dst_roi, udst_roi, nDiffs);
|
||||
}
|
||||
}
|
||||
|
||||
OCL_TEST_P(CalcBackProject, Mat_RealImage)
|
||||
{
|
||||
//check on given image
|
||||
test_by_pict();
|
||||
}
|
||||
|
||||
//////////////////////////////// CalcHist //////////////////////////////////////////////
|
||||
|
||||
PARAM_TEST_CASE(CalcHist, bool)
|
||||
{
|
||||
bool useRoi;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(hist);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
useRoi = GET_PARAM(0);
|
||||
}
|
||||
|
||||
void random_roi()
|
||||
{
|
||||
Size roiSize = randomSize(1, MAX_VALUE);
|
||||
|
||||
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(src, src_roi, roiSize, srcBorder, CV_8UC1, 0, 256);
|
||||
|
||||
Border histBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(hist, hist_roi, Size(1, 256), histBorder, CV_32SC1, 0, MAX_VALUE);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(hist);
|
||||
}
|
||||
};
|
||||
|
||||
OCL_TEST_P(CalcHist, Mat)
|
||||
{
|
||||
const std::vector<int> channels(1, 0);
|
||||
std::vector<float> ranges(2);
|
||||
std::vector<int> histSize(1, 256);
|
||||
ranges[0] = 0;
|
||||
ranges[1] = 256;
|
||||
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::calcHist(std::vector<Mat>(1, src_roi), channels, noArray(), hist_roi, histSize, ranges, false));
|
||||
OCL_ON(cv::calcHist(std::vector<UMat>(1, usrc_roi), channels, noArray(), uhist_roi, histSize, ranges, false));
|
||||
|
||||
OCL_EXPECT_MATS_NEAR(hist, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, CalcBackProject, Combine(Values((MatDepth)CV_8U), Values(1, 2), Bool()));
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, CalcHist, Values(true, false));
|
||||
|
||||
} } // namespace opencv_test::ocl
|
||||
|
||||
#endif // HAVE_OPENCL
|
||||
184
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_houghlines.cpp
vendored
Normal file
184
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_houghlines.cpp
vendored
Normal file
@@ -0,0 +1,184 @@
|
||||
// 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, Itseez, 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 {
|
||||
|
||||
struct Vec2fComparator
|
||||
{
|
||||
bool operator()(const Vec2f& a, const Vec2f b) const
|
||||
{
|
||||
if(a[0] != b[0]) return a[0] < b[0];
|
||||
else return a[1] < b[1];
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////// HoughLines ////////////////////////////////////
|
||||
|
||||
PARAM_TEST_CASE(HoughLines, double, double, int)
|
||||
{
|
||||
double rhoStep, thetaStep;
|
||||
int threshold;
|
||||
|
||||
Size src_size;
|
||||
Mat src, dst;
|
||||
UMat usrc, udst;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
rhoStep = GET_PARAM(0);
|
||||
thetaStep = GET_PARAM(1);
|
||||
threshold = GET_PARAM(2);
|
||||
}
|
||||
|
||||
void generateTestData()
|
||||
{
|
||||
src_size = randomSize(500, 1920);
|
||||
src.create(src_size, CV_8UC1);
|
||||
src.setTo(Scalar::all(0));
|
||||
line(src, Point(0, 100), Point(100, 100), Scalar::all(255), 1);
|
||||
line(src, Point(0, 200), Point(100, 200), Scalar::all(255), 1);
|
||||
line(src, Point(0, 400), Point(100, 400), Scalar::all(255), 1);
|
||||
line(src, Point(100, 0), Point(100, 200), Scalar::all(255), 1);
|
||||
line(src, Point(200, 0), Point(200, 200), Scalar::all(255), 1);
|
||||
line(src, Point(400, 0), Point(400, 200), Scalar::all(255), 1);
|
||||
|
||||
src.copyTo(usrc);
|
||||
}
|
||||
|
||||
void readRealTestData()
|
||||
{
|
||||
Mat img = readImage("shared/pic5.png", IMREAD_GRAYSCALE);
|
||||
Canny(img, src, 100, 150, 3);
|
||||
|
||||
src.copyTo(usrc);
|
||||
}
|
||||
|
||||
void Near(double eps = 0.)
|
||||
{
|
||||
EXPECT_EQ(dst.size(), udst.size());
|
||||
|
||||
if (dst.total() > 0)
|
||||
{
|
||||
Mat lines_cpu, lines_gpu;
|
||||
dst.copyTo(lines_cpu);
|
||||
udst.copyTo(lines_gpu);
|
||||
|
||||
std::sort(lines_cpu.begin<Vec2f>(), lines_cpu.end<Vec2f>(), Vec2fComparator());
|
||||
std::sort(lines_gpu.begin<Vec2f>(), lines_gpu.end<Vec2f>(), Vec2fComparator());
|
||||
|
||||
EXPECT_LE(TestUtils::checkNorm2(lines_cpu, lines_gpu), eps);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
OCL_TEST_P(HoughLines, RealImage)
|
||||
{
|
||||
readRealTestData();
|
||||
|
||||
OCL_OFF(cv::HoughLines(src, dst, rhoStep, thetaStep, threshold));
|
||||
OCL_ON(cv::HoughLines(usrc, udst, rhoStep, thetaStep, threshold));
|
||||
|
||||
Near(1e-5);
|
||||
}
|
||||
|
||||
OCL_TEST_P(HoughLines, GeneratedImage)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
generateTestData();
|
||||
|
||||
OCL_OFF(cv::HoughLines(src, dst, rhoStep, thetaStep, threshold));
|
||||
OCL_ON(cv::HoughLines(usrc, udst, rhoStep, thetaStep, threshold));
|
||||
|
||||
Near(1e-5);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////// HoughLinesP ///////////////////////////////////
|
||||
|
||||
PARAM_TEST_CASE(HoughLinesP, int, double, double)
|
||||
{
|
||||
double rhoStep, thetaStep, minLineLength, maxGap;
|
||||
int threshold;
|
||||
|
||||
Size src_size;
|
||||
Mat src, dst;
|
||||
UMat usrc, udst;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
rhoStep = 1.0;
|
||||
thetaStep = CV_PI / 180;
|
||||
threshold = GET_PARAM(0);
|
||||
minLineLength = GET_PARAM(1);
|
||||
maxGap = GET_PARAM(2);
|
||||
}
|
||||
|
||||
void readRealTestData()
|
||||
{
|
||||
Mat img = readImage("shared/pic5.png", IMREAD_GRAYSCALE);
|
||||
Canny(img, src, 50, 200, 3);
|
||||
|
||||
src.copyTo(usrc);
|
||||
}
|
||||
|
||||
void Near(double eps = 0.)
|
||||
{
|
||||
Mat lines_gpu = udst.getMat(ACCESS_READ);
|
||||
|
||||
if (dst.total() > 0 && lines_gpu.total() > 0)
|
||||
{
|
||||
Mat result_cpu(src.size(), CV_8UC1, Scalar::all(0));
|
||||
Mat result_gpu(src.size(), CV_8UC1, Scalar::all(0));
|
||||
|
||||
MatConstIterator_<Vec4i> it = dst.begin<Vec4i>(), end = dst.end<Vec4i>();
|
||||
for ( ; it != end; it++)
|
||||
{
|
||||
Vec4i p = *it;
|
||||
line(result_cpu, Point(p[0], p[1]), Point(p[2], p[3]), Scalar(255));
|
||||
}
|
||||
|
||||
it = lines_gpu.begin<Vec4i>(), end = lines_gpu.end<Vec4i>();
|
||||
for ( ; it != end; it++)
|
||||
{
|
||||
Vec4i p = *it;
|
||||
line(result_gpu, Point(p[0], p[1]), Point(p[2], p[3]), Scalar(255));
|
||||
}
|
||||
|
||||
EXPECT_MAT_SIMILAR(result_cpu, result_gpu, eps);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
OCL_TEST_P(HoughLinesP, RealImage)
|
||||
{
|
||||
readRealTestData();
|
||||
|
||||
OCL_OFF(cv::HoughLinesP(src, dst, rhoStep, thetaStep, threshold, minLineLength, maxGap));
|
||||
OCL_ON(cv::HoughLinesP(usrc, udst, rhoStep, thetaStep, threshold, minLineLength, maxGap));
|
||||
|
||||
Near(0.25);
|
||||
}
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, HoughLines, Combine(Values(1, 0.5), // rhoStep
|
||||
Values(CV_PI / 180.0, CV_PI / 360.0), // thetaStep
|
||||
Values(85, 150))); // threshold
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, HoughLinesP, Combine(Values(100, 150), // threshold
|
||||
Values(50, 100), // minLineLength
|
||||
Values(5, 10))); // maxLineGap
|
||||
|
||||
} } // namespace opencv_test::ocl
|
||||
|
||||
#endif // HAVE_OPENCL
|
||||
501
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_imgproc.cpp
vendored
Normal file
501
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_imgproc.cpp
vendored
Normal file
@@ -0,0 +1,501 @@
|
||||
/*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) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// @Authors
|
||||
// Niko Li, newlife20080214@gmail.com
|
||||
// Jia Haipeng, jiahaipeng95@gmail.com
|
||||
// Shengen Yan, yanshengen@gmail.com
|
||||
// Jiang Liyuan, lyuan001.good@163.com
|
||||
// Rock Li, Rock.Li@amd.com
|
||||
// Wu Zailong, bullet@yeah.net
|
||||
// Xu Pang, pangxu010@163.com
|
||||
// Sen Liu, swjtuls1987@126.com
|
||||
//
|
||||
// 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/ts/ocl_test.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
namespace opencv_test {
|
||||
namespace ocl {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PARAM_TEST_CASE(ImgprocTestBase, MatType,
|
||||
int, // blockSize
|
||||
int, // border type
|
||||
bool) // roi or not
|
||||
{
|
||||
int type, borderType, blockSize;
|
||||
bool useRoi;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(dst);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
type = GET_PARAM(0);
|
||||
blockSize = GET_PARAM(1);
|
||||
borderType = GET_PARAM(2);
|
||||
useRoi = GET_PARAM(3);
|
||||
}
|
||||
|
||||
void random_roi()
|
||||
{
|
||||
Size roiSize = randomSize(1, MAX_VALUE);
|
||||
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(src, src_roi, roiSize, srcBorder, type, 5, 256);
|
||||
|
||||
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(dst, dst_roi, roiSize, dstBorder, type, 5, 16);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
}
|
||||
|
||||
void Near(double threshold = 0.0, bool relative = false)
|
||||
{
|
||||
if (relative)
|
||||
OCL_EXPECT_MATS_NEAR_RELATIVE(dst, threshold);
|
||||
else
|
||||
OCL_EXPECT_MATS_NEAR(dst, threshold);
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////// copyMakeBorder ////////////////////////////////////////////
|
||||
|
||||
PARAM_TEST_CASE(CopyMakeBorder, MatDepth, // depth
|
||||
Channels, // channels
|
||||
bool, // isolated or not
|
||||
BorderType, // border type
|
||||
bool) // roi or not
|
||||
{
|
||||
int type, borderType;
|
||||
bool useRoi;
|
||||
|
||||
TestUtils::Border border;
|
||||
Scalar val;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(dst);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
type = CV_MAKE_TYPE(GET_PARAM(0), GET_PARAM(1));
|
||||
borderType = GET_PARAM(3);
|
||||
|
||||
if (GET_PARAM(2))
|
||||
borderType |= BORDER_ISOLATED;
|
||||
|
||||
useRoi = GET_PARAM(4);
|
||||
}
|
||||
|
||||
void random_roi()
|
||||
{
|
||||
border = randomBorder(0, MAX_VALUE << 2);
|
||||
val = randomScalar(-MAX_VALUE, MAX_VALUE);
|
||||
|
||||
Size roiSize = randomSize(1, MAX_VALUE);
|
||||
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(src, src_roi, roiSize, srcBorder, type, -MAX_VALUE, MAX_VALUE);
|
||||
|
||||
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
dstBorder.top += border.top;
|
||||
dstBorder.lef += border.lef;
|
||||
dstBorder.rig += border.rig;
|
||||
dstBorder.bot += border.bot;
|
||||
|
||||
randomSubMat(dst, dst_roi, roiSize, dstBorder, type, -MAX_VALUE, MAX_VALUE);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
}
|
||||
|
||||
void Near()
|
||||
{
|
||||
OCL_EXPECT_MATS_NEAR(dst, 0);
|
||||
}
|
||||
};
|
||||
|
||||
OCL_TEST_P(CopyMakeBorder, Mat)
|
||||
{
|
||||
for (int i = 0; i < test_loop_times; ++i)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::copyMakeBorder(src_roi, dst_roi, border.top, border.bot, border.lef, border.rig, borderType, val));
|
||||
OCL_ON(cv::copyMakeBorder(usrc_roi, udst_roi, border.top, border.bot, border.lef, border.rig, borderType, val));
|
||||
|
||||
Near();
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////// equalizeHist //////////////////////////////////////////////
|
||||
|
||||
typedef ImgprocTestBase EqualizeHist;
|
||||
|
||||
OCL_TEST_P(EqualizeHist, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::equalizeHist(src_roi, dst_roi));
|
||||
OCL_ON(cv::equalizeHist(usrc_roi, udst_roi));
|
||||
|
||||
Near(1);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////// Corners test //////////////////////////////////////////
|
||||
|
||||
struct CornerTestBase :
|
||||
public ImgprocTestBase
|
||||
{
|
||||
void random_roi()
|
||||
{
|
||||
Mat image = readImageType("../gpu/stereobm/aloe-L.png", type);
|
||||
ASSERT_FALSE(image.empty());
|
||||
|
||||
bool isFP = CV_MAT_DEPTH(type) >= CV_32F;
|
||||
float val = 255.0f;
|
||||
if (isFP)
|
||||
{
|
||||
image.convertTo(image, -1, 1.0 / 255);
|
||||
val /= 255.0f;
|
||||
}
|
||||
|
||||
Size roiSize = image.size();
|
||||
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
|
||||
Size wholeSize = Size(roiSize.width + srcBorder.lef + srcBorder.rig, roiSize.height + srcBorder.top + srcBorder.bot);
|
||||
src = randomMat(wholeSize, type, -val, val, false);
|
||||
src_roi = src(Rect(srcBorder.lef, srcBorder.top, roiSize.width, roiSize.height));
|
||||
image.copyTo(src_roi);
|
||||
|
||||
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(dst, dst_roi, roiSize, dstBorder, CV_32FC1, 5, 16);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
}
|
||||
};
|
||||
|
||||
typedef CornerTestBase CornerMinEigenVal;
|
||||
|
||||
OCL_TEST_P(CornerMinEigenVal, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
int apertureSize = 3;
|
||||
|
||||
OCL_OFF(cv::cornerMinEigenVal(src_roi, dst_roi, blockSize, apertureSize, borderType));
|
||||
OCL_ON(cv::cornerMinEigenVal(usrc_roi, udst_roi, blockSize, apertureSize, borderType));
|
||||
|
||||
// The corner kernel uses native_sqrt() which has implementation defined accuracy.
|
||||
// If we're using a CL implementation that isn't intel, test with relaxed accuracy.
|
||||
if (!ocl::useOpenCL() || ocl::Device::getDefault().isIntel())
|
||||
Near(1e-5, true);
|
||||
else
|
||||
Near(0.1, true);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////// cornerHarris //////////////////////////////////////////
|
||||
|
||||
typedef CornerTestBase CornerHarris;
|
||||
|
||||
OCL_TEST_P(CornerHarris, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
int apertureSize = 3;
|
||||
double k = randomDouble(0.01, 0.9);
|
||||
|
||||
OCL_OFF(cv::cornerHarris(src_roi, dst_roi, blockSize, apertureSize, k, borderType));
|
||||
OCL_ON(cv::cornerHarris(usrc_roi, udst_roi, blockSize, apertureSize, k, borderType));
|
||||
|
||||
Near(1e-6, true);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////// preCornerDetect //////////////////////////////////////////
|
||||
|
||||
typedef ImgprocTestBase PreCornerDetect;
|
||||
|
||||
OCL_TEST_P(PreCornerDetect, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
const int apertureSize = blockSize;
|
||||
|
||||
OCL_OFF(cv::preCornerDetect(src_roi, dst_roi, apertureSize, borderType));
|
||||
OCL_ON(cv::preCornerDetect(usrc_roi, udst_roi, apertureSize, borderType));
|
||||
|
||||
Near(1e-6, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////// integral /////////////////////////////////////////////////
|
||||
|
||||
struct Integral :
|
||||
public ImgprocTestBase
|
||||
{
|
||||
int sdepth, sqdepth;
|
||||
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(dst2);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
type = GET_PARAM(0);
|
||||
sdepth = GET_PARAM(1);
|
||||
sqdepth = GET_PARAM(2);
|
||||
useRoi = GET_PARAM(3);
|
||||
}
|
||||
|
||||
void random_roi()
|
||||
{
|
||||
ASSERT_EQ(CV_MAT_CN(type), 1);
|
||||
|
||||
Size roiSize = randomSize(1, MAX_VALUE), isize = Size(roiSize.width + 1, roiSize.height + 1);
|
||||
Border srcBorder = randomBorder(0, useRoi ? 2 : 0);
|
||||
randomSubMat(src, src_roi, roiSize, srcBorder, type, 5, 256);
|
||||
|
||||
Border dstBorder = randomBorder(0, useRoi ? 2 : 0);
|
||||
randomSubMat(dst, dst_roi, isize, dstBorder, sdepth, 5, 16);
|
||||
|
||||
Border dst2Border = randomBorder(0, useRoi ? 2 : 0);
|
||||
randomSubMat(dst2, dst2_roi, isize, dst2Border, sqdepth, 5, 16);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst2);
|
||||
}
|
||||
|
||||
void Near2(double threshold = 0.0, bool relative = false)
|
||||
{
|
||||
if (relative)
|
||||
OCL_EXPECT_MATS_NEAR_RELATIVE(dst2, threshold);
|
||||
else
|
||||
OCL_EXPECT_MATS_NEAR(dst2, threshold);
|
||||
}
|
||||
};
|
||||
|
||||
OCL_TEST_P(Integral, Mat1)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::integral(src_roi, dst_roi, sdepth));
|
||||
OCL_ON(cv::integral(usrc_roi, udst_roi, sdepth));
|
||||
|
||||
Near();
|
||||
}
|
||||
}
|
||||
|
||||
OCL_TEST_P(Integral, Mat2)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::integral(src_roi, dst_roi, dst2_roi, sdepth, sqdepth));
|
||||
OCL_ON(cv::integral(usrc_roi, udst_roi, udst2_roi, sdepth, sqdepth));
|
||||
|
||||
Near();
|
||||
sqdepth == CV_32F ? Near2(1e-6, true) : Near2();
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////// threshold //////////////////////////////////////////////
|
||||
|
||||
struct Threshold :
|
||||
public ImgprocTestBase
|
||||
{
|
||||
int thresholdType;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
type = GET_PARAM(0);
|
||||
thresholdType = GET_PARAM(2);
|
||||
useRoi = GET_PARAM(3);
|
||||
}
|
||||
};
|
||||
|
||||
OCL_TEST_P(Threshold, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
double maxVal = randomDouble(20.0, 127.0);
|
||||
double thresh = randomDouble(0.0, maxVal);
|
||||
|
||||
OCL_OFF(cv::threshold(src_roi, dst_roi, thresh, maxVal, thresholdType));
|
||||
OCL_ON(cv::threshold(usrc_roi, udst_roi, thresh, maxVal, thresholdType));
|
||||
|
||||
Near(1);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////// CLAHE //////////////////////////////////////////////////
|
||||
|
||||
PARAM_TEST_CASE(CLAHETest, Size, double, bool)
|
||||
{
|
||||
Size gridSize;
|
||||
double clipLimit;
|
||||
bool useRoi;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(dst);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
gridSize = GET_PARAM(0);
|
||||
clipLimit = GET_PARAM(1);
|
||||
useRoi = GET_PARAM(2);
|
||||
}
|
||||
|
||||
void random_roi()
|
||||
{
|
||||
Size roiSize = randomSize(std::max(gridSize.height, gridSize.width), MAX_VALUE);
|
||||
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(src, src_roi, roiSize, srcBorder, CV_8UC1, 5, 256);
|
||||
|
||||
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(dst, dst_roi, roiSize, dstBorder, CV_8UC1, 5, 16);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
}
|
||||
|
||||
void Near(double threshold = 0.0)
|
||||
{
|
||||
OCL_EXPECT_MATS_NEAR(dst, threshold);
|
||||
}
|
||||
};
|
||||
|
||||
OCL_TEST_P(CLAHETest, Accuracy)
|
||||
{
|
||||
for (int i = 0; i < test_loop_times; ++i)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
Ptr<CLAHE> clahe = cv::createCLAHE(clipLimit, gridSize);
|
||||
|
||||
OCL_OFF(clahe->apply(src_roi, dst_roi));
|
||||
OCL_ON(clahe->apply(usrc_roi, udst_roi));
|
||||
|
||||
Near(1.0);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, EqualizeHist, Combine(
|
||||
Values((MatType)CV_8UC1),
|
||||
Values(0), // not used
|
||||
Values(0), // not used
|
||||
Bool()));
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, CornerMinEigenVal, Combine(
|
||||
Values((MatType)CV_8UC1, (MatType)CV_32FC1),
|
||||
Values(3, 5),
|
||||
Values((BorderType)BORDER_CONSTANT, (BorderType)BORDER_REPLICATE,
|
||||
(BorderType)BORDER_REFLECT, (BorderType)BORDER_REFLECT101),
|
||||
Bool()));
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, CornerHarris, Combine(
|
||||
Values((MatType)CV_8UC1, CV_32FC1),
|
||||
Values(3, 5),
|
||||
Values( (BorderType)BORDER_CONSTANT, (BorderType)BORDER_REPLICATE,
|
||||
(BorderType)BORDER_REFLECT, (BorderType)BORDER_REFLECT_101),
|
||||
Bool()));
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, PreCornerDetect, Combine(
|
||||
Values((MatType)CV_8UC1, CV_32FC1),
|
||||
Values(3, 5),
|
||||
Values( (BorderType)BORDER_CONSTANT, (BorderType)BORDER_REPLICATE,
|
||||
(BorderType)BORDER_REFLECT, (BorderType)BORDER_REFLECT_101),
|
||||
Bool()));
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, Integral, Combine(
|
||||
Values((MatType)CV_8UC1), // TODO does not work with CV_32F, CV_64F
|
||||
Values(CV_32SC1, CV_32FC1), // desired sdepth
|
||||
Values(CV_32FC1, CV_64FC1), // desired sqdepth
|
||||
Bool()));
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, Threshold, Combine(
|
||||
Values(CV_8UC1, CV_8UC2, CV_8UC3, CV_8UC4,
|
||||
CV_16SC1, CV_16SC2, CV_16SC3, CV_16SC4,
|
||||
CV_32FC1, CV_32FC2, CV_32FC3, CV_32FC4),
|
||||
Values(0),
|
||||
Values(ThreshOp(THRESH_BINARY),
|
||||
ThreshOp(THRESH_BINARY_INV), ThreshOp(THRESH_TRUNC),
|
||||
ThreshOp(THRESH_TOZERO), ThreshOp(THRESH_TOZERO_INV)),
|
||||
Bool()));
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, CLAHETest, Combine(
|
||||
Values(Size(4, 4), Size(32, 8), Size(8, 64)),
|
||||
Values(0.0, 10.0, 62.0, 300.0),
|
||||
Bool()));
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImgprocTestBase, CopyMakeBorder, Combine(
|
||||
testing::Values((MatDepth)CV_8U, (MatDepth)CV_16S, (MatDepth)CV_32S, (MatDepth)CV_32F),
|
||||
testing::Values(Channels(1), Channels(3), (Channels)4),
|
||||
Bool(), // border isolated or not
|
||||
Values((BorderType)BORDER_CONSTANT, (BorderType)BORDER_REPLICATE, (BorderType)BORDER_REFLECT,
|
||||
(BorderType)BORDER_WRAP, (BorderType)BORDER_REFLECT_101),
|
||||
Bool()));
|
||||
|
||||
} } // namespace opencv_test::ocl
|
||||
|
||||
#endif // HAVE_OPENCL
|
||||
133
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_match_template.cpp
vendored
Normal file
133
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_match_template.cpp
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
/*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) 2010-2012, Multicoreware, Inc., all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, 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/ts/ocl_test.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
namespace opencv_test {
|
||||
namespace ocl {
|
||||
|
||||
///////////////////////////////////////////// matchTemplate //////////////////////////////////////////////////////////
|
||||
|
||||
CV_ENUM(MatchTemplType, CV_TM_CCORR, CV_TM_CCORR_NORMED, CV_TM_SQDIFF, CV_TM_SQDIFF_NORMED, CV_TM_CCOEFF, CV_TM_CCOEFF_NORMED)
|
||||
|
||||
PARAM_TEST_CASE(MatchTemplate, MatDepth, Channels, MatchTemplType, bool)
|
||||
{
|
||||
int type;
|
||||
int depth;
|
||||
int method;
|
||||
bool use_roi;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(image);
|
||||
TEST_DECLARE_INPUT_PARAMETER(templ);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(result);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
type = CV_MAKE_TYPE(GET_PARAM(0), GET_PARAM(1));
|
||||
depth = GET_PARAM(0);
|
||||
method = GET_PARAM(2);
|
||||
use_roi = GET_PARAM(3);
|
||||
}
|
||||
|
||||
void generateTestData()
|
||||
{
|
||||
Size image_roiSize = randomSize(2, 100);
|
||||
Size templ_roiSize = Size(randomInt(1, image_roiSize.width), randomInt(1, image_roiSize.height));
|
||||
Size result_roiSize = Size(image_roiSize.width - templ_roiSize.width + 1,
|
||||
image_roiSize.height - templ_roiSize.height + 1);
|
||||
|
||||
const double upValue = 256;
|
||||
|
||||
Border imageBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
|
||||
randomSubMat(image, image_roi, image_roiSize, imageBorder, type, -upValue, upValue);
|
||||
|
||||
Border templBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
|
||||
randomSubMat(templ, templ_roi, templ_roiSize, templBorder, type, -upValue, upValue);
|
||||
|
||||
Border resultBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
|
||||
randomSubMat(result, result_roi, result_roiSize, resultBorder, CV_32FC1, -upValue, upValue);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(image);
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(templ);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(result);
|
||||
}
|
||||
|
||||
void Near()
|
||||
{
|
||||
bool isNormed =
|
||||
method == TM_CCORR_NORMED ||
|
||||
method == TM_SQDIFF_NORMED ||
|
||||
method == TM_CCOEFF_NORMED;
|
||||
|
||||
if (isNormed)
|
||||
OCL_EXPECT_MATS_NEAR(result, 3e-2);
|
||||
else
|
||||
OCL_EXPECT_MATS_NEAR_RELATIVE_SPARSE(result, 1.5e-2);
|
||||
}
|
||||
};
|
||||
|
||||
OCL_TEST_P(MatchTemplate, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
generateTestData();
|
||||
|
||||
OCL_OFF(cv::matchTemplate(image_roi, templ_roi, result_roi, method));
|
||||
OCL_ON(cv::matchTemplate(uimage_roi, utempl_roi, uresult_roi, method));
|
||||
|
||||
Near();
|
||||
}
|
||||
}
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImageProc, MatchTemplate, Combine(
|
||||
Values(CV_8U, CV_32F),
|
||||
Values(1, 2, 3, 4),
|
||||
MatchTemplType::all(),
|
||||
Bool())
|
||||
);
|
||||
} } // namespace opencv_test::ocl
|
||||
|
||||
#endif
|
||||
111
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_medianfilter.cpp
vendored
Normal file
111
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_medianfilter.cpp
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
/*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) 2010-2012, Multicoreware, Inc., all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, 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/ts/ocl_test.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
namespace opencv_test {
|
||||
namespace ocl {
|
||||
|
||||
/////////////////////////////////////////////medianFilter//////////////////////////////////////////////////////////
|
||||
|
||||
PARAM_TEST_CASE(MedianFilter, MatDepth, Channels, int, bool)
|
||||
{
|
||||
int type;
|
||||
int ksize;
|
||||
bool use_roi;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(dst);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
type = CV_MAKE_TYPE(GET_PARAM(0), GET_PARAM(1));
|
||||
ksize = GET_PARAM(2);
|
||||
use_roi = GET_PARAM(3);
|
||||
}
|
||||
|
||||
void generateTestData()
|
||||
{
|
||||
Size roiSize = randomSize(1, MAX_VALUE);
|
||||
Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
|
||||
randomSubMat(src, src_roi, roiSize, srcBorder, type, -MAX_VALUE, MAX_VALUE);
|
||||
|
||||
Border dstBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
|
||||
randomSubMat(dst, dst_roi, roiSize, dstBorder, type, -MAX_VALUE, MAX_VALUE);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
}
|
||||
|
||||
void Near(double threshold = 0.0)
|
||||
{
|
||||
EXPECT_MAT_NEAR(dst, udst, threshold);
|
||||
EXPECT_MAT_NEAR(dst_roi, udst_roi, threshold);
|
||||
}
|
||||
};
|
||||
|
||||
OCL_TEST_P(MedianFilter, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
generateTestData();
|
||||
|
||||
OCL_OFF(cv::medianBlur(src_roi, dst_roi, ksize));
|
||||
OCL_ON(cv::medianBlur(usrc_roi, udst_roi, ksize));
|
||||
|
||||
Near(0);
|
||||
}
|
||||
}
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImageProc, MedianFilter, Combine(
|
||||
Values(CV_8U, CV_16U, CV_16S, CV_32F),
|
||||
OCL_ALL_CHANNELS,
|
||||
Values(3, 5),
|
||||
Bool())
|
||||
);
|
||||
} } // namespace opencv_test::ocl
|
||||
|
||||
#endif
|
||||
171
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_pyramids.cpp
vendored
Normal file
171
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_pyramids.cpp
vendored
Normal file
@@ -0,0 +1,171 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// @Authors
|
||||
// Yao Wang yao@multicorewareinc.com
|
||||
//
|
||||
// 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/ts/ocl_test.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
namespace opencv_test {
|
||||
namespace ocl {
|
||||
|
||||
PARAM_TEST_CASE(PyrTestBase, MatDepth, Channels, BorderType, bool)
|
||||
{
|
||||
int depth, channels, borderType;
|
||||
bool use_roi;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(dst);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
depth = GET_PARAM(0);
|
||||
channels = GET_PARAM(1);
|
||||
borderType = GET_PARAM(2);
|
||||
use_roi = GET_PARAM(3);
|
||||
}
|
||||
|
||||
void generateTestData(Size src_roiSize, Size dst_roiSize)
|
||||
{
|
||||
Border srcBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
|
||||
randomSubMat(src, src_roi, src_roiSize, srcBorder, CV_MAKETYPE(depth, channels), -MAX_VALUE, MAX_VALUE);
|
||||
|
||||
Border dstBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
|
||||
randomSubMat(dst, dst_roi, dst_roiSize, dstBorder, CV_MAKETYPE(depth, channels), -MAX_VALUE, MAX_VALUE);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
}
|
||||
|
||||
void Near(double threshold = 0.0)
|
||||
{
|
||||
OCL_EXPECT_MATS_NEAR(dst, threshold);
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////// PyrDown //////////////////////////
|
||||
|
||||
typedef PyrTestBase PyrDown;
|
||||
|
||||
OCL_TEST_P(PyrDown, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
Size src_roiSize = randomSize(1, MAX_VALUE);
|
||||
Size dst_roiSize = Size(randomInt((src_roiSize.width - 1) / 2, (src_roiSize.width + 3) / 2),
|
||||
randomInt((src_roiSize.height - 1) / 2, (src_roiSize.height + 3) / 2));
|
||||
dst_roiSize = dst_roiSize.empty() ? Size((src_roiSize.width + 1) / 2, (src_roiSize.height + 1) / 2) : dst_roiSize;
|
||||
generateTestData(src_roiSize, dst_roiSize);
|
||||
|
||||
OCL_OFF(pyrDown(src_roi, dst_roi, dst_roiSize, borderType));
|
||||
OCL_ON(pyrDown(usrc_roi, udst_roi, dst_roiSize, borderType));
|
||||
|
||||
Near(depth == CV_32F ? 1e-4f : 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImgprocPyr, PyrDown, Combine(
|
||||
Values(CV_8U, CV_16U, CV_16S, CV_32F, CV_64F),
|
||||
Values(1, 2, 3, 4),
|
||||
Values((BorderType)BORDER_REPLICATE,
|
||||
(BorderType)BORDER_REFLECT, (BorderType)BORDER_REFLECT_101),
|
||||
Bool()
|
||||
));
|
||||
|
||||
/////////////////////// PyrUp //////////////////////////
|
||||
|
||||
typedef PyrTestBase PyrUp;
|
||||
|
||||
OCL_TEST_P(PyrUp, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
Size src_roiSize = randomSize(1, MAX_VALUE);
|
||||
Size dst_roiSize = Size(2 * src_roiSize.width, 2 * src_roiSize.height);
|
||||
generateTestData(src_roiSize, dst_roiSize);
|
||||
|
||||
OCL_OFF(pyrUp(src_roi, dst_roi, dst_roiSize, borderType));
|
||||
OCL_ON(pyrUp(usrc_roi, udst_roi, dst_roiSize, borderType));
|
||||
|
||||
Near(depth == CV_32F ? 1e-4f : 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
typedef PyrTestBase PyrUp_cols2;
|
||||
|
||||
OCL_TEST_P(PyrUp_cols2, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
Size src_roiSize = randomSize(1, MAX_VALUE);
|
||||
src_roiSize.width += (src_roiSize.width % 2);
|
||||
Size dst_roiSize = Size(2 * src_roiSize.width, 2 * src_roiSize.height);
|
||||
generateTestData(src_roiSize, dst_roiSize);
|
||||
|
||||
OCL_OFF(pyrUp(src_roi, dst_roi, dst_roiSize, borderType));
|
||||
OCL_ON(pyrUp(usrc_roi, udst_roi, dst_roiSize, borderType));
|
||||
|
||||
Near(depth == CV_32F ? 1e-4f : 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImgprocPyr, PyrUp, Combine(
|
||||
Values(CV_8U, CV_16U, CV_16S, CV_32F, CV_64F),
|
||||
Values(1, 2, 3, 4),
|
||||
Values((BorderType)BORDER_REFLECT_101),
|
||||
Bool()
|
||||
));
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImgprocPyr, PyrUp_cols2, Combine(
|
||||
Values((MatDepth)CV_8U),
|
||||
Values((Channels)1),
|
||||
Values((BorderType)BORDER_REFLECT_101),
|
||||
Bool()
|
||||
));
|
||||
|
||||
} } // namespace opencv_test::ocl
|
||||
|
||||
#endif // HAVE_OPENCL
|
||||
168
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_sepfilter2d.cpp
vendored
Normal file
168
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_sepfilter2d.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) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Copyright (C) 2010-2012, Multicoreware, 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/ts/ocl_test.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
namespace opencv_test {
|
||||
namespace ocl {
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// sepFilter2D
|
||||
PARAM_TEST_CASE(SepFilter2D, MatDepth, Channels, BorderType, bool, bool)
|
||||
{
|
||||
static const int kernelMinSize = 2;
|
||||
static const int kernelMaxSize = 10;
|
||||
|
||||
int type;
|
||||
Point anchor;
|
||||
int borderType;
|
||||
bool useRoi;
|
||||
Mat kernelX, kernelY;
|
||||
double delta;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(dst);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
type = CV_MAKE_TYPE(GET_PARAM(0), GET_PARAM(1));
|
||||
borderType = GET_PARAM(2) | (GET_PARAM(3) ? BORDER_ISOLATED : 0);
|
||||
useRoi = GET_PARAM(4);
|
||||
}
|
||||
|
||||
void random_roi(bool bitExact)
|
||||
{
|
||||
Size ksize = randomSize(kernelMinSize, kernelMaxSize);
|
||||
if (1 != ksize.width % 2)
|
||||
ksize.width++;
|
||||
if (1 != ksize.height % 2)
|
||||
ksize.height++;
|
||||
|
||||
Mat temp = randomMat(Size(ksize.width, 1), CV_32FC1, -0.5, 1.0);
|
||||
cv::normalize(temp, kernelX, 1.0, 0.0, NORM_L1);
|
||||
temp = randomMat(Size(1, ksize.height), CV_32FC1, -0.5, 1.0);
|
||||
cv::normalize(temp, kernelY, 1.0, 0.0, NORM_L1);
|
||||
|
||||
if (bitExact)
|
||||
{
|
||||
kernelX.convertTo(temp, CV_32S, 256);
|
||||
temp.convertTo(kernelX, CV_32F, 1.0 / 256);
|
||||
kernelY.convertTo(temp, CV_32S, 256);
|
||||
temp.convertTo(kernelY, CV_32F, 1.0 / 256);
|
||||
}
|
||||
|
||||
Size roiSize = randomSize(ksize.width, MAX_VALUE, ksize.height, MAX_VALUE);
|
||||
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(src, src_roi, roiSize, srcBorder, type, -MAX_VALUE, MAX_VALUE);
|
||||
|
||||
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(dst, dst_roi, roiSize, dstBorder, type, -MAX_VALUE, MAX_VALUE);
|
||||
|
||||
anchor.x = anchor.y = -1;
|
||||
delta = randomDouble(-100, 100);
|
||||
|
||||
if (bitExact)
|
||||
{
|
||||
delta = (int)(delta * 256) / 256.0;
|
||||
}
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
}
|
||||
|
||||
void Near(double threshold = 0.0)
|
||||
{
|
||||
OCL_EXPECT_MATS_NEAR(dst, threshold);
|
||||
}
|
||||
};
|
||||
|
||||
OCL_TEST_P(SepFilter2D, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times + 3; j++)
|
||||
{
|
||||
random_roi(false);
|
||||
|
||||
OCL_OFF(cv::sepFilter2D(src_roi, dst_roi, -1, kernelX, kernelY, anchor, delta, borderType));
|
||||
OCL_ON(cv::sepFilter2D(usrc_roi, udst_roi, -1, kernelX, kernelY, anchor, delta, borderType));
|
||||
|
||||
Near(1.0);
|
||||
}
|
||||
}
|
||||
|
||||
OCL_TEST_P(SepFilter2D, Mat_BitExact)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times + 3; j++)
|
||||
{
|
||||
random_roi(true);
|
||||
|
||||
OCL_OFF(cv::sepFilter2D(src_roi, dst_roi, -1, kernelX, kernelY, anchor, delta, borderType));
|
||||
OCL_ON(cv::sepFilter2D(usrc_roi, udst_roi, -1, kernelX, kernelY, anchor, delta, borderType));
|
||||
|
||||
if (src_roi.depth() < CV_32F)
|
||||
Near(0.0);
|
||||
else
|
||||
Near(1e-3);
|
||||
}
|
||||
}
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImageProc, SepFilter2D,
|
||||
Combine(
|
||||
Values(CV_8U, CV_32F),
|
||||
OCL_ALL_CHANNELS,
|
||||
Values(
|
||||
(BorderType)BORDER_CONSTANT,
|
||||
(BorderType)BORDER_REPLICATE,
|
||||
(BorderType)BORDER_REFLECT,
|
||||
(BorderType)BORDER_REFLECT_101),
|
||||
Bool(), // BORDER_ISOLATED
|
||||
Bool() // ROI
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
} } // namespace opencv_test::ocl
|
||||
|
||||
#endif // HAVE_OPENCL
|
||||
506
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_warp.cpp
vendored
Normal file
506
3rdparty/opencv-4.5.4/modules/imgproc/test/ocl/test_warp.cpp
vendored
Normal file
@@ -0,0 +1,506 @@
|
||||
/*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) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// @Authors
|
||||
// Niko Li, newlife20080214@gmail.com
|
||||
// Jia Haipeng, jiahaipeng95@gmail.com
|
||||
// Shengen Yan, yanshengen@gmail.com
|
||||
// Jiang Liyuan, lyuan001.good@163.com
|
||||
// Rock Li, Rock.Li@amd.com
|
||||
// Wu Zailong, bullet@yeah.net
|
||||
// Xu Pang, pangxu010@163.com
|
||||
// Sen Liu, swjtuls1987@126.com
|
||||
//
|
||||
// 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/ts/ocl_test.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
namespace opencv_test {
|
||||
namespace ocl {
|
||||
|
||||
enum
|
||||
{
|
||||
noType = -1
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// warpAffine & warpPerspective
|
||||
|
||||
PARAM_TEST_CASE(WarpTestBase, MatType, Interpolation, bool, bool)
|
||||
{
|
||||
int type, interpolation;
|
||||
Size dsize;
|
||||
bool useRoi, mapInverse;
|
||||
int depth;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(dst);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
type = GET_PARAM(0);
|
||||
interpolation = GET_PARAM(1);
|
||||
mapInverse = GET_PARAM(2);
|
||||
useRoi = GET_PARAM(3);
|
||||
depth = CV_MAT_DEPTH(type);
|
||||
|
||||
if (mapInverse)
|
||||
interpolation |= WARP_INVERSE_MAP;
|
||||
}
|
||||
|
||||
void random_roi()
|
||||
{
|
||||
dsize = randomSize(1, MAX_VALUE);
|
||||
|
||||
Size roiSize = randomSize(1, MAX_VALUE);
|
||||
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(src, src_roi, roiSize, srcBorder, type, -MAX_VALUE, MAX_VALUE);
|
||||
|
||||
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(dst, dst_roi, dsize, dstBorder, type, -MAX_VALUE, MAX_VALUE);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
}
|
||||
|
||||
void Near(double threshold = 0.0)
|
||||
{
|
||||
if (depth < CV_32F)
|
||||
EXPECT_MAT_N_DIFF(dst_roi, udst_roi, cvRound(dst_roi.total()*threshold));
|
||||
else
|
||||
OCL_EXPECT_MATS_NEAR_RELATIVE(dst, threshold);
|
||||
}
|
||||
};
|
||||
|
||||
PARAM_TEST_CASE(WarpTest_cols4_Base, MatType, Interpolation, bool, bool)
|
||||
{
|
||||
int type, interpolation;
|
||||
Size dsize;
|
||||
bool useRoi, mapInverse;
|
||||
int depth;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(dst);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
type = GET_PARAM(0);
|
||||
interpolation = GET_PARAM(1);
|
||||
mapInverse = GET_PARAM(2);
|
||||
useRoi = GET_PARAM(3);
|
||||
depth = CV_MAT_DEPTH(type);
|
||||
|
||||
if (mapInverse)
|
||||
interpolation |= WARP_INVERSE_MAP;
|
||||
}
|
||||
|
||||
void random_roi()
|
||||
{
|
||||
dsize = randomSize(1, MAX_VALUE);
|
||||
dsize.width = ((dsize.width >> 2) + 1) * 4;
|
||||
|
||||
Size roiSize = randomSize(1, MAX_VALUE);
|
||||
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(src, src_roi, roiSize, srcBorder, type, -MAX_VALUE, MAX_VALUE);
|
||||
|
||||
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(dst, dst_roi, dsize, dstBorder, type, -MAX_VALUE, MAX_VALUE);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
}
|
||||
|
||||
void Near(double threshold = 0.0)
|
||||
{
|
||||
if (depth < CV_32F)
|
||||
EXPECT_MAT_N_DIFF(dst_roi, udst_roi, cvRound(dst_roi.total()*threshold));
|
||||
else
|
||||
OCL_EXPECT_MATS_NEAR_RELATIVE(dst, threshold);
|
||||
}
|
||||
};
|
||||
|
||||
/////warpAffine
|
||||
|
||||
typedef WarpTestBase WarpAffine;
|
||||
|
||||
/////warpAffine
|
||||
|
||||
typedef WarpTestBase WarpAffine;
|
||||
|
||||
OCL_TEST_P(WarpAffine, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
double eps = depth < CV_32F ? 0.04 : 0.06;
|
||||
random_roi();
|
||||
|
||||
Mat M = getRotationMatrix2D(Point2f(src_roi.cols / 2.0f, src_roi.rows / 2.0f),
|
||||
rng.uniform(-180.f, 180.f), rng.uniform(0.4f, 2.0f));
|
||||
|
||||
OCL_OFF(cv::warpAffine(src_roi, dst_roi, M, dsize, interpolation));
|
||||
OCL_ON(cv::warpAffine(usrc_roi, udst_roi, M, dsize, interpolation));
|
||||
|
||||
Near(eps);
|
||||
}
|
||||
}
|
||||
|
||||
typedef WarpTest_cols4_Base WarpAffine_cols4;
|
||||
|
||||
OCL_TEST_P(WarpAffine_cols4, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
double eps = depth < CV_32F ? 0.04 : 0.06;
|
||||
random_roi();
|
||||
|
||||
Mat M = getRotationMatrix2D(Point2f(src_roi.cols / 2.0f, src_roi.rows / 2.0f),
|
||||
rng.uniform(-180.f, 180.f), rng.uniform(0.4f, 2.0f));
|
||||
|
||||
OCL_OFF(cv::warpAffine(src_roi, dst_roi, M, dsize, interpolation));
|
||||
OCL_ON(cv::warpAffine(usrc_roi, udst_roi, M, dsize, interpolation));
|
||||
|
||||
Near(eps);
|
||||
}
|
||||
}
|
||||
|
||||
//// warpPerspective
|
||||
|
||||
typedef WarpTestBase WarpPerspective;
|
||||
|
||||
OCL_TEST_P(WarpPerspective, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
double eps = depth < CV_32F ? 0.03 : 0.06;
|
||||
random_roi();
|
||||
|
||||
float cols = static_cast<float>(src_roi.cols), rows = static_cast<float>(src_roi.rows);
|
||||
float cols2 = cols / 2.0f, rows2 = rows / 2.0f;
|
||||
Point2f sp[] = { Point2f(0.0f, 0.0f), Point2f(cols, 0.0f), Point2f(0.0f, rows), Point2f(cols, rows) };
|
||||
Point2f dp[] = { Point2f(rng.uniform(0.0f, cols2), rng.uniform(0.0f, rows2)),
|
||||
Point2f(rng.uniform(cols2, cols), rng.uniform(0.0f, rows2)),
|
||||
Point2f(rng.uniform(0.0f, cols2), rng.uniform(rows2, rows)),
|
||||
Point2f(rng.uniform(cols2, cols), rng.uniform(rows2, rows)) };
|
||||
Mat M = getPerspectiveTransform(sp, dp);
|
||||
|
||||
OCL_OFF(cv::warpPerspective(src_roi, dst_roi, M, dsize, interpolation));
|
||||
OCL_ON(cv::warpPerspective(usrc_roi, udst_roi, M, dsize, interpolation));
|
||||
|
||||
Near(eps);
|
||||
}
|
||||
}
|
||||
|
||||
typedef WarpTest_cols4_Base WarpPerspective_cols4;
|
||||
|
||||
OCL_TEST_P(WarpPerspective_cols4, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
double eps = depth < CV_32F ? 0.03 : 0.06;
|
||||
random_roi();
|
||||
|
||||
float cols = static_cast<float>(src_roi.cols), rows = static_cast<float>(src_roi.rows);
|
||||
float cols2 = cols / 2.0f, rows2 = rows / 2.0f;
|
||||
Point2f sp[] = { Point2f(0.0f, 0.0f), Point2f(cols, 0.0f), Point2f(0.0f, rows), Point2f(cols, rows) };
|
||||
Point2f dp[] = { Point2f(rng.uniform(0.0f, cols2), rng.uniform(0.0f, rows2)),
|
||||
Point2f(rng.uniform(cols2, cols), rng.uniform(0.0f, rows2)),
|
||||
Point2f(rng.uniform(0.0f, cols2), rng.uniform(rows2, rows)),
|
||||
Point2f(rng.uniform(cols2, cols), rng.uniform(rows2, rows)) };
|
||||
Mat M = getPerspectiveTransform(sp, dp);
|
||||
|
||||
OCL_OFF(cv::warpPerspective(src_roi, dst_roi, M, dsize, interpolation));
|
||||
OCL_ON(cv::warpPerspective(usrc_roi, udst_roi, M, dsize, interpolation));
|
||||
|
||||
Near(eps);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//// resize
|
||||
|
||||
PARAM_TEST_CASE(Resize, MatType, double, double, Interpolation, bool, int)
|
||||
{
|
||||
int type, interpolation;
|
||||
int widthMultiple;
|
||||
double fx, fy;
|
||||
bool useRoi;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(dst);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
type = GET_PARAM(0);
|
||||
fx = GET_PARAM(1);
|
||||
fy = GET_PARAM(2);
|
||||
interpolation = GET_PARAM(3);
|
||||
useRoi = GET_PARAM(4);
|
||||
widthMultiple = GET_PARAM(5);
|
||||
}
|
||||
|
||||
void random_roi()
|
||||
{
|
||||
CV_Assert(fx > 0 && fy > 0);
|
||||
|
||||
Size srcRoiSize = randomSize(10, MAX_VALUE), dstRoiSize;
|
||||
// Make sure the width is a multiple of the requested value, and no more
|
||||
srcRoiSize.width += widthMultiple - 1 - (srcRoiSize.width - 1) % widthMultiple;
|
||||
dstRoiSize.width = cvRound(srcRoiSize.width * fx);
|
||||
dstRoiSize.height = cvRound(srcRoiSize.height * fy);
|
||||
|
||||
if (dstRoiSize.empty())
|
||||
{
|
||||
random_roi();
|
||||
return;
|
||||
}
|
||||
|
||||
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(src, src_roi, srcRoiSize, srcBorder, type, -MAX_VALUE, MAX_VALUE);
|
||||
|
||||
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(dst, dst_roi, dstRoiSize, dstBorder, type, -MAX_VALUE, MAX_VALUE);
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(__aarch64__) || defined(__arm__)
|
||||
const int integerEps = 3;
|
||||
#else
|
||||
const int integerEps = 1;
|
||||
#endif
|
||||
OCL_TEST_P(Resize, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
int depth = CV_MAT_DEPTH(type);
|
||||
double eps = depth <= CV_32S ? integerEps : 5e-2;
|
||||
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::resize(src_roi, dst_roi, Size(), fx, fy, interpolation));
|
||||
OCL_ON(cv::resize(usrc_roi, udst_roi, Size(), fx, fy, interpolation));
|
||||
|
||||
OCL_EXPECT_MAT_N_DIFF(dst, eps);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// remap
|
||||
|
||||
PARAM_TEST_CASE(Remap, MatDepth, Channels, std::pair<MatType, MatType>, BorderType, bool)
|
||||
{
|
||||
int srcType, map1Type, map2Type;
|
||||
int borderType;
|
||||
bool useRoi;
|
||||
|
||||
Scalar val;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src);
|
||||
TEST_DECLARE_INPUT_PARAMETER(map1);
|
||||
TEST_DECLARE_INPUT_PARAMETER(map2);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(dst);
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
srcType = CV_MAKE_TYPE(GET_PARAM(0), GET_PARAM(1));
|
||||
map1Type = GET_PARAM(2).first;
|
||||
map2Type = GET_PARAM(2).second;
|
||||
borderType = GET_PARAM(3);
|
||||
useRoi = GET_PARAM(4);
|
||||
}
|
||||
|
||||
void random_roi()
|
||||
{
|
||||
val = randomScalar(-MAX_VALUE, MAX_VALUE);
|
||||
Size srcROISize = randomSize(1, MAX_VALUE);
|
||||
Size dstROISize = randomSize(1, MAX_VALUE);
|
||||
|
||||
Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(src, src_roi, srcROISize, srcBorder, srcType, 5, 256);
|
||||
|
||||
Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(dst, dst_roi, dstROISize, dstBorder, srcType, -MAX_VALUE, MAX_VALUE);
|
||||
|
||||
int mapMaxValue = MAX_VALUE << 2;
|
||||
Border map1Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
|
||||
randomSubMat(map1, map1_roi, dstROISize, map1Border, map1Type, -mapMaxValue, mapMaxValue);
|
||||
|
||||
Border map2Border = randomBorder(0, useRoi ? MAX_VALUE + 1 : 0);
|
||||
if (map2Type != noType)
|
||||
{
|
||||
int mapMinValue = -mapMaxValue;
|
||||
if (map2Type == CV_16UC1 || map2Type == CV_16SC1)
|
||||
mapMinValue = 0, mapMaxValue = INTER_TAB_SIZE2;
|
||||
randomSubMat(map2, map2_roi, dstROISize, map2Border, map2Type, mapMinValue, mapMaxValue);
|
||||
}
|
||||
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(src);
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(map1);
|
||||
UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
|
||||
if (noType != map2Type)
|
||||
UMAT_UPLOAD_INPUT_PARAMETER(map2);
|
||||
}
|
||||
};
|
||||
|
||||
typedef Remap Remap_INTER_NEAREST;
|
||||
|
||||
OCL_TEST_P(Remap_INTER_NEAREST, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
OCL_OFF(cv::remap(src_roi, dst_roi, map1_roi, map2_roi, INTER_NEAREST, borderType, val));
|
||||
OCL_ON(cv::remap(usrc_roi, udst_roi, umap1_roi, umap2_roi, INTER_NEAREST, borderType, val));
|
||||
|
||||
OCL_EXPECT_MAT_N_DIFF(dst, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
typedef Remap Remap_INTER_LINEAR;
|
||||
|
||||
OCL_TEST_P(Remap_INTER_LINEAR, Mat)
|
||||
{
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
{
|
||||
random_roi();
|
||||
|
||||
double eps = 2.0;
|
||||
#ifdef __ANDROID__
|
||||
// TODO investigate accuracy
|
||||
if (cv::ocl::Device::getDefault().isNVidia())
|
||||
eps = 8.0;
|
||||
#elif defined(__arm__)
|
||||
eps = 8.0;
|
||||
#endif
|
||||
|
||||
OCL_OFF(cv::remap(src_roi, dst_roi, map1_roi, map2_roi, INTER_LINEAR, borderType, val));
|
||||
OCL_ON(cv::remap(usrc_roi, udst_roi, umap1_roi, umap2_roi, INTER_LINEAR, borderType, val));
|
||||
|
||||
OCL_EXPECT_MAT_N_DIFF(dst, eps);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, WarpAffine, Combine(
|
||||
Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4),
|
||||
Values((Interpolation)INTER_NEAREST, (Interpolation)INTER_LINEAR, (Interpolation)INTER_CUBIC),
|
||||
Bool(),
|
||||
Bool()));
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, WarpAffine_cols4, Combine(
|
||||
Values((MatType)CV_8UC1),
|
||||
Values((Interpolation)INTER_NEAREST, (Interpolation)INTER_LINEAR, (Interpolation)INTER_CUBIC),
|
||||
Bool(),
|
||||
Bool()));
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, WarpPerspective, Combine(
|
||||
Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC3, CV_32FC4),
|
||||
Values((Interpolation)INTER_NEAREST, (Interpolation)INTER_LINEAR, (Interpolation)INTER_CUBIC),
|
||||
Bool(),
|
||||
Bool()));
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, WarpPerspective_cols4, Combine(
|
||||
Values((MatType)CV_8UC1),
|
||||
Values((Interpolation)INTER_NEAREST, (Interpolation)INTER_LINEAR, (Interpolation)INTER_CUBIC),
|
||||
Bool(),
|
||||
Bool()));
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, Resize, Combine(
|
||||
Values(CV_8UC1, CV_8UC4, CV_16UC2, CV_32FC1, CV_32FC4),
|
||||
Values(0.5, 1.5, 2.0, 0.2),
|
||||
Values(0.5, 1.5, 2.0, 0.2),
|
||||
Values((Interpolation)INTER_NEAREST, (Interpolation)INTER_LINEAR),
|
||||
Bool(),
|
||||
Values(1, 16)));
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarpLinearExact, Resize, Combine(
|
||||
Values(CV_8UC1, CV_8UC4, CV_16UC2),
|
||||
Values(0.5, 1.5, 2.0, 0.2),
|
||||
Values(0.5, 1.5, 2.0, 0.2),
|
||||
Values((Interpolation)INTER_LINEAR_EXACT),
|
||||
Bool(),
|
||||
Values(1, 16)));
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarpResizeArea, Resize, Combine(
|
||||
Values((MatType)CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4),
|
||||
Values(0.7, 0.4, 0.5),
|
||||
Values(0.3, 0.6, 0.5),
|
||||
Values((Interpolation)INTER_AREA),
|
||||
Bool(),
|
||||
Values(1, 16)));
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, Remap_INTER_LINEAR, Combine(
|
||||
Values(CV_8U, CV_16U, CV_32F),
|
||||
Values(1, 3, 4),
|
||||
Values(std::pair<MatType, MatType>((MatType)CV_32FC1, (MatType)CV_32FC1),
|
||||
std::pair<MatType, MatType>((MatType)CV_16SC2, (MatType)CV_16UC1),
|
||||
std::pair<MatType, MatType>((MatType)CV_32FC2, noType)),
|
||||
Values((BorderType)BORDER_CONSTANT,
|
||||
(BorderType)BORDER_REPLICATE,
|
||||
(BorderType)BORDER_WRAP,
|
||||
(BorderType)BORDER_REFLECT,
|
||||
(BorderType)BORDER_REFLECT_101),
|
||||
Bool()));
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(ImgprocWarp, Remap_INTER_NEAREST, Combine(
|
||||
Values(CV_8U, CV_16U, CV_32F),
|
||||
Values(1, 3, 4),
|
||||
Values(std::pair<MatType, MatType>((MatType)CV_32FC1, (MatType)CV_32FC1),
|
||||
std::pair<MatType, MatType>((MatType)CV_32FC2, noType),
|
||||
std::pair<MatType, MatType>((MatType)CV_16SC2, (MatType)CV_16UC1),
|
||||
std::pair<MatType, MatType>((MatType)CV_16SC2, noType)),
|
||||
Values((BorderType)BORDER_CONSTANT,
|
||||
(BorderType)BORDER_REPLICATE,
|
||||
(BorderType)BORDER_WRAP,
|
||||
(BorderType)BORDER_REFLECT,
|
||||
(BorderType)BORDER_REFLECT_101),
|
||||
Bool()));
|
||||
|
||||
} } // namespace opencv_test::ocl
|
||||
|
||||
#endif // HAVE_OPENCL
|
||||
379
3rdparty/opencv-4.5.4/modules/imgproc/test/test_approxpoly.cpp
vendored
Normal file
379
3rdparty/opencv-4.5.4/modules/imgproc/test/test_approxpoly.cpp
vendored
Normal file
@@ -0,0 +1,379 @@
|
||||
/*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.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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 {
|
||||
|
||||
//
|
||||
// TODO!!!:
|
||||
// check_slice (and/or check) seem(s) to be broken, or this is a bug in function
|
||||
// (or its inability to handle possible self-intersections in the generated contours).
|
||||
//
|
||||
// At least, if // return TotalErrors;
|
||||
// is uncommented in check_slice, the test fails easily.
|
||||
// So, now (and it looks like since 0.9.6)
|
||||
// we only check that the set of vertices of the approximated polygon is
|
||||
// a subset of vertices of the original contour.
|
||||
//
|
||||
|
||||
class CV_ApproxPolyTest : public cvtest::BaseTest
|
||||
{
|
||||
public:
|
||||
CV_ApproxPolyTest();
|
||||
~CV_ApproxPolyTest();
|
||||
void clear();
|
||||
//int write_default_params(CvFileStorage* fs);
|
||||
|
||||
protected:
|
||||
//int read_params( const cv::FileStorage& fs );
|
||||
|
||||
int check_slice( CvPoint StartPt, CvPoint EndPt,
|
||||
CvSeqReader* SrcReader, float Eps,
|
||||
int* j, int Count );
|
||||
int check( CvSeq* SrcSeq, CvSeq* DstSeq, float Eps );
|
||||
|
||||
bool get_contour( int /*type*/, CvSeq** Seq, int* d,
|
||||
CvMemStorage* storage );
|
||||
|
||||
void run(int);
|
||||
};
|
||||
|
||||
|
||||
CV_ApproxPolyTest::CV_ApproxPolyTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CV_ApproxPolyTest::~CV_ApproxPolyTest()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
void CV_ApproxPolyTest::clear()
|
||||
{
|
||||
cvtest::BaseTest::clear();
|
||||
}
|
||||
|
||||
|
||||
/*int CV_ApproxPolyTest::write_default_params( CvFileStorage* fs )
|
||||
{
|
||||
cvtest::BaseTest::write_default_params( fs );
|
||||
if( ts->get_testing_mode() != cvtest::TS::TIMING_MODE )
|
||||
{
|
||||
write_param( fs, "test_case_count", test_case_count );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int CV_ApproxPolyTest::read_params( const cv::FileStorage& fs )
|
||||
{
|
||||
int code = cvtest::BaseTest::read_params( fs );
|
||||
if( code < 0 )
|
||||
return code;
|
||||
|
||||
test_case_count = cvReadInt( find_param( fs, "test_case_count" ), test_case_count );
|
||||
min_log_size = cvtest::clipInt( min_log_size, 1, 10 );
|
||||
return 0;
|
||||
}*/
|
||||
|
||||
|
||||
bool CV_ApproxPolyTest::get_contour( int /*type*/, CvSeq** Seq, int* d,
|
||||
CvMemStorage* storage )
|
||||
{
|
||||
RNG& rng = ts->get_rng();
|
||||
int max_x = INT_MIN, max_y = INT_MIN, min_x = INT_MAX, min_y = INT_MAX;
|
||||
int i;
|
||||
CvSeq* seq;
|
||||
int total = cvtest::randInt(rng) % 1000 + 1;
|
||||
Point center;
|
||||
int radius, angle;
|
||||
double deg_to_rad = CV_PI/180.;
|
||||
Point pt;
|
||||
|
||||
center.x = cvtest::randInt( rng ) % 1000;
|
||||
center.y = cvtest::randInt( rng ) % 1000;
|
||||
radius = cvtest::randInt( rng ) % 1000;
|
||||
angle = cvtest::randInt( rng ) % 360;
|
||||
|
||||
seq = cvCreateSeq( CV_SEQ_POLYGON, sizeof(CvContour), sizeof(CvPoint), storage );
|
||||
|
||||
for( i = 0; i < total; i++ )
|
||||
{
|
||||
int d_radius = cvtest::randInt( rng ) % 10 - 5;
|
||||
int d_angle = 360/total;//cvtest::randInt( rng ) % 10 - 5;
|
||||
pt.x = cvRound( center.x + radius*cos(angle*deg_to_rad));
|
||||
pt.y = cvRound( center.x - radius*sin(angle*deg_to_rad));
|
||||
radius += d_radius;
|
||||
angle += d_angle;
|
||||
cvSeqPush( seq, &pt );
|
||||
|
||||
max_x = MAX( max_x, pt.x );
|
||||
max_y = MAX( max_y, pt.y );
|
||||
|
||||
min_x = MIN( min_x, pt.x );
|
||||
min_y = MIN( min_y, pt.y );
|
||||
}
|
||||
|
||||
*d = (max_x - min_x)*(max_x - min_x) + (max_y - min_y)*(max_y - min_y);
|
||||
*Seq = seq;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int CV_ApproxPolyTest::check_slice( CvPoint StartPt, CvPoint EndPt,
|
||||
CvSeqReader* SrcReader, float Eps,
|
||||
int* _j, int Count )
|
||||
{
|
||||
///////////
|
||||
Point Pt;
|
||||
///////////
|
||||
bool flag;
|
||||
double dy,dx;
|
||||
double A,B,C;
|
||||
double Sq;
|
||||
double sin_a = 0;
|
||||
double cos_a = 0;
|
||||
double d = 0;
|
||||
double dist;
|
||||
///////////
|
||||
int j, TotalErrors = 0;
|
||||
|
||||
////////////////////////////////
|
||||
if( SrcReader == NULL )
|
||||
{
|
||||
assert( false );
|
||||
return 0;
|
||||
}
|
||||
|
||||
///////// init line ////////////
|
||||
flag = true;
|
||||
|
||||
dx = (double)StartPt.x - (double)EndPt.x;
|
||||
dy = (double)StartPt.y - (double)EndPt.y;
|
||||
|
||||
if( ( dx == 0 ) && ( dy == 0 ) ) flag = false;
|
||||
else
|
||||
{
|
||||
A = -dy;
|
||||
B = dx;
|
||||
C = dy * (double)StartPt.x - dx * (double)StartPt.y;
|
||||
Sq = sqrt( A*A + B*B );
|
||||
|
||||
sin_a = B/Sq;
|
||||
cos_a = A/Sq;
|
||||
d = C/Sq;
|
||||
}
|
||||
|
||||
/////// find start point and check distance ////////
|
||||
for( j = *_j; j < Count; j++ )
|
||||
{
|
||||
{ CvPoint pt_ = CV_STRUCT_INITIALIZER; CV_READ_SEQ_ELEM(pt_, *SrcReader); Pt = pt_; }
|
||||
if( StartPt.x == Pt.x && StartPt.y == Pt.y ) break;
|
||||
else
|
||||
{
|
||||
if( flag ) dist = sin_a * Pt.y + cos_a * Pt.x - d;
|
||||
else dist = sqrt( (double)(EndPt.y - Pt.y)*(EndPt.y - Pt.y) + (EndPt.x - Pt.x)*(EndPt.x - Pt.x) );
|
||||
if( dist > Eps ) TotalErrors++;
|
||||
}
|
||||
}
|
||||
|
||||
*_j = j;
|
||||
|
||||
//return TotalErrors;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int CV_ApproxPolyTest::check( CvSeq* SrcSeq, CvSeq* DstSeq, float Eps )
|
||||
{
|
||||
//////////
|
||||
CvSeqReader DstReader;
|
||||
CvSeqReader SrcReader;
|
||||
CvPoint StartPt = {0, 0}, EndPt = {0, 0};
|
||||
///////////
|
||||
int TotalErrors = 0;
|
||||
///////////
|
||||
int Count;
|
||||
int i,j;
|
||||
|
||||
assert( SrcSeq && DstSeq );
|
||||
|
||||
////////// init ////////////////////
|
||||
Count = SrcSeq->total;
|
||||
|
||||
cvStartReadSeq( DstSeq, &DstReader, 0 );
|
||||
cvStartReadSeq( SrcSeq, &SrcReader, 0 );
|
||||
|
||||
CV_READ_SEQ_ELEM( StartPt, DstReader );
|
||||
for( i = 0 ; i < Count ; )
|
||||
{
|
||||
CV_READ_SEQ_ELEM( EndPt, SrcReader );
|
||||
i++;
|
||||
if( StartPt.x == EndPt.x && StartPt.y == EndPt.y ) break;
|
||||
}
|
||||
|
||||
///////// start ////////////////
|
||||
for( i = 1, j = 0 ; i <= DstSeq->total ; )
|
||||
{
|
||||
///////// read slice ////////////
|
||||
EndPt.x = StartPt.x;
|
||||
EndPt.y = StartPt.y;
|
||||
CV_READ_SEQ_ELEM( StartPt, DstReader );
|
||||
i++;
|
||||
|
||||
TotalErrors += check_slice( StartPt, EndPt, &SrcReader, Eps, &j, Count );
|
||||
|
||||
if( j > Count )
|
||||
{
|
||||
TotalErrors++;
|
||||
return TotalErrors;
|
||||
} //if( !flag )
|
||||
|
||||
} // for( int i = 0 ; i < DstSeq->total ; i++ )
|
||||
|
||||
return TotalErrors;
|
||||
}
|
||||
|
||||
|
||||
//extern CvTestContourGenerator cvTsTestContours[];
|
||||
|
||||
void CV_ApproxPolyTest::run( int /*start_from*/ )
|
||||
{
|
||||
int code = cvtest::TS::OK;
|
||||
CvMemStorage* storage = 0;
|
||||
////////////// Variables ////////////////
|
||||
int IntervalsCount = 10;
|
||||
///////////
|
||||
//CvTestContourGenerator Cont;
|
||||
CvSeq* SrcSeq = NULL;
|
||||
CvSeq* DstSeq;
|
||||
int iDiam;
|
||||
float dDiam, Eps, EpsStep;
|
||||
|
||||
for( int i = 0; i < 30; i++ )
|
||||
{
|
||||
CvMemStoragePos pos;
|
||||
|
||||
ts->update_context( this, i, false );
|
||||
|
||||
///////////////////// init contour /////////
|
||||
dDiam = 0;
|
||||
while( sqrt(dDiam) / IntervalsCount == 0 )
|
||||
{
|
||||
if( storage != 0 )
|
||||
cvReleaseMemStorage(&storage);
|
||||
|
||||
storage = cvCreateMemStorage( 0 );
|
||||
if( get_contour( 0, &SrcSeq, &iDiam, storage ) )
|
||||
dDiam = (float)iDiam;
|
||||
}
|
||||
dDiam = (float)sqrt( dDiam );
|
||||
|
||||
storage = SrcSeq->storage;
|
||||
|
||||
////////////////// test /////////////
|
||||
EpsStep = dDiam / IntervalsCount ;
|
||||
for( Eps = EpsStep ; Eps < dDiam ; Eps += EpsStep )
|
||||
{
|
||||
cvSaveMemStoragePos( storage, &pos );
|
||||
|
||||
////////// call function ////////////
|
||||
DstSeq = cvApproxPoly( SrcSeq, SrcSeq->header_size, storage,
|
||||
CV_POLY_APPROX_DP, Eps );
|
||||
|
||||
if( DstSeq == NULL )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG,
|
||||
"cvApproxPoly returned NULL for contour #%d, epsilon = %g\n", i, Eps );
|
||||
code = cvtest::TS::FAIL_INVALID_OUTPUT;
|
||||
goto _exit_;
|
||||
} // if( DstSeq == NULL )
|
||||
|
||||
code = check( SrcSeq, DstSeq, Eps );
|
||||
if( code != 0 )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG,
|
||||
"Incorrect result for the contour #%d approximated with epsilon=%g\n", i, Eps );
|
||||
code = cvtest::TS::FAIL_BAD_ACCURACY;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
cvRestoreMemStoragePos( storage, &pos );
|
||||
} // for( Eps = EpsStep ; Eps <= Diam ; Eps += EpsStep )
|
||||
|
||||
///////////// free memory ///////////////////
|
||||
cvReleaseMemStorage(&storage);
|
||||
} // for( int i = 0; NULL != ( Cont = Contours[i] ) ; i++ )
|
||||
|
||||
_exit_:
|
||||
cvReleaseMemStorage(&storage);
|
||||
|
||||
if( code < 0 )
|
||||
ts->set_failed_test_info( code );
|
||||
}
|
||||
|
||||
TEST(Imgproc_ApproxPoly, accuracy) { CV_ApproxPolyTest test; test.safe_run(); }
|
||||
|
||||
//Tests to make sure that unreasonable epsilon (error)
|
||||
//values never get passed to the Douglas-Peucker algorithm.
|
||||
TEST(Imgproc_ApproxPoly, bad_epsilon)
|
||||
{
|
||||
std::vector<Point2f> inputPoints;
|
||||
inputPoints.push_back(Point2f(0.0f, 0.0f));
|
||||
std::vector<Point2f> outputPoints;
|
||||
|
||||
double eps = std::numeric_limits<double>::infinity();
|
||||
ASSERT_ANY_THROW(approxPolyDP(inputPoints, outputPoints, eps, false));
|
||||
|
||||
eps = 9e99;
|
||||
ASSERT_ANY_THROW(approxPolyDP(inputPoints, outputPoints, eps, false));
|
||||
|
||||
eps = -1e-6;
|
||||
ASSERT_ANY_THROW(approxPolyDP(inputPoints, outputPoints, eps, false));
|
||||
|
||||
eps = NAN;
|
||||
ASSERT_ANY_THROW(approxPolyDP(inputPoints, outputPoints, eps, false));
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
292
3rdparty/opencv-4.5.4/modules/imgproc/test/test_bilateral_filter.cpp
vendored
Normal file
292
3rdparty/opencv-4.5.4/modules/imgproc/test/test_bilateral_filter.cpp
vendored
Normal file
@@ -0,0 +1,292 @@
|
||||
/*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_BilateralFilterTest :
|
||||
public cvtest::BaseTest
|
||||
{
|
||||
public:
|
||||
enum
|
||||
{
|
||||
MAX_WIDTH = 1920, MIN_WIDTH = 1,
|
||||
MAX_HEIGHT = 1080, MIN_HEIGHT = 1
|
||||
};
|
||||
|
||||
CV_BilateralFilterTest();
|
||||
~CV_BilateralFilterTest();
|
||||
|
||||
protected:
|
||||
virtual void run_func();
|
||||
virtual int prepare_test_case(int test_case_index);
|
||||
virtual int validate_test_results(int test_case_index);
|
||||
|
||||
private:
|
||||
void reference_bilateral_filter(const Mat& src, Mat& dst, int d, double sigma_color,
|
||||
double sigma_space, int borderType = BORDER_DEFAULT);
|
||||
|
||||
int getRandInt(RNG& rng, int min_value, int max_value) const;
|
||||
|
||||
double _sigma_color;
|
||||
double _sigma_space;
|
||||
|
||||
Mat _src;
|
||||
Mat _parallel_dst;
|
||||
int _d;
|
||||
};
|
||||
|
||||
CV_BilateralFilterTest::CV_BilateralFilterTest() :
|
||||
cvtest::BaseTest(), _src(), _parallel_dst(), _d()
|
||||
{
|
||||
test_case_count = 1000;
|
||||
}
|
||||
|
||||
CV_BilateralFilterTest::~CV_BilateralFilterTest()
|
||||
{
|
||||
}
|
||||
|
||||
int CV_BilateralFilterTest::getRandInt(RNG& rng, int min_value, int max_value) const
|
||||
{
|
||||
double rand_value = rng.uniform(log((double)min_value), log((double)max_value + 1));
|
||||
return cvRound(exp((double)rand_value));
|
||||
}
|
||||
|
||||
void CV_BilateralFilterTest::reference_bilateral_filter(const Mat &src, Mat &dst, int d,
|
||||
double sigma_color, double sigma_space, int borderType)
|
||||
{
|
||||
int cn = src.channels();
|
||||
int i, j, k, maxk, radius;
|
||||
double minValSrc = -1, maxValSrc = 1;
|
||||
const int kExpNumBinsPerChannel = 1 << 12;
|
||||
int kExpNumBins = 0;
|
||||
float lastExpVal = 1.f;
|
||||
float len, scale_index;
|
||||
Size size = src.size();
|
||||
|
||||
dst.create(size, src.type());
|
||||
|
||||
CV_Assert( (src.type() == CV_32FC1 || src.type() == CV_32FC3) &&
|
||||
src.type() == dst.type() && src.size() == dst.size() &&
|
||||
src.data != dst.data );
|
||||
|
||||
if( sigma_color <= 0 )
|
||||
sigma_color = 1;
|
||||
if( sigma_space <= 0 )
|
||||
sigma_space = 1;
|
||||
|
||||
double gauss_color_coeff = -0.5/(sigma_color*sigma_color);
|
||||
double gauss_space_coeff = -0.5/(sigma_space*sigma_space);
|
||||
|
||||
if( d <= 0 )
|
||||
radius = cvRound(sigma_space*1.5);
|
||||
else
|
||||
radius = d/2;
|
||||
radius = MAX(radius, 1);
|
||||
d = radius*2 + 1;
|
||||
// compute the min/max range for the input image (even if multichannel)
|
||||
|
||||
// TODO cvtest
|
||||
cv::minMaxLoc( src.reshape(1), &minValSrc, &maxValSrc );
|
||||
if(std::abs(minValSrc - maxValSrc) < FLT_EPSILON)
|
||||
{
|
||||
src.copyTo(dst);
|
||||
return;
|
||||
}
|
||||
|
||||
// temporary copy of the image with borders for easy processing
|
||||
Mat temp;
|
||||
cv::copyMakeBorder( src, temp, radius, radius, radius, radius, borderType );
|
||||
cv::patchNaNs(temp);
|
||||
|
||||
// allocate lookup tables
|
||||
vector<float> _space_weight(d*d);
|
||||
vector<int> _space_ofs(d*d);
|
||||
float* space_weight = &_space_weight[0];
|
||||
int* space_ofs = &_space_ofs[0];
|
||||
|
||||
// assign a length which is slightly more than needed
|
||||
len = (float)(maxValSrc - minValSrc) * cn;
|
||||
kExpNumBins = kExpNumBinsPerChannel * cn;
|
||||
vector<float> _expLUT(kExpNumBins+2);
|
||||
float* expLUT = &_expLUT[0];
|
||||
|
||||
scale_index = kExpNumBins/len;
|
||||
|
||||
// initialize the exp LUT
|
||||
for( i = 0; i < kExpNumBins+2; i++ )
|
||||
{
|
||||
if( lastExpVal > 0.f )
|
||||
{
|
||||
double val = i / scale_index;
|
||||
expLUT[i] = (float)std::exp(val * val * gauss_color_coeff);
|
||||
lastExpVal = expLUT[i];
|
||||
}
|
||||
else
|
||||
expLUT[i] = 0.f;
|
||||
}
|
||||
|
||||
// initialize space-related bilateral filter coefficients
|
||||
for( i = -radius, maxk = 0; i <= radius; i++ )
|
||||
for( j = -radius; j <= radius; j++ )
|
||||
{
|
||||
double r = std::sqrt((double)i*i + (double)j*j);
|
||||
if( r > radius )
|
||||
continue;
|
||||
space_weight[maxk] = (float)std::exp(r*r*gauss_space_coeff);
|
||||
space_ofs[maxk++] = (int)(i*(temp.step/sizeof(float)) + j*cn);
|
||||
}
|
||||
|
||||
for( i = 0; i < size.height; i++ )
|
||||
{
|
||||
const float* sptr = temp.ptr<float>(i+radius) + radius*cn;
|
||||
float* dptr = dst.ptr<float>(i);
|
||||
|
||||
if( cn == 1 )
|
||||
{
|
||||
for( j = 0; j < size.width; j++ )
|
||||
{
|
||||
float sum = 0, wsum = 0;
|
||||
float val0 = sptr[j];
|
||||
for( k = 0; k < maxk; k++ )
|
||||
{
|
||||
float val = sptr[j + space_ofs[k]];
|
||||
float alpha = (float)(std::abs(val - val0)*scale_index);
|
||||
int idx = cvFloor(alpha);
|
||||
alpha -= idx;
|
||||
float w = space_weight[k]*(expLUT[idx] + alpha*(expLUT[idx+1] - expLUT[idx]));
|
||||
sum += val*w;
|
||||
wsum += w;
|
||||
}
|
||||
dptr[j] = (float)(sum/wsum);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
assert( cn == 3 );
|
||||
for( j = 0; j < size.width*3; j += 3 )
|
||||
{
|
||||
float sum_b = 0, sum_g = 0, sum_r = 0, wsum = 0;
|
||||
float b0 = sptr[j], g0 = sptr[j+1], r0 = sptr[j+2];
|
||||
for( k = 0; k < maxk; k++ )
|
||||
{
|
||||
const float* sptr_k = sptr + j + space_ofs[k];
|
||||
float b = sptr_k[0], g = sptr_k[1], r = sptr_k[2];
|
||||
float alpha = (float)((std::abs(b - b0) +
|
||||
std::abs(g - g0) + std::abs(r - r0))*scale_index);
|
||||
int idx = cvFloor(alpha);
|
||||
alpha -= idx;
|
||||
float w = space_weight[k]*(expLUT[idx] + alpha*(expLUT[idx+1] - expLUT[idx]));
|
||||
sum_b += b*w; sum_g += g*w; sum_r += r*w;
|
||||
wsum += w;
|
||||
}
|
||||
wsum = 1.f/wsum;
|
||||
b0 = sum_b*wsum;
|
||||
g0 = sum_g*wsum;
|
||||
r0 = sum_r*wsum;
|
||||
dptr[j] = b0; dptr[j+1] = g0; dptr[j+2] = r0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int CV_BilateralFilterTest::prepare_test_case(int /* test_case_index */)
|
||||
{
|
||||
const static int types[] = { CV_32FC1, CV_32FC3, CV_8UC1, CV_8UC3 };
|
||||
RNG& rng = ts->get_rng();
|
||||
Size size(getRandInt(rng, MIN_WIDTH, MAX_WIDTH), getRandInt(rng, MIN_HEIGHT, MAX_HEIGHT));
|
||||
int type = types[rng(sizeof(types) / sizeof(types[0]))];
|
||||
|
||||
_d = rng.uniform(0., 1.) > 0.5 ? 5 : 3;
|
||||
|
||||
_src.create(size, type);
|
||||
|
||||
rng.fill(_src, RNG::UNIFORM, 0, 256);
|
||||
|
||||
_sigma_color = _sigma_space = 1.;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CV_BilateralFilterTest::validate_test_results(int test_case_index)
|
||||
{
|
||||
double eps = (_src.depth() < CV_32F)?1:5e-3;
|
||||
double e;
|
||||
Mat reference_dst, reference_src;
|
||||
if (_src.depth() == CV_32F)
|
||||
{
|
||||
reference_bilateral_filter(_src, reference_dst, _d, _sigma_color, _sigma_space);
|
||||
e = cvtest::norm(reference_dst, _parallel_dst, NORM_INF|NORM_RELATIVE);
|
||||
}
|
||||
else
|
||||
{
|
||||
int type = _src.type();
|
||||
_src.convertTo(reference_src, CV_32F);
|
||||
reference_bilateral_filter(reference_src, reference_dst, _d, _sigma_color, _sigma_space);
|
||||
reference_dst.convertTo(reference_dst, type);
|
||||
e = cvtest::norm(reference_dst, _parallel_dst, NORM_INF);
|
||||
}
|
||||
|
||||
if (e > eps)
|
||||
{
|
||||
ts->printf(cvtest::TS::CONSOLE, "actual error: %g, expected: %g", e, eps);
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
|
||||
}
|
||||
else
|
||||
ts->set_failed_test_info(cvtest::TS::OK);
|
||||
|
||||
return BaseTest::validate_test_results(test_case_index);
|
||||
}
|
||||
|
||||
void CV_BilateralFilterTest::run_func()
|
||||
{
|
||||
bilateralFilter(_src, _parallel_dst, _d, _sigma_color, _sigma_space);
|
||||
}
|
||||
|
||||
TEST(Imgproc_BilateralFilter, accuracy)
|
||||
{
|
||||
CV_BilateralFilterTest test;
|
||||
test.safe_run();
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
143
3rdparty/opencv-4.5.4/modules/imgproc/test/test_boundingrect.cpp
vendored
Normal file
143
3rdparty/opencv-4.5.4/modules/imgproc/test/test_boundingrect.cpp
vendored
Normal file
@@ -0,0 +1,143 @@
|
||||
/*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 IMGPROC_BOUNDINGRECT_ERROR_DIFF 1
|
||||
|
||||
#define MESSAGE_ERROR_DIFF "Bounding rectangle found by boundingRect function is incorrect."
|
||||
|
||||
class CV_BoundingRectTest: public cvtest::ArrayTest
|
||||
{
|
||||
public:
|
||||
CV_BoundingRectTest();
|
||||
~CV_BoundingRectTest();
|
||||
|
||||
protected:
|
||||
void run (int);
|
||||
|
||||
private:
|
||||
template <typename T> void generate_src_points(vector <Point_<T> >& src, int n);
|
||||
template <typename T> cv::Rect get_bounding_rect(const vector <Point_<T> > src);
|
||||
template <typename T> bool checking_function_work(vector <Point_<T> >& src, int type);
|
||||
};
|
||||
|
||||
CV_BoundingRectTest::CV_BoundingRectTest() {}
|
||||
CV_BoundingRectTest::~CV_BoundingRectTest() {}
|
||||
|
||||
template <typename T> void CV_BoundingRectTest::generate_src_points(vector <Point_<T> >& src, int n)
|
||||
{
|
||||
src.clear();
|
||||
for (int i = 0; i < n; ++i)
|
||||
src.push_back(Point_<T>(cv::randu<T>(), cv::randu<T>()));
|
||||
}
|
||||
|
||||
template <typename T> cv::Rect CV_BoundingRectTest::get_bounding_rect(const vector <Point_<T> > src)
|
||||
{
|
||||
int n = (int)src.size();
|
||||
T min_w = std::numeric_limits<T>::max(), max_w = std::numeric_limits<T>::min();
|
||||
T min_h = min_w, max_h = max_w;
|
||||
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
min_w = std::min<T>(src.at(i).x, min_w);
|
||||
max_w = std::max<T>(src.at(i).x, max_w);
|
||||
min_h = std::min<T>(src.at(i).y, min_h);
|
||||
max_h = std::max<T>(src.at(i).y, max_h);
|
||||
}
|
||||
|
||||
return Rect((int)min_w, (int)min_h, (int)max_w-(int)min_w + 1, (int)max_h-(int)min_h + 1);
|
||||
}
|
||||
|
||||
template <typename T> bool CV_BoundingRectTest::checking_function_work(vector <Point_<T> >& src, int type)
|
||||
{
|
||||
const int MAX_COUNT_OF_POINTS = 1000;
|
||||
const int N = 10000;
|
||||
|
||||
for (int k = 0; k < N; ++k)
|
||||
{
|
||||
|
||||
RNG& rng = ts->get_rng();
|
||||
|
||||
int n = rng.next()%MAX_COUNT_OF_POINTS + 1;
|
||||
|
||||
generate_src_points <T> (src, n);
|
||||
|
||||
cv::Rect right = get_bounding_rect <T> (src);
|
||||
|
||||
cv::Rect rect[2] = { boundingRect(src), boundingRect(Mat(src)) };
|
||||
|
||||
for (int i = 0; i < 2; ++i) if (rect[i] != right)
|
||||
{
|
||||
cout << endl; cout << "Checking for the work of boundingRect function..." << endl;
|
||||
cout << "Type of src points: ";
|
||||
switch (type)
|
||||
{
|
||||
case 0: {cout << "INT"; break;}
|
||||
case 1: {cout << "FLOAT"; break;}
|
||||
default: break;
|
||||
}
|
||||
cout << endl;
|
||||
cout << "Src points are stored as "; if (i == 0) cout << "VECTOR" << endl; else cout << "MAT" << endl;
|
||||
cout << "Number of points: " << n << endl;
|
||||
cout << "Right rect (x, y, w, h): [" << right.x << ", " << right.y << ", " << right.width << ", " << right.height << "]" << endl;
|
||||
cout << "Result rect (x, y, w, h): [" << rect[i].x << ", " << rect[i].y << ", " << rect[i].width << ", " << rect[i].height << "]" << endl;
|
||||
cout << endl;
|
||||
CV_Error(IMGPROC_BOUNDINGRECT_ERROR_DIFF, MESSAGE_ERROR_DIFF);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CV_BoundingRectTest::run(int)
|
||||
{
|
||||
vector <Point> src_veci; if (!checking_function_work(src_veci, 0)) return;
|
||||
vector <Point2f> src_vecf; checking_function_work(src_vecf, 1);
|
||||
}
|
||||
|
||||
TEST (Imgproc_BoundingRect, accuracy) { CV_BoundingRectTest test; test.safe_run(); }
|
||||
|
||||
}} // namespace
|
||||
422
3rdparty/opencv-4.5.4/modules/imgproc/test/test_canny.cpp
vendored
Normal file
422
3rdparty/opencv-4.5.4/modules/imgproc/test/test_canny.cpp
vendored
Normal file
@@ -0,0 +1,422 @@
|
||||
/*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.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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_CannyTest : public cvtest::ArrayTest
|
||||
{
|
||||
public:
|
||||
CV_CannyTest(bool custom_deriv = false);
|
||||
|
||||
protected:
|
||||
void get_test_array_types_and_sizes( int test_case_idx, vector<vector<Size> >& sizes, vector<vector<int> >& types );
|
||||
double get_success_error_level( int test_case_idx, int i, int j );
|
||||
int prepare_test_case( int test_case_idx );
|
||||
void run_func();
|
||||
void prepare_to_validation( int );
|
||||
int validate_test_results( int /*test_case_idx*/ );
|
||||
|
||||
int aperture_size;
|
||||
bool use_true_gradient;
|
||||
double threshold1, threshold2;
|
||||
bool test_cpp;
|
||||
bool test_custom_deriv;
|
||||
|
||||
Mat img;
|
||||
};
|
||||
|
||||
|
||||
CV_CannyTest::CV_CannyTest(bool custom_deriv)
|
||||
{
|
||||
test_array[INPUT].push_back(NULL);
|
||||
test_array[OUTPUT].push_back(NULL);
|
||||
test_array[REF_OUTPUT].push_back(NULL);
|
||||
element_wise_relative_error = true;
|
||||
aperture_size = 0;
|
||||
use_true_gradient = false;
|
||||
threshold1 = threshold2 = 0;
|
||||
test_custom_deriv = custom_deriv;
|
||||
|
||||
const char imgPath[] = "shared/fruits.png";
|
||||
img = cv::imread(cvtest::TS::ptr()->get_data_path() + imgPath, IMREAD_GRAYSCALE);
|
||||
}
|
||||
|
||||
|
||||
void CV_CannyTest::get_test_array_types_and_sizes( int test_case_idx,
|
||||
vector<vector<Size> >& sizes,
|
||||
vector<vector<int> >& types )
|
||||
{
|
||||
RNG& rng = ts->get_rng();
|
||||
double thresh_range;
|
||||
|
||||
cvtest::ArrayTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
|
||||
types[INPUT][0] = types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_8U;
|
||||
|
||||
aperture_size = cvtest::randInt(rng) % 2 ? 5 : 3;
|
||||
thresh_range = aperture_size == 3 ? 300 : 1000;
|
||||
|
||||
threshold1 = cvtest::randReal(rng)*thresh_range;
|
||||
threshold2 = cvtest::randReal(rng)*thresh_range*0.3;
|
||||
|
||||
if( cvtest::randInt(rng) % 2 )
|
||||
CV_SWAP( threshold1, threshold2, thresh_range );
|
||||
|
||||
use_true_gradient = cvtest::randInt(rng) % 2 != 0;
|
||||
test_cpp = (cvtest::randInt(rng) & 256) == 0;
|
||||
|
||||
ts->printf(cvtest::TS::LOG, "Canny(size = %d x %d, aperture_size = %d, threshold1 = %g, threshold2 = %g, L2 = %s) test_cpp = %s (test case #%d)\n",
|
||||
sizes[0][0].width, sizes[0][0].height, aperture_size, threshold1, threshold2, use_true_gradient ? "TRUE" : "FALSE", test_cpp ? "TRUE" : "FALSE", test_case_idx);
|
||||
}
|
||||
|
||||
|
||||
int CV_CannyTest::prepare_test_case( int test_case_idx )
|
||||
{
|
||||
int code = cvtest::ArrayTest::prepare_test_case( test_case_idx );
|
||||
if( code > 0 )
|
||||
{
|
||||
RNG& rng = ts->get_rng();
|
||||
Mat& src = test_mat[INPUT][0];
|
||||
//GaussianBlur(src, src, Size(11, 11), 5, 5);
|
||||
if(src.cols > img.cols || src.rows > img.rows)
|
||||
resize(img, src, src.size(), 0, 0, INTER_LINEAR_EXACT);
|
||||
else
|
||||
img(
|
||||
Rect(
|
||||
cvtest::randInt(rng) % (img.cols-src.cols),
|
||||
cvtest::randInt(rng) % (img.rows-src.rows),
|
||||
src.cols,
|
||||
src.rows
|
||||
)
|
||||
).copyTo(src);
|
||||
GaussianBlur(src, src, Size(5, 5), 0);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
double CV_CannyTest::get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void CV_CannyTest::run_func()
|
||||
{
|
||||
if (test_custom_deriv)
|
||||
{
|
||||
cv::Mat _out = cv::cvarrToMat(test_array[OUTPUT][0]);
|
||||
cv::Mat src = cv::cvarrToMat(test_array[INPUT][0]);
|
||||
cv::Mat dx, dy;
|
||||
int m = aperture_size;
|
||||
Point anchor(m/2, m/2);
|
||||
Mat dxkernel = cvtest::calcSobelKernel2D( 1, 0, m, 0 );
|
||||
Mat dykernel = cvtest::calcSobelKernel2D( 0, 1, m, 0 );
|
||||
cvtest::filter2D(src, dx, CV_16S, dxkernel, anchor, 0, BORDER_REPLICATE);
|
||||
cvtest::filter2D(src, dy, CV_16S, dykernel, anchor, 0, BORDER_REPLICATE);
|
||||
cv::Canny(dx, dy, _out, threshold1, threshold2, use_true_gradient);
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::Mat _out = cv::cvarrToMat(test_array[OUTPUT][0]);
|
||||
cv::Canny(cv::cvarrToMat(test_array[INPUT][0]), _out, threshold1, threshold2,
|
||||
aperture_size + (use_true_gradient ? CV_CANNY_L2_GRADIENT : 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
cannyFollow( int x, int y, float lowThreshold, const Mat& mag, Mat& dst )
|
||||
{
|
||||
static const int ofs[][2] = {{1,0},{1,-1},{0,-1},{-1,-1},{-1,0},{-1,1},{0,1},{1,1}};
|
||||
int i;
|
||||
|
||||
dst.at<uchar>(y, x) = (uchar)255;
|
||||
|
||||
for( i = 0; i < 8; i++ )
|
||||
{
|
||||
int x1 = x + ofs[i][0];
|
||||
int y1 = y + ofs[i][1];
|
||||
if( (unsigned)x1 < (unsigned)mag.cols &&
|
||||
(unsigned)y1 < (unsigned)mag.rows &&
|
||||
mag.at<float>(y1, x1) > lowThreshold &&
|
||||
!dst.at<uchar>(y1, x1) )
|
||||
cannyFollow( x1, y1, lowThreshold, mag, dst );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_Canny( const Mat& src, Mat& dst,
|
||||
double threshold1, double threshold2,
|
||||
int aperture_size, bool use_true_gradient )
|
||||
{
|
||||
int m = aperture_size;
|
||||
Point anchor(m/2, m/2);
|
||||
const double tan_pi_8 = tan(CV_PI/8.);
|
||||
const double tan_3pi_8 = tan(CV_PI*3/8);
|
||||
float lowThreshold = (float)MIN(threshold1, threshold2);
|
||||
float highThreshold = (float)MAX(threshold1, threshold2);
|
||||
|
||||
int x, y, width = src.cols, height = src.rows;
|
||||
|
||||
Mat dxkernel = cvtest::calcSobelKernel2D( 1, 0, m, 0 );
|
||||
Mat dykernel = cvtest::calcSobelKernel2D( 0, 1, m, 0 );
|
||||
Mat dx, dy, mag(height, width, CV_32F);
|
||||
cvtest::filter2D(src, dx, CV_32S, dxkernel, anchor, 0, BORDER_REPLICATE);
|
||||
cvtest::filter2D(src, dy, CV_32S, dykernel, anchor, 0, BORDER_REPLICATE);
|
||||
|
||||
// calc gradient magnitude
|
||||
for( y = 0; y < height; y++ )
|
||||
{
|
||||
for( x = 0; x < width; x++ )
|
||||
{
|
||||
int dxval = dx.at<int>(y, x), dyval = dy.at<int>(y, x);
|
||||
mag.at<float>(y, x) = use_true_gradient ?
|
||||
(float)sqrt((double)(dxval*dxval + dyval*dyval)) :
|
||||
(float)(fabs((double)dxval) + fabs((double)dyval));
|
||||
}
|
||||
}
|
||||
|
||||
// calc gradient direction, do nonmaxima suppression
|
||||
for( y = 0; y < height; y++ )
|
||||
{
|
||||
for( x = 0; x < width; x++ )
|
||||
{
|
||||
|
||||
float a = mag.at<float>(y, x), b = 0, c = 0;
|
||||
int y1 = 0, y2 = 0, x1 = 0, x2 = 0;
|
||||
|
||||
if( a <= lowThreshold )
|
||||
continue;
|
||||
|
||||
int dxval = dx.at<int>(y, x);
|
||||
int dyval = dy.at<int>(y, x);
|
||||
|
||||
double tg = dxval ? (double)dyval/dxval : DBL_MAX*CV_SIGN(dyval);
|
||||
|
||||
if( fabs(tg) < tan_pi_8 )
|
||||
{
|
||||
y1 = y2 = y; x1 = x + 1; x2 = x - 1;
|
||||
}
|
||||
else if( tan_pi_8 <= tg && tg <= tan_3pi_8 )
|
||||
{
|
||||
y1 = y + 1; y2 = y - 1; x1 = x + 1; x2 = x - 1;
|
||||
}
|
||||
else if( -tan_3pi_8 <= tg && tg <= -tan_pi_8 )
|
||||
{
|
||||
y1 = y - 1; y2 = y + 1; x1 = x + 1; x2 = x - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert( fabs(tg) > tan_3pi_8 );
|
||||
x1 = x2 = x; y1 = y + 1; y2 = y - 1;
|
||||
}
|
||||
|
||||
if( (unsigned)y1 < (unsigned)height && (unsigned)x1 < (unsigned)width )
|
||||
b = (float)fabs(mag.at<float>(y1, x1));
|
||||
|
||||
if( (unsigned)y2 < (unsigned)height && (unsigned)x2 < (unsigned)width )
|
||||
c = (float)fabs(mag.at<float>(y2, x2));
|
||||
|
||||
if( (a > b || (a == b && ((x1 == x+1 && y1 == y) || (x1 == x && y1 == y+1)))) && a > c )
|
||||
;
|
||||
else
|
||||
mag.at<float>(y, x) = -a;
|
||||
}
|
||||
}
|
||||
|
||||
dst = Scalar::all(0);
|
||||
|
||||
// hysteresis threshold
|
||||
for( y = 0; y < height; y++ )
|
||||
{
|
||||
for( x = 0; x < width; x++ )
|
||||
if( mag.at<float>(y, x) > highThreshold && !dst.at<uchar>(y, x) )
|
||||
cannyFollow( x, y, lowThreshold, mag, dst );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CV_CannyTest::prepare_to_validation( int )
|
||||
{
|
||||
Mat src = test_mat[INPUT][0], dst = test_mat[REF_OUTPUT][0];
|
||||
test_Canny( src, dst, threshold1, threshold2, aperture_size, use_true_gradient );
|
||||
}
|
||||
|
||||
|
||||
int CV_CannyTest::validate_test_results( int test_case_idx )
|
||||
{
|
||||
int code = cvtest::TS::OK, nz0;
|
||||
prepare_to_validation(test_case_idx);
|
||||
|
||||
double err = cvtest::norm(test_mat[OUTPUT][0], test_mat[REF_OUTPUT][0], CV_L1);
|
||||
if( err == 0 )
|
||||
return code;
|
||||
|
||||
if( err != cvRound(err) || cvRound(err)%255 != 0 )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG, "Some of the pixels, produced by Canny, are not 0's or 255's; the difference is %g\n", err );
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
|
||||
return code;
|
||||
}
|
||||
|
||||
nz0 = cvRound(cvtest::norm(test_mat[REF_OUTPUT][0], CV_L1)/255);
|
||||
err = (err/255/MAX(nz0,100))*100;
|
||||
if( err > 1 )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG, "Too high percentage of non-matching edge pixels = %g%%\n", err);
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
TEST(Imgproc_Canny, accuracy) { CV_CannyTest test; test.safe_run(); }
|
||||
TEST(Imgproc_Canny, accuracy_deriv) { CV_CannyTest test(true); test.safe_run(); }
|
||||
|
||||
|
||||
/*
|
||||
* Comparing OpenVX based implementation with the main one
|
||||
*/
|
||||
|
||||
#ifndef IMPLEMENT_PARAM_CLASS
|
||||
#define IMPLEMENT_PARAM_CLASS(name, type) \
|
||||
class name \
|
||||
{ \
|
||||
public: \
|
||||
name ( type arg = type ()) : val_(arg) {} \
|
||||
operator type () const {return val_;} \
|
||||
private: \
|
||||
type val_; \
|
||||
}; \
|
||||
inline void PrintTo( name param, std::ostream* os) \
|
||||
{ \
|
||||
*os << #name << "(" << testing::PrintToString(static_cast< type >(param)) << ")"; \
|
||||
}
|
||||
#endif // IMPLEMENT_PARAM_CLASS
|
||||
|
||||
IMPLEMENT_PARAM_CLASS(ImagePath, string)
|
||||
IMPLEMENT_PARAM_CLASS(ApertureSize, int)
|
||||
IMPLEMENT_PARAM_CLASS(L2gradient, bool)
|
||||
|
||||
PARAM_TEST_CASE(CannyVX, ImagePath, ApertureSize, L2gradient)
|
||||
{
|
||||
string imgPath;
|
||||
int kSize;
|
||||
bool useL2;
|
||||
Mat src, dst;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
imgPath = GET_PARAM(0);
|
||||
kSize = GET_PARAM(1);
|
||||
useL2 = GET_PARAM(2);
|
||||
}
|
||||
|
||||
void loadImage()
|
||||
{
|
||||
src = cv::imread(cvtest::TS::ptr()->get_data_path() + imgPath, IMREAD_GRAYSCALE);
|
||||
ASSERT_FALSE(src.empty()) << "can't load image: " << imgPath;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(CannyVX, Accuracy)
|
||||
{
|
||||
if(haveOpenVX())
|
||||
{
|
||||
loadImage();
|
||||
|
||||
setUseOpenVX(false);
|
||||
Mat canny;
|
||||
cv::Canny(src, canny, 100, 150, 3);
|
||||
|
||||
setUseOpenVX(true);
|
||||
Mat cannyVX;
|
||||
cv::Canny(src, cannyVX, 100, 150, 3);
|
||||
|
||||
// 'smart' diff check (excluding isolated pixels)
|
||||
Mat diff, diff1;
|
||||
absdiff(canny, cannyVX, diff);
|
||||
boxFilter(diff, diff1, -1, Size(3,3));
|
||||
const int minPixelsAroud = 3; // empirical number
|
||||
diff1 = diff1 > 255/9 * minPixelsAroud;
|
||||
erode(diff1, diff1, Mat());
|
||||
double error = cv::norm(diff1, NORM_L1) / 255;
|
||||
const int maxError = std::min(10, diff.size().area()/100); // empirical number
|
||||
if(error > maxError)
|
||||
{
|
||||
string outPath =
|
||||
string("CannyVX-diff-") +
|
||||
imgPath + '-' +
|
||||
'k' + char(kSize+'0') + '-' +
|
||||
(useL2 ? "l2" : "l1");
|
||||
std::replace(outPath.begin(), outPath.end(), '/', '_');
|
||||
std::replace(outPath.begin(), outPath.end(), '\\', '_');
|
||||
std::replace(outPath.begin(), outPath.end(), '.', '_');
|
||||
imwrite(outPath+".png", diff);
|
||||
}
|
||||
ASSERT_LE(error, maxError);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(
|
||||
ImgProc, CannyVX,
|
||||
testing::Combine(
|
||||
testing::Values(
|
||||
string("shared/baboon.png"),
|
||||
string("shared/fruits.png"),
|
||||
string("shared/lena.png"),
|
||||
string("shared/pic1.png"),
|
||||
string("shared/pic3.png"),
|
||||
string("shared/pic5.png"),
|
||||
string("shared/pic6.png")
|
||||
),
|
||||
testing::Values(ApertureSize(3), ApertureSize(5)),
|
||||
testing::Values(L2gradient(false), L2gradient(true))
|
||||
)
|
||||
);
|
||||
|
||||
}} // namespace
|
||||
/* End of file. */
|
||||
3106
3rdparty/opencv-4.5.4/modules/imgproc/test/test_color.cpp
vendored
Normal file
3106
3rdparty/opencv-4.5.4/modules/imgproc/test/test_color.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
360
3rdparty/opencv-4.5.4/modules/imgproc/test/test_connectedcomponents.cpp
vendored
Normal file
360
3rdparty/opencv-4.5.4/modules/imgproc/test/test_connectedcomponents.cpp
vendored
Normal file
@@ -0,0 +1,360 @@
|
||||
/*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_ConnectedComponentsTest : public cvtest::BaseTest
|
||||
{
|
||||
public:
|
||||
CV_ConnectedComponentsTest();
|
||||
~CV_ConnectedComponentsTest();
|
||||
protected:
|
||||
void run(int);
|
||||
};
|
||||
|
||||
CV_ConnectedComponentsTest::CV_ConnectedComponentsTest() {}
|
||||
CV_ConnectedComponentsTest::~CV_ConnectedComponentsTest() {}
|
||||
|
||||
// This function force a row major order for the labels
|
||||
void normalizeLabels(Mat1i& imgLabels, int iNumLabels) {
|
||||
vector<int> vecNewLabels(iNumLabels + 1, 0);
|
||||
int iMaxNewLabel = 0;
|
||||
|
||||
for (int r = 0; r<imgLabels.rows; ++r) {
|
||||
for (int c = 0; c<imgLabels.cols; ++c) {
|
||||
int iCurLabel = imgLabels(r, c);
|
||||
if (iCurLabel>0) {
|
||||
if (vecNewLabels[iCurLabel] == 0) {
|
||||
vecNewLabels[iCurLabel] = ++iMaxNewLabel;
|
||||
}
|
||||
imgLabels(r, c) = vecNewLabels[iCurLabel];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CV_ConnectedComponentsTest::run( int /* start_from */)
|
||||
{
|
||||
|
||||
int ccltype[] = { cv::CCL_DEFAULT, cv::CCL_WU, cv::CCL_GRANA, cv::CCL_BOLELLI, cv::CCL_SAUF, cv::CCL_BBDT, cv::CCL_SPAGHETTI };
|
||||
|
||||
string exp_path = string(ts->get_data_path()) + "connectedcomponents/ccomp_exp.png";
|
||||
Mat exp = imread(exp_path, 0);
|
||||
Mat orig = imread(string(ts->get_data_path()) + "connectedcomponents/concentric_circles.png", 0);
|
||||
|
||||
if (orig.empty())
|
||||
{
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
Mat bw = orig > 128;
|
||||
|
||||
for (uint cclt = 0; cclt < sizeof(ccltype)/sizeof(int); ++cclt)
|
||||
{
|
||||
|
||||
Mat1i labelImage;
|
||||
int nLabels = connectedComponents(bw, labelImage, 8, CV_32S, ccltype[cclt]);
|
||||
|
||||
normalizeLabels(labelImage, nLabels);
|
||||
|
||||
// Validate test results
|
||||
for (int r = 0; r < labelImage.rows; ++r){
|
||||
for (int c = 0; c < labelImage.cols; ++c){
|
||||
int l = labelImage.at<int>(r, c);
|
||||
bool pass = l >= 0 && l <= nLabels;
|
||||
if (!pass){
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (exp.empty() || orig.size() != exp.size())
|
||||
{
|
||||
imwrite(exp_path, labelImage);
|
||||
exp = labelImage;
|
||||
}
|
||||
|
||||
if (0 != cvtest::norm(labelImage > 0, exp > 0, NORM_INF))
|
||||
{
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);
|
||||
return;
|
||||
}
|
||||
if (nLabels != cvtest::norm(labelImage, NORM_INF) + 1)
|
||||
{
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ts->set_failed_test_info(cvtest::TS::OK);
|
||||
}
|
||||
|
||||
TEST(Imgproc_ConnectedComponents, regression) { CV_ConnectedComponentsTest test; test.safe_run(); }
|
||||
|
||||
TEST(Imgproc_ConnectedComponents, grana_buffer_overflow)
|
||||
{
|
||||
cv::Mat darkMask;
|
||||
darkMask.create(31, 87, CV_8U);
|
||||
darkMask = 0;
|
||||
|
||||
cv::Mat labels;
|
||||
cv::Mat stats;
|
||||
cv::Mat centroids;
|
||||
|
||||
int nbComponents = cv::connectedComponentsWithStats(darkMask, labels, stats, centroids, 8, CV_32S, cv::CCL_GRANA);
|
||||
EXPECT_EQ(1, nbComponents);
|
||||
}
|
||||
|
||||
static cv::Mat createCrashMat(int numThreads) {
|
||||
const int h = numThreads * 4 * 2 + 8;
|
||||
const double nParallelStripes = std::max(1, std::min(h / 2, numThreads * 4));
|
||||
const int w = 4;
|
||||
|
||||
const int nstripes = cvRound(nParallelStripes <= 0 ? h : MIN(MAX(nParallelStripes, 1.), h));
|
||||
const cv::Range stripeRange(0, nstripes);
|
||||
const cv::Range wholeRange(0, h);
|
||||
|
||||
cv::Mat m(h, w, CV_8U);
|
||||
m = 0;
|
||||
|
||||
// Look for a range that starts with odd value and ends with even value
|
||||
cv::Range bugRange;
|
||||
for (int s = stripeRange.start; s < stripeRange.end; s++) {
|
||||
cv::Range sr(s, s + 1);
|
||||
cv::Range r;
|
||||
r.start = (int) (wholeRange.start +
|
||||
((uint64) sr.start * (wholeRange.end - wholeRange.start) + nstripes / 2) / nstripes);
|
||||
r.end = sr.end >= nstripes ?
|
||||
wholeRange.end :
|
||||
(int) (wholeRange.start +
|
||||
((uint64) sr.end * (wholeRange.end - wholeRange.start) + nstripes / 2) / nstripes);
|
||||
|
||||
if (r.start > 0 && r.start % 2 == 1 && r.end % 2 == 0 && r.end >= r.start + 2) {
|
||||
bugRange = r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (bugRange.empty()) { // Could not create a buggy range
|
||||
return m;
|
||||
}
|
||||
|
||||
// Fill in bug Range
|
||||
for (int x = 1; x < w; x++) {
|
||||
m.at<char>(bugRange.start - 1, x) = 1;
|
||||
}
|
||||
|
||||
m.at<char>(bugRange.start + 0, 0) = 1;
|
||||
m.at<char>(bugRange.start + 0, 1) = 1;
|
||||
m.at<char>(bugRange.start + 0, 3) = 1;
|
||||
m.at<char>(bugRange.start + 1, 1) = 1;
|
||||
m.at<char>(bugRange.start + 2, 1) = 1;
|
||||
m.at<char>(bugRange.start + 2, 3) = 1;
|
||||
m.at<char>(bugRange.start + 3, 0) = 1;
|
||||
m.at<char>(bugRange.start + 3, 1) = 1;
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
TEST(Imgproc_ConnectedComponents, parallel_wu_labels)
|
||||
{
|
||||
cv::Mat mat = createCrashMat(cv::getNumThreads());
|
||||
if(mat.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const int nbPixels = cv::countNonZero(mat);
|
||||
|
||||
cv::Mat labels;
|
||||
cv::Mat stats;
|
||||
cv::Mat centroids;
|
||||
int nb = 0;
|
||||
EXPECT_NO_THROW( nb = cv::connectedComponentsWithStats(mat, labels, stats, centroids, 8, CV_32S, cv::CCL_WU) );
|
||||
|
||||
int area = 0;
|
||||
for(int i=1; i<nb; ++i) {
|
||||
area += stats.at<int32_t>(i, cv::CC_STAT_AREA);
|
||||
}
|
||||
|
||||
EXPECT_EQ(nbPixels, area);
|
||||
}
|
||||
|
||||
TEST(Imgproc_ConnectedComponents, missing_background_pixels)
|
||||
{
|
||||
cv::Mat m = Mat::ones(10, 10, CV_8U);
|
||||
cv::Mat labels;
|
||||
cv::Mat stats;
|
||||
cv::Mat centroids;
|
||||
EXPECT_NO_THROW(cv::connectedComponentsWithStats(m, labels, stats, centroids, 8, CV_32S, cv::CCL_WU) );
|
||||
EXPECT_EQ(stats.at<int32_t>(0, cv::CC_STAT_WIDTH), 0);
|
||||
EXPECT_EQ(stats.at<int32_t>(0, cv::CC_STAT_HEIGHT), 0);
|
||||
EXPECT_EQ(stats.at<int32_t>(0, cv::CC_STAT_LEFT), -1);
|
||||
EXPECT_TRUE(std::isnan(centroids.at<double>(0, 0)));
|
||||
EXPECT_TRUE(std::isnan(centroids.at<double>(0, 1)));
|
||||
}
|
||||
|
||||
TEST(Imgproc_ConnectedComponents, spaghetti_bbdt_sauf_stats)
|
||||
{
|
||||
cv::Mat1b img(16, 16);
|
||||
img << 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0,
|
||||
0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0,
|
||||
0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0,
|
||||
0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0,
|
||||
0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1,
|
||||
0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1,
|
||||
0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1;
|
||||
|
||||
cv::Mat1i labels;
|
||||
cv::Mat1i stats;
|
||||
cv::Mat1d centroids;
|
||||
|
||||
int ccltype[] = { cv::CCL_WU, cv::CCL_GRANA, cv::CCL_BOLELLI, cv::CCL_SAUF, cv::CCL_BBDT, cv::CCL_SPAGHETTI };
|
||||
|
||||
for (uint cclt = 0; cclt < sizeof(ccltype) / sizeof(int); ++cclt) {
|
||||
|
||||
EXPECT_NO_THROW(cv::connectedComponentsWithStats(img, labels, stats, centroids, 8, CV_32S, ccltype[cclt]));
|
||||
EXPECT_EQ(stats(0, cv::CC_STAT_LEFT), 0);
|
||||
EXPECT_EQ(stats(0, cv::CC_STAT_TOP), 0);
|
||||
EXPECT_EQ(stats(0, cv::CC_STAT_WIDTH), 16);
|
||||
EXPECT_EQ(stats(0, cv::CC_STAT_HEIGHT), 15);
|
||||
EXPECT_EQ(stats(0, cv::CC_STAT_AREA), 144);
|
||||
|
||||
EXPECT_EQ(stats(1, cv::CC_STAT_LEFT), 1);
|
||||
EXPECT_EQ(stats(1, cv::CC_STAT_TOP), 1);
|
||||
EXPECT_EQ(stats(1, cv::CC_STAT_WIDTH), 3);
|
||||
EXPECT_EQ(stats(1, cv::CC_STAT_HEIGHT), 3);
|
||||
EXPECT_EQ(stats(1, cv::CC_STAT_AREA), 9);
|
||||
|
||||
EXPECT_EQ(stats(2, cv::CC_STAT_LEFT), 1);
|
||||
EXPECT_EQ(stats(2, cv::CC_STAT_TOP), 1);
|
||||
EXPECT_EQ(stats(2, cv::CC_STAT_WIDTH), 8);
|
||||
EXPECT_EQ(stats(2, cv::CC_STAT_HEIGHT), 7);
|
||||
EXPECT_EQ(stats(2, cv::CC_STAT_AREA), 40);
|
||||
|
||||
EXPECT_EQ(stats(3, cv::CC_STAT_LEFT), 10);
|
||||
EXPECT_EQ(stats(3, cv::CC_STAT_TOP), 2);
|
||||
EXPECT_EQ(stats(3, cv::CC_STAT_WIDTH), 5);
|
||||
EXPECT_EQ(stats(3, cv::CC_STAT_HEIGHT), 2);
|
||||
EXPECT_EQ(stats(3, cv::CC_STAT_AREA), 8);
|
||||
|
||||
EXPECT_EQ(stats(4, cv::CC_STAT_LEFT), 11);
|
||||
EXPECT_EQ(stats(4, cv::CC_STAT_TOP), 5);
|
||||
EXPECT_EQ(stats(4, cv::CC_STAT_WIDTH), 3);
|
||||
EXPECT_EQ(stats(4, cv::CC_STAT_HEIGHT), 3);
|
||||
EXPECT_EQ(stats(4, cv::CC_STAT_AREA), 9);
|
||||
|
||||
EXPECT_EQ(stats(5, cv::CC_STAT_LEFT), 2);
|
||||
EXPECT_EQ(stats(5, cv::CC_STAT_TOP), 9);
|
||||
EXPECT_EQ(stats(5, cv::CC_STAT_WIDTH), 1);
|
||||
EXPECT_EQ(stats(5, cv::CC_STAT_HEIGHT), 1);
|
||||
EXPECT_EQ(stats(5, cv::CC_STAT_AREA), 1);
|
||||
|
||||
EXPECT_EQ(stats(6, cv::CC_STAT_LEFT), 12);
|
||||
EXPECT_EQ(stats(6, cv::CC_STAT_TOP), 9);
|
||||
EXPECT_EQ(stats(6, cv::CC_STAT_WIDTH), 1);
|
||||
EXPECT_EQ(stats(6, cv::CC_STAT_HEIGHT), 1);
|
||||
EXPECT_EQ(stats(6, cv::CC_STAT_AREA), 1);
|
||||
|
||||
// Labels' order could be different!
|
||||
if (cclt == cv::CCL_WU || cclt == cv::CCL_SAUF) {
|
||||
// CCL_SAUF, CCL_WU
|
||||
EXPECT_EQ(stats(9, cv::CC_STAT_LEFT), 1);
|
||||
EXPECT_EQ(stats(9, cv::CC_STAT_TOP), 11);
|
||||
EXPECT_EQ(stats(9, cv::CC_STAT_WIDTH), 4);
|
||||
EXPECT_EQ(stats(9, cv::CC_STAT_HEIGHT), 2);
|
||||
EXPECT_EQ(stats(9, cv::CC_STAT_AREA), 8);
|
||||
|
||||
EXPECT_EQ(stats(7, cv::CC_STAT_LEFT), 6);
|
||||
EXPECT_EQ(stats(7, cv::CC_STAT_TOP), 10);
|
||||
EXPECT_EQ(stats(7, cv::CC_STAT_WIDTH), 4);
|
||||
EXPECT_EQ(stats(7, cv::CC_STAT_HEIGHT), 2);
|
||||
EXPECT_EQ(stats(7, cv::CC_STAT_AREA), 8);
|
||||
|
||||
EXPECT_EQ(stats(8, cv::CC_STAT_LEFT), 0);
|
||||
EXPECT_EQ(stats(8, cv::CC_STAT_TOP), 10);
|
||||
EXPECT_EQ(stats(8, cv::CC_STAT_WIDTH), 16);
|
||||
EXPECT_EQ(stats(8, cv::CC_STAT_HEIGHT), 6);
|
||||
EXPECT_EQ(stats(8, cv::CC_STAT_AREA), 21);
|
||||
}
|
||||
else {
|
||||
// CCL_BBDT, CCL_GRANA, CCL_SPAGHETTI, CCL_BOLELLI
|
||||
EXPECT_EQ(stats(7, cv::CC_STAT_LEFT), 1);
|
||||
EXPECT_EQ(stats(7, cv::CC_STAT_TOP), 11);
|
||||
EXPECT_EQ(stats(7, cv::CC_STAT_WIDTH), 4);
|
||||
EXPECT_EQ(stats(7, cv::CC_STAT_HEIGHT), 2);
|
||||
EXPECT_EQ(stats(7, cv::CC_STAT_AREA), 8);
|
||||
|
||||
EXPECT_EQ(stats(8, cv::CC_STAT_LEFT), 6);
|
||||
EXPECT_EQ(stats(8, cv::CC_STAT_TOP), 10);
|
||||
EXPECT_EQ(stats(8, cv::CC_STAT_WIDTH), 4);
|
||||
EXPECT_EQ(stats(8, cv::CC_STAT_HEIGHT), 2);
|
||||
EXPECT_EQ(stats(8, cv::CC_STAT_AREA), 8);
|
||||
|
||||
EXPECT_EQ(stats(9, cv::CC_STAT_LEFT), 0);
|
||||
EXPECT_EQ(stats(9, cv::CC_STAT_TOP), 10);
|
||||
EXPECT_EQ(stats(9, cv::CC_STAT_WIDTH), 16);
|
||||
EXPECT_EQ(stats(9, cv::CC_STAT_HEIGHT), 6);
|
||||
EXPECT_EQ(stats(9, cv::CC_STAT_AREA), 21);
|
||||
}
|
||||
EXPECT_EQ(stats(10, cv::CC_STAT_LEFT), 9);
|
||||
EXPECT_EQ(stats(10, cv::CC_STAT_TOP), 12);
|
||||
EXPECT_EQ(stats(10, cv::CC_STAT_WIDTH), 5);
|
||||
EXPECT_EQ(stats(10, cv::CC_STAT_HEIGHT), 2);
|
||||
EXPECT_EQ(stats(10, cv::CC_STAT_AREA), 7);
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
552
3rdparty/opencv-4.5.4/modules/imgproc/test/test_contours.cpp
vendored
Normal file
552
3rdparty/opencv-4.5.4/modules/imgproc/test/test_contours.cpp
vendored
Normal file
@@ -0,0 +1,552 @@
|
||||
/*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.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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/highgui.hpp>
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
class CV_FindContourTest : public cvtest::BaseTest
|
||||
{
|
||||
public:
|
||||
enum { NUM_IMG = 4 };
|
||||
|
||||
CV_FindContourTest();
|
||||
~CV_FindContourTest();
|
||||
void clear();
|
||||
|
||||
protected:
|
||||
int read_params( const cv::FileStorage& fs );
|
||||
int prepare_test_case( int test_case_idx );
|
||||
int validate_test_results( int test_case_idx );
|
||||
void run_func();
|
||||
|
||||
int min_blob_size, max_blob_size;
|
||||
int blob_count, max_log_blob_count;
|
||||
int retr_mode, approx_method;
|
||||
|
||||
int min_log_img_width, max_log_img_width;
|
||||
int min_log_img_height, max_log_img_height;
|
||||
Size img_size;
|
||||
int count, count2;
|
||||
|
||||
IplImage* img[NUM_IMG];
|
||||
CvMemStorage* storage;
|
||||
CvSeq *contours, *contours2, *chain;
|
||||
|
||||
static const bool useVeryWideImages =
|
||||
#if SIZE_MAX <= 0xffffffff
|
||||
// 32-bit: don't even try the very wide images
|
||||
false
|
||||
#else
|
||||
// 64-bit: test with very wide images
|
||||
true
|
||||
#endif
|
||||
;
|
||||
};
|
||||
|
||||
|
||||
CV_FindContourTest::CV_FindContourTest()
|
||||
{
|
||||
int i;
|
||||
|
||||
test_case_count = useVeryWideImages ? 10 : 300;
|
||||
min_blob_size = 1;
|
||||
max_blob_size = 50;
|
||||
max_log_blob_count = 10;
|
||||
|
||||
min_log_img_width = useVeryWideImages ? 17 : 3;
|
||||
max_log_img_width = useVeryWideImages ? 17 : 10;
|
||||
|
||||
min_log_img_height = 3;
|
||||
max_log_img_height = 10;
|
||||
|
||||
for( i = 0; i < NUM_IMG; i++ )
|
||||
img[i] = 0;
|
||||
|
||||
storage = 0;
|
||||
}
|
||||
|
||||
|
||||
CV_FindContourTest::~CV_FindContourTest()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
void CV_FindContourTest::clear()
|
||||
{
|
||||
int i;
|
||||
|
||||
cvtest::BaseTest::clear();
|
||||
|
||||
for( i = 0; i < NUM_IMG; i++ )
|
||||
cvReleaseImage( &img[i] );
|
||||
|
||||
cvReleaseMemStorage( &storage );
|
||||
}
|
||||
|
||||
|
||||
int CV_FindContourTest::read_params( const cv::FileStorage& fs )
|
||||
{
|
||||
int t;
|
||||
int code = cvtest::BaseTest::read_params( fs );
|
||||
|
||||
if( code < 0 )
|
||||
return code;
|
||||
|
||||
read( find_param( fs, "min_blob_size" ), min_blob_size, min_blob_size );
|
||||
read( find_param( fs, "max_blob_size" ), max_blob_size, max_blob_size );
|
||||
read( find_param( fs, "max_log_blob_count" ), max_log_blob_count, max_log_blob_count );
|
||||
read( find_param( fs, "min_log_img_width" ), min_log_img_width, min_log_img_width );
|
||||
read( find_param( fs, "max_log_img_width" ), max_log_img_width, max_log_img_width );
|
||||
read( find_param( fs, "min_log_img_height"), min_log_img_height, min_log_img_height );
|
||||
read( find_param( fs, "max_log_img_height"), max_log_img_height, max_log_img_height );
|
||||
|
||||
min_blob_size = cvtest::clipInt( min_blob_size, 1, 100 );
|
||||
max_blob_size = cvtest::clipInt( max_blob_size, 1, 100 );
|
||||
|
||||
if( min_blob_size > max_blob_size )
|
||||
CV_SWAP( min_blob_size, max_blob_size, t );
|
||||
|
||||
max_log_blob_count = cvtest::clipInt( max_log_blob_count, 1, 10 );
|
||||
|
||||
min_log_img_width = cvtest::clipInt( min_log_img_width, 1, useVeryWideImages ? 17 : 10 );
|
||||
min_log_img_width = cvtest::clipInt( max_log_img_width, 1, useVeryWideImages ? 17 : 10 );
|
||||
min_log_img_height = cvtest::clipInt( min_log_img_height, 1, 10 );
|
||||
min_log_img_height = cvtest::clipInt( max_log_img_height, 1, 10 );
|
||||
|
||||
if( min_log_img_width > max_log_img_width )
|
||||
std::swap( min_log_img_width, max_log_img_width );
|
||||
|
||||
if (min_log_img_height > max_log_img_height)
|
||||
std::swap(min_log_img_height, max_log_img_height);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
cvTsGenerateBlobImage( IplImage* img, int min_blob_size, int max_blob_size,
|
||||
int blob_count, int min_brightness, int max_brightness,
|
||||
RNG& rng )
|
||||
{
|
||||
int i;
|
||||
Size size;
|
||||
|
||||
CV_Assert(img->depth == IPL_DEPTH_8U && img->nChannels == 1);
|
||||
|
||||
cvZero( img );
|
||||
|
||||
// keep the border clear
|
||||
cvSetImageROI( img, cvRect(1,1,img->width-2,img->height-2) );
|
||||
size = cvGetSize( img );
|
||||
|
||||
for( i = 0; i < blob_count; i++ )
|
||||
{
|
||||
Point center;
|
||||
Size axes;
|
||||
int angle = cvtest::randInt(rng) % 180;
|
||||
int brightness = cvtest::randInt(rng) %
|
||||
(max_brightness - min_brightness) + min_brightness;
|
||||
center.x = cvtest::randInt(rng) % size.width;
|
||||
center.y = cvtest::randInt(rng) % size.height;
|
||||
|
||||
axes.width = (cvtest::randInt(rng) %
|
||||
(max_blob_size - min_blob_size) + min_blob_size + 1)/2;
|
||||
axes.height = (cvtest::randInt(rng) %
|
||||
(max_blob_size - min_blob_size) + min_blob_size + 1)/2;
|
||||
|
||||
cvEllipse( img, cvPoint(center), cvSize(axes), angle, 0, 360, cvScalar(brightness), CV_FILLED );
|
||||
}
|
||||
|
||||
cvResetImageROI( img );
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
cvTsMarkContours( IplImage* img, int val )
|
||||
{
|
||||
int i, j;
|
||||
int step = img->widthStep;
|
||||
|
||||
assert( img->depth == IPL_DEPTH_8U && img->nChannels == 1 && (val&1) != 0);
|
||||
|
||||
for( i = 1; i < img->height - 1; i++ )
|
||||
for( j = 1; j < img->width - 1; j++ )
|
||||
{
|
||||
uchar* t = (uchar*)(img->imageData + img->widthStep*i + j);
|
||||
if( *t == 1 && (t[-step] == 0 || t[-1] == 0 || t[1] == 0 || t[step] == 0))
|
||||
*t = (uchar)val;
|
||||
}
|
||||
|
||||
cvThreshold( img, img, val - 2, val, CV_THRESH_BINARY );
|
||||
}
|
||||
|
||||
|
||||
int CV_FindContourTest::prepare_test_case( int test_case_idx )
|
||||
{
|
||||
RNG& rng = ts->get_rng();
|
||||
const int min_brightness = 0, max_brightness = 2;
|
||||
int i, code = cvtest::BaseTest::prepare_test_case( test_case_idx );
|
||||
|
||||
if( code < 0 )
|
||||
return code;
|
||||
|
||||
clear();
|
||||
|
||||
blob_count = cvRound(exp(cvtest::randReal(rng)*max_log_blob_count*CV_LOG2));
|
||||
|
||||
img_size.width = cvRound(exp((cvtest::randReal(rng)*
|
||||
(max_log_img_width - min_log_img_width) + min_log_img_width)*CV_LOG2));
|
||||
img_size.height = cvRound(exp((cvtest::randReal(rng)*
|
||||
(max_log_img_height - min_log_img_height) + min_log_img_height)*CV_LOG2));
|
||||
|
||||
approx_method = cvtest::randInt( rng ) % 4 + 1;
|
||||
retr_mode = cvtest::randInt( rng ) % 4;
|
||||
|
||||
storage = cvCreateMemStorage( 1 << 10 );
|
||||
|
||||
for( i = 0; i < NUM_IMG; i++ )
|
||||
img[i] = cvCreateImage( cvSize(img_size), 8, 1 );
|
||||
|
||||
cvTsGenerateBlobImage( img[0], min_blob_size, max_blob_size,
|
||||
blob_count, min_brightness, max_brightness, rng );
|
||||
|
||||
cvCopy( img[0], img[1] );
|
||||
cvCopy( img[0], img[2] );
|
||||
|
||||
cvTsMarkContours( img[1], 255 );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void CV_FindContourTest::run_func()
|
||||
{
|
||||
contours = contours2 = chain = 0;
|
||||
count = cvFindContours( img[2], storage, &contours, sizeof(CvContour), retr_mode, approx_method );
|
||||
|
||||
cvZero( img[3] );
|
||||
|
||||
if( contours && retr_mode != CV_RETR_EXTERNAL && approx_method < CV_CHAIN_APPROX_TC89_L1 )
|
||||
cvDrawContours( img[3], contours, cvScalar(255), cvScalar(255), INT_MAX, -1 );
|
||||
|
||||
cvCopy( img[0], img[2] );
|
||||
|
||||
count2 = cvFindContours( img[2], storage, &chain, sizeof(CvChain), retr_mode, CV_CHAIN_CODE );
|
||||
|
||||
if( chain )
|
||||
contours2 = cvApproxChains( chain, storage, approx_method, 0, 0, 1 );
|
||||
|
||||
cvZero( img[2] );
|
||||
|
||||
if( contours && retr_mode != CV_RETR_EXTERNAL && approx_method < CV_CHAIN_APPROX_TC89_L1 )
|
||||
cvDrawContours( img[2], contours2, cvScalar(255), cvScalar(255), INT_MAX );
|
||||
}
|
||||
|
||||
|
||||
// the whole testing is done here, run_func() is not utilized in this test
|
||||
int CV_FindContourTest::validate_test_results( int /*test_case_idx*/ )
|
||||
{
|
||||
int code = cvtest::TS::OK;
|
||||
|
||||
cvCmpS( img[0], 0, img[0], CV_CMP_GT );
|
||||
|
||||
if( count != count2 )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG, "The number of contours retrieved with different "
|
||||
"approximation methods is not the same\n"
|
||||
"(%d contour(s) for method %d vs %d contour(s) for method %d)\n",
|
||||
count, approx_method, count2, CV_CHAIN_CODE );
|
||||
code = cvtest::TS::FAIL_INVALID_OUTPUT;
|
||||
}
|
||||
|
||||
if( retr_mode != CV_RETR_EXTERNAL && approx_method < CV_CHAIN_APPROX_TC89_L1 )
|
||||
{
|
||||
Mat _img[4];
|
||||
for( int i = 0; i < 4; i++ )
|
||||
_img[i] = cvarrToMat(img[i]);
|
||||
|
||||
code = cvtest::cmpEps2(ts, _img[0], _img[3], 0, true, "Comparing original image with the map of filled contours" );
|
||||
|
||||
if( code < 0 )
|
||||
goto _exit_;
|
||||
|
||||
code = cvtest::cmpEps2( ts, _img[1], _img[2], 0, true,
|
||||
"Comparing contour outline vs manually produced edge map" );
|
||||
|
||||
if( code < 0 )
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
if( contours )
|
||||
{
|
||||
CvTreeNodeIterator iterator1;
|
||||
CvTreeNodeIterator iterator2;
|
||||
int count3;
|
||||
|
||||
for(int i = 0; i < 2; i++ )
|
||||
{
|
||||
CvTreeNodeIterator iterator;
|
||||
cvInitTreeNodeIterator( &iterator, i == 0 ? contours : contours2, INT_MAX );
|
||||
|
||||
for( count3 = 0; cvNextTreeNode( &iterator ) != 0; count3++ )
|
||||
;
|
||||
|
||||
if( count3 != count )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG,
|
||||
"The returned number of retrieved contours (using the approx_method = %d) does not match\n"
|
||||
"to the actual number of contours in the tree/list (returned %d, actual %d)\n",
|
||||
i == 0 ? approx_method : 0, count, count3 );
|
||||
code = cvtest::TS::FAIL_INVALID_OUTPUT;
|
||||
goto _exit_;
|
||||
}
|
||||
}
|
||||
|
||||
cvInitTreeNodeIterator( &iterator1, contours, INT_MAX );
|
||||
cvInitTreeNodeIterator( &iterator2, contours2, INT_MAX );
|
||||
|
||||
for( count3 = 0; count3 < count; count3++ )
|
||||
{
|
||||
CvSeq* seq1 = (CvSeq*)cvNextTreeNode( &iterator1 );
|
||||
CvSeq* seq2 = (CvSeq*)cvNextTreeNode( &iterator2 );
|
||||
CvSeqReader reader1;
|
||||
CvSeqReader reader2;
|
||||
|
||||
if( !seq1 || !seq2 )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG,
|
||||
"There are NULL pointers in the original contour tree or the "
|
||||
"tree produced by cvApproxChains\n" );
|
||||
code = cvtest::TS::FAIL_INVALID_OUTPUT;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
cvStartReadSeq( seq1, &reader1 );
|
||||
cvStartReadSeq( seq2, &reader2 );
|
||||
|
||||
if( seq1->total != seq2->total )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG,
|
||||
"The original contour #%d has %d points, while the corresponding contour has %d point\n",
|
||||
count3, seq1->total, seq2->total );
|
||||
code = cvtest::TS::FAIL_INVALID_OUTPUT;
|
||||
goto _exit_;
|
||||
}
|
||||
|
||||
for(int i = 0; i < seq1->total; i++ )
|
||||
{
|
||||
CvPoint pt1 = {0, 0};
|
||||
CvPoint pt2 = {0, 0};
|
||||
|
||||
CV_READ_SEQ_ELEM( pt1, reader1 );
|
||||
CV_READ_SEQ_ELEM( pt2, reader2 );
|
||||
|
||||
if( pt1.x != pt2.x || pt1.y != pt2.y )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG,
|
||||
"The point #%d in the contour #%d is different from the corresponding point "
|
||||
"in the approximated chain ((%d,%d) vs (%d,%d)", count3, i, pt1.x, pt1.y, pt2.x, pt2.y );
|
||||
code = cvtest::TS::FAIL_INVALID_OUTPUT;
|
||||
goto _exit_;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_exit_:
|
||||
if( code < 0 )
|
||||
{
|
||||
#if 0
|
||||
cvNamedWindow( "test", 0 );
|
||||
cvShowImage( "test", img[0] );
|
||||
cvWaitKey();
|
||||
#endif
|
||||
ts->set_failed_test_info( code );
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
TEST(Imgproc_FindContours, accuracy) { CV_FindContourTest test; test.safe_run(); }
|
||||
|
||||
//rotate/flip a quadrant appropriately
|
||||
static void rot(int n, int *x, int *y, int rx, int ry)
|
||||
{
|
||||
if (ry == 0) {
|
||||
if (rx == 1) {
|
||||
*x = n-1 - *x;
|
||||
*y = n-1 - *y;
|
||||
}
|
||||
|
||||
//Swap x and y
|
||||
int t = *x;
|
||||
*x = *y;
|
||||
*y = t;
|
||||
}
|
||||
}
|
||||
|
||||
static void d2xy(int n, int d, int *x, int *y)
|
||||
{
|
||||
int rx, ry, s, t=d;
|
||||
*x = *y = 0;
|
||||
for (s=1; s<n; s*=2)
|
||||
{
|
||||
rx = 1 & (t/2);
|
||||
ry = 1 & (t ^ rx);
|
||||
rot(s, x, y, rx, ry);
|
||||
*x += s * rx;
|
||||
*y += s * ry;
|
||||
t /= 4;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Imgproc_FindContours, hilbert)
|
||||
{
|
||||
int n = 64, n2 = n*n, scale = 10, w = (n + 2)*scale;
|
||||
Point ofs(scale, scale);
|
||||
Mat img(w, w, CV_8U);
|
||||
img.setTo(Scalar::all(0));
|
||||
|
||||
Point p(0,0);
|
||||
for( int i = 0; i < n2; i++ )
|
||||
{
|
||||
Point q(0,0);
|
||||
d2xy(n2, i, &q.x, &q.y);
|
||||
line(img, p*scale + ofs, q*scale + ofs, Scalar::all(255));
|
||||
p = q;
|
||||
}
|
||||
dilate(img, img, Mat());
|
||||
vector<vector<Point> > contours;
|
||||
findContours(img, contours, noArray(), RETR_LIST, CHAIN_APPROX_SIMPLE);
|
||||
printf("ncontours = %d, contour[0].npoints=%d\n", (int)contours.size(), (int)contours[0].size());
|
||||
img.setTo(Scalar::all(0));
|
||||
|
||||
drawContours(img, contours, 0, Scalar::all(255), 1);
|
||||
|
||||
ASSERT_EQ(1, (int)contours.size());
|
||||
ASSERT_EQ(9832, (int)contours[0].size());
|
||||
}
|
||||
|
||||
TEST(Imgproc_FindContours, border)
|
||||
{
|
||||
Mat img;
|
||||
cv::copyMakeBorder(Mat::zeros(8, 10, CV_8U), img, 1, 1, 1, 1, BORDER_CONSTANT, Scalar(1));
|
||||
|
||||
std::vector<std::vector<cv::Point> > contours;
|
||||
findContours(img, contours, RETR_LIST, CHAIN_APPROX_NONE);
|
||||
|
||||
Mat img_draw_contours = Mat::zeros(img.size(), CV_8U);
|
||||
for (size_t cpt = 0; cpt < contours.size(); cpt++)
|
||||
{
|
||||
drawContours(img_draw_contours, contours, static_cast<int>(cpt), cv::Scalar(1));
|
||||
}
|
||||
|
||||
ASSERT_EQ(0, cvtest::norm(img, img_draw_contours, NORM_INF));
|
||||
}
|
||||
|
||||
TEST(Imgproc_FindContours, regression_4363_shared_nbd)
|
||||
{
|
||||
// Create specific test image
|
||||
Mat1b img(12, 69, (const uchar&)0);
|
||||
|
||||
img(1, 1) = 1;
|
||||
|
||||
// Vertical rectangle with hole sharing the same NBD
|
||||
for (int r = 1; r <= 10; ++r) {
|
||||
for (int c = 3; c <= 5; ++c) {
|
||||
img(r, c) = 1;
|
||||
}
|
||||
}
|
||||
img(9, 4) = 0;
|
||||
|
||||
// 124 small CCs
|
||||
for (int r = 1; r <= 7; r += 2) {
|
||||
for (int c = 7; c <= 67; c += 2) {
|
||||
img(r, c) = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Last CC
|
||||
img(9, 7) = 1;
|
||||
|
||||
vector< vector<Point> > contours;
|
||||
vector<Vec4i> hierarchy;
|
||||
findContours(img, contours, hierarchy, RETR_TREE, CHAIN_APPROX_NONE);
|
||||
|
||||
bool found = false;
|
||||
size_t index = 0;
|
||||
for (vector< vector<Point> >::const_iterator i = contours.begin(); i != contours.end(); ++i)
|
||||
{
|
||||
const vector<Point>& c = *i;
|
||||
if (!c.empty() && c[0] == Point(7, 9))
|
||||
{
|
||||
found = true;
|
||||
index = (size_t)(i - contours.begin());
|
||||
break;
|
||||
}
|
||||
}
|
||||
EXPECT_TRUE(found) << "Desired result: point (7,9) is a contour - Actual result: point (7,9) is not a contour";
|
||||
|
||||
if (found)
|
||||
{
|
||||
EXPECT_LT(hierarchy[index][3], 0) << "Desired result: (7,9) has no parent - Actual result: parent of (7,9) is another contour. index = " << index;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Imgproc_PointPolygonTest, regression_10222)
|
||||
{
|
||||
vector<Point> contour;
|
||||
contour.push_back(Point(0, 0));
|
||||
contour.push_back(Point(0, 100000));
|
||||
contour.push_back(Point(100000, 100000));
|
||||
contour.push_back(Point(100000, 50000));
|
||||
contour.push_back(Point(100000, 0));
|
||||
|
||||
const Point2f point(40000, 40000);
|
||||
const double result = cv::pointPolygonTest(contour, point, false);
|
||||
EXPECT_GT(result, 0) << "Desired result: point is inside polygon - actual result: point is not inside polygon";
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
/* End of file. */
|
||||
2461
3rdparty/opencv-4.5.4/modules/imgproc/test/test_convhull.cpp
vendored
Normal file
2461
3rdparty/opencv-4.5.4/modules/imgproc/test/test_convhull.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
727
3rdparty/opencv-4.5.4/modules/imgproc/test/test_cvtyuv.cpp
vendored
Normal file
727
3rdparty/opencv-4.5.4/modules/imgproc/test/test_cvtyuv.cpp
vendored
Normal file
@@ -0,0 +1,727 @@
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
#undef RGB
|
||||
#undef YUV
|
||||
|
||||
typedef Vec3b YUV;
|
||||
typedef Vec3b RGB;
|
||||
|
||||
int countOfDifferencies(const Mat& gold, const Mat& result, int maxAllowedDifference = 1)
|
||||
{
|
||||
Mat diff;
|
||||
absdiff(gold, result, diff);
|
||||
return countNonZero(diff.reshape(1) > maxAllowedDifference);
|
||||
}
|
||||
|
||||
class YUVreader
|
||||
{
|
||||
public:
|
||||
virtual ~YUVreader() {}
|
||||
virtual YUV read(const Mat& yuv, int row, int col) = 0;
|
||||
virtual int channels() = 0;
|
||||
virtual Size size(Size imgSize) = 0;
|
||||
|
||||
virtual bool requiresEvenHeight() { return true; }
|
||||
virtual bool requiresEvenWidth() { return true; }
|
||||
|
||||
static YUVreader* getReader(int code);
|
||||
};
|
||||
|
||||
class RGBreader
|
||||
{
|
||||
public:
|
||||
virtual ~RGBreader() {}
|
||||
virtual RGB read(const Mat& rgb, int row, int col) = 0;
|
||||
virtual int channels() = 0;
|
||||
|
||||
static RGBreader* getReader(int code);
|
||||
};
|
||||
|
||||
class RGBwriter
|
||||
{
|
||||
public:
|
||||
virtual ~RGBwriter() {}
|
||||
|
||||
virtual void write(Mat& rgb, int row, int col, const RGB& val) = 0;
|
||||
virtual int channels() = 0;
|
||||
|
||||
static RGBwriter* getWriter(int code);
|
||||
};
|
||||
|
||||
class GRAYwriter
|
||||
{
|
||||
public:
|
||||
virtual ~GRAYwriter() {}
|
||||
|
||||
virtual void write(Mat& gray, int row, int col, const uchar& val)
|
||||
{
|
||||
gray.at<uchar>(row, col) = val;
|
||||
}
|
||||
|
||||
virtual int channels() { return 1; }
|
||||
|
||||
static GRAYwriter* getWriter(int code);
|
||||
};
|
||||
|
||||
class YUVwriter
|
||||
{
|
||||
public:
|
||||
virtual ~YUVwriter() {}
|
||||
|
||||
virtual void write(Mat& yuv, int row, int col, const YUV& val) = 0;
|
||||
virtual int channels() = 0;
|
||||
virtual Size size(Size imgSize) = 0;
|
||||
|
||||
virtual bool requiresEvenHeight() { return true; }
|
||||
virtual bool requiresEvenWidth() { return true; }
|
||||
|
||||
static YUVwriter* getWriter(int code);
|
||||
};
|
||||
|
||||
class RGB888Writer : public RGBwriter
|
||||
{
|
||||
void write(Mat& rgb, int row, int col, const RGB& val)
|
||||
{
|
||||
rgb.at<Vec3b>(row, col) = val;
|
||||
}
|
||||
|
||||
int channels() { return 3; }
|
||||
};
|
||||
|
||||
class BGR888Writer : public RGBwriter
|
||||
{
|
||||
void write(Mat& rgb, int row, int col, const RGB& val)
|
||||
{
|
||||
Vec3b tmp(val[2], val[1], val[0]);
|
||||
rgb.at<Vec3b>(row, col) = tmp;
|
||||
}
|
||||
|
||||
int channels() { return 3; }
|
||||
};
|
||||
|
||||
class RGBA8888Writer : public RGBwriter
|
||||
{
|
||||
void write(Mat& rgb, int row, int col, const RGB& val)
|
||||
{
|
||||
Vec4b tmp(val[0], val[1], val[2], 255);
|
||||
rgb.at<Vec4b>(row, col) = tmp;
|
||||
}
|
||||
|
||||
int channels() { return 4; }
|
||||
};
|
||||
|
||||
class BGRA8888Writer : public RGBwriter
|
||||
{
|
||||
void write(Mat& rgb, int row, int col, const RGB& val)
|
||||
{
|
||||
Vec4b tmp(val[2], val[1], val[0], 255);
|
||||
rgb.at<Vec4b>(row, col) = tmp;
|
||||
}
|
||||
|
||||
int channels() { return 4; }
|
||||
};
|
||||
|
||||
class YUV420pWriter: public YUVwriter
|
||||
{
|
||||
int channels() { return 1; }
|
||||
Size size(Size imgSize) { return Size(imgSize.width, imgSize.height + imgSize.height/2); }
|
||||
};
|
||||
|
||||
class YV12Writer: public YUV420pWriter
|
||||
{
|
||||
void write(Mat& yuv, int row, int col, const YUV& val)
|
||||
{
|
||||
int h = yuv.rows * 2 / 3;
|
||||
|
||||
yuv.ptr<uchar>(row)[col] = val[0];
|
||||
if( row % 2 == 0 && col % 2 == 0 )
|
||||
{
|
||||
yuv.ptr<uchar>(h + row/4)[col/2 + ((row/2) % 2) * (yuv.cols/2)] = val[2];
|
||||
yuv.ptr<uchar>(h + (row/2 + h/2)/2)[col/2 + ((row/2 + h/2) % 2) * (yuv.cols/2)] = val[1];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class I420Writer: public YUV420pWriter
|
||||
{
|
||||
void write(Mat& yuv, int row, int col, const YUV& val)
|
||||
{
|
||||
int h = yuv.rows * 2 / 3;
|
||||
|
||||
yuv.ptr<uchar>(row)[col] = val[0];
|
||||
if( row % 2 == 0 && col % 2 == 0 )
|
||||
{
|
||||
yuv.ptr<uchar>(h + row/4)[col/2 + ((row/2) % 2) * (yuv.cols/2)] = val[1];
|
||||
yuv.ptr<uchar>(h + (row/2 + h/2)/2)[col/2 + ((row/2 + h/2) % 2) * (yuv.cols/2)] = val[2];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class YUV420Reader: public YUVreader
|
||||
{
|
||||
int channels() { return 1; }
|
||||
Size size(Size imgSize) { return Size(imgSize.width, imgSize.height * 3 / 2); }
|
||||
};
|
||||
|
||||
class YUV422Reader: public YUVreader
|
||||
{
|
||||
int channels() { return 2; }
|
||||
Size size(Size imgSize) { return imgSize; }
|
||||
bool requiresEvenHeight() { return false; }
|
||||
};
|
||||
|
||||
class NV21Reader: public YUV420Reader
|
||||
{
|
||||
YUV read(const Mat& yuv, int row, int col)
|
||||
{
|
||||
uchar y = yuv.ptr<uchar>(row)[col];
|
||||
uchar u = yuv.ptr<uchar>(yuv.rows * 2 / 3 + row/2)[(col/2)*2 + 1];
|
||||
uchar v = yuv.ptr<uchar>(yuv.rows * 2 / 3 + row/2)[(col/2)*2];
|
||||
|
||||
return YUV(y, u, v);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct NV12Reader: public YUV420Reader
|
||||
{
|
||||
YUV read(const Mat& yuv, int row, int col)
|
||||
{
|
||||
uchar y = yuv.ptr<uchar>(row)[col];
|
||||
uchar u = yuv.ptr<uchar>(yuv.rows * 2 / 3 + row/2)[(col/2)*2];
|
||||
uchar v = yuv.ptr<uchar>(yuv.rows * 2 / 3 + row/2)[(col/2)*2 + 1];
|
||||
|
||||
return YUV(y, u, v);
|
||||
}
|
||||
};
|
||||
|
||||
class YV12Reader: public YUV420Reader
|
||||
{
|
||||
YUV read(const Mat& yuv, int row, int col)
|
||||
{
|
||||
int h = yuv.rows * 2 / 3;
|
||||
uchar y = yuv.ptr<uchar>(row)[col];
|
||||
uchar u = yuv.ptr<uchar>(h + (row/2 + h/2)/2)[col/2 + ((row/2 + h/2) % 2) * (yuv.cols/2)];
|
||||
uchar v = yuv.ptr<uchar>(h + row/4)[col/2 + ((row/2) % 2) * (yuv.cols/2)];
|
||||
|
||||
return YUV(y, u, v);
|
||||
}
|
||||
};
|
||||
|
||||
class IYUVReader: public YUV420Reader
|
||||
{
|
||||
YUV read(const Mat& yuv, int row, int col)
|
||||
{
|
||||
int h = yuv.rows * 2 / 3;
|
||||
uchar y = yuv.ptr<uchar>(row)[col];
|
||||
uchar u = yuv.ptr<uchar>(h + row/4)[col/2 + ((row/2) % 2) * (yuv.cols/2)];
|
||||
uchar v = yuv.ptr<uchar>(h + (row/2 + h/2)/2)[col/2 + ((row/2 + h/2) % 2) * (yuv.cols/2)];
|
||||
|
||||
return YUV(y, u, v);
|
||||
}
|
||||
};
|
||||
|
||||
class UYVYReader: public YUV422Reader
|
||||
{
|
||||
YUV read(const Mat& yuv, int row, int col)
|
||||
{
|
||||
uchar y = yuv.ptr<Vec2b>(row)[col][1];
|
||||
uchar u = yuv.ptr<Vec2b>(row)[(col/2)*2][0];
|
||||
uchar v = yuv.ptr<Vec2b>(row)[(col/2)*2 + 1][0];
|
||||
|
||||
return YUV(y, u, v);
|
||||
}
|
||||
};
|
||||
|
||||
class YUY2Reader: public YUV422Reader
|
||||
{
|
||||
YUV read(const Mat& yuv, int row, int col)
|
||||
{
|
||||
uchar y = yuv.ptr<Vec2b>(row)[col][0];
|
||||
uchar u = yuv.ptr<Vec2b>(row)[(col/2)*2][1];
|
||||
uchar v = yuv.ptr<Vec2b>(row)[(col/2)*2 + 1][1];
|
||||
|
||||
return YUV(y, u, v);
|
||||
}
|
||||
};
|
||||
|
||||
class YVYUReader: public YUV422Reader
|
||||
{
|
||||
YUV read(const Mat& yuv, int row, int col)
|
||||
{
|
||||
uchar y = yuv.ptr<Vec2b>(row)[col][0];
|
||||
uchar u = yuv.ptr<Vec2b>(row)[(col/2)*2 + 1][1];
|
||||
uchar v = yuv.ptr<Vec2b>(row)[(col/2)*2][1];
|
||||
|
||||
return YUV(y, u, v);
|
||||
}
|
||||
};
|
||||
|
||||
class YUV888Reader : public YUVreader
|
||||
{
|
||||
YUV read(const Mat& yuv, int row, int col)
|
||||
{
|
||||
return yuv.at<YUV>(row, col);
|
||||
}
|
||||
|
||||
int channels() { return 3; }
|
||||
Size size(Size imgSize) { return imgSize; }
|
||||
bool requiresEvenHeight() { return false; }
|
||||
bool requiresEvenWidth() { return false; }
|
||||
};
|
||||
|
||||
class RGB888Reader : public RGBreader
|
||||
{
|
||||
RGB read(const Mat& rgb, int row, int col)
|
||||
{
|
||||
return rgb.at<RGB>(row, col);
|
||||
}
|
||||
|
||||
int channels() { return 3; }
|
||||
};
|
||||
|
||||
class BGR888Reader : public RGBreader
|
||||
{
|
||||
RGB read(const Mat& rgb, int row, int col)
|
||||
{
|
||||
RGB tmp = rgb.at<RGB>(row, col);
|
||||
return RGB(tmp[2], tmp[1], tmp[0]);
|
||||
}
|
||||
|
||||
int channels() { return 3; }
|
||||
};
|
||||
|
||||
class RGBA8888Reader : public RGBreader
|
||||
{
|
||||
RGB read(const Mat& rgb, int row, int col)
|
||||
{
|
||||
Vec4b rgba = rgb.at<Vec4b>(row, col);
|
||||
return RGB(rgba[0], rgba[1], rgba[2]);
|
||||
}
|
||||
|
||||
int channels() { return 4; }
|
||||
};
|
||||
|
||||
class BGRA8888Reader : public RGBreader
|
||||
{
|
||||
RGB read(const Mat& rgb, int row, int col)
|
||||
{
|
||||
Vec4b rgba = rgb.at<Vec4b>(row, col);
|
||||
return RGB(rgba[2], rgba[1], rgba[0]);
|
||||
}
|
||||
|
||||
int channels() { return 4; }
|
||||
};
|
||||
|
||||
class YUV2RGB_Converter
|
||||
{
|
||||
public:
|
||||
RGB convert(YUV yuv)
|
||||
{
|
||||
int y = std::max(0, yuv[0] - 16);
|
||||
int u = yuv[1] - 128;
|
||||
int v = yuv[2] - 128;
|
||||
uchar r = saturate_cast<uchar>(1.164f * y + 1.596f * v);
|
||||
uchar g = saturate_cast<uchar>(1.164f * y - 0.813f * v - 0.391f * u);
|
||||
uchar b = saturate_cast<uchar>(1.164f * y + 2.018f * u);
|
||||
|
||||
return RGB(r, g, b);
|
||||
}
|
||||
};
|
||||
|
||||
class YUV2GRAY_Converter
|
||||
{
|
||||
public:
|
||||
uchar convert(YUV yuv)
|
||||
{
|
||||
return yuv[0];
|
||||
}
|
||||
};
|
||||
|
||||
class RGB2YUV_Converter
|
||||
{
|
||||
public:
|
||||
YUV convert(RGB rgb)
|
||||
{
|
||||
int r = rgb[0];
|
||||
int g = rgb[1];
|
||||
int b = rgb[2];
|
||||
|
||||
uchar y = saturate_cast<uchar>((int)( 0.257f*r + 0.504f*g + 0.098f*b + 0.5f) + 16);
|
||||
uchar u = saturate_cast<uchar>((int)(-0.148f*r - 0.291f*g + 0.439f*b + 0.5f) + 128);
|
||||
uchar v = saturate_cast<uchar>((int)( 0.439f*r - 0.368f*g - 0.071f*b + 0.5f) + 128);
|
||||
|
||||
return YUV(y, u, v);
|
||||
}
|
||||
};
|
||||
|
||||
YUVreader* YUVreader::getReader(int code)
|
||||
{
|
||||
switch(code)
|
||||
{
|
||||
case COLOR_YUV2RGB_NV12:
|
||||
case COLOR_YUV2BGR_NV12:
|
||||
case COLOR_YUV2RGBA_NV12:
|
||||
case COLOR_YUV2BGRA_NV12:
|
||||
return new NV12Reader();
|
||||
case COLOR_YUV2RGB_NV21:
|
||||
case COLOR_YUV2BGR_NV21:
|
||||
case COLOR_YUV2RGBA_NV21:
|
||||
case COLOR_YUV2BGRA_NV21:
|
||||
return new NV21Reader();
|
||||
case COLOR_YUV2RGB_YV12:
|
||||
case COLOR_YUV2BGR_YV12:
|
||||
case COLOR_YUV2RGBA_YV12:
|
||||
case COLOR_YUV2BGRA_YV12:
|
||||
return new YV12Reader();
|
||||
case COLOR_YUV2RGB_IYUV:
|
||||
case COLOR_YUV2BGR_IYUV:
|
||||
case COLOR_YUV2RGBA_IYUV:
|
||||
case COLOR_YUV2BGRA_IYUV:
|
||||
return new IYUVReader();
|
||||
case COLOR_YUV2RGB_UYVY:
|
||||
case COLOR_YUV2BGR_UYVY:
|
||||
case COLOR_YUV2RGBA_UYVY:
|
||||
case COLOR_YUV2BGRA_UYVY:
|
||||
return new UYVYReader();
|
||||
//case COLOR_YUV2RGB_VYUY = 109,
|
||||
//case COLOR_YUV2BGR_VYUY = 110,
|
||||
//case COLOR_YUV2RGBA_VYUY = 113,
|
||||
//case COLOR_YUV2BGRA_VYUY = 114,
|
||||
// return ??
|
||||
case COLOR_YUV2RGB_YUY2:
|
||||
case COLOR_YUV2BGR_YUY2:
|
||||
case COLOR_YUV2RGBA_YUY2:
|
||||
case COLOR_YUV2BGRA_YUY2:
|
||||
return new YUY2Reader();
|
||||
case COLOR_YUV2RGB_YVYU:
|
||||
case COLOR_YUV2BGR_YVYU:
|
||||
case COLOR_YUV2RGBA_YVYU:
|
||||
case COLOR_YUV2BGRA_YVYU:
|
||||
return new YVYUReader();
|
||||
case COLOR_YUV2GRAY_420:
|
||||
return new NV21Reader();
|
||||
case COLOR_YUV2GRAY_UYVY:
|
||||
return new UYVYReader();
|
||||
case COLOR_YUV2GRAY_YUY2:
|
||||
return new YUY2Reader();
|
||||
case COLOR_YUV2BGR:
|
||||
case COLOR_YUV2RGB:
|
||||
return new YUV888Reader();
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
RGBreader* RGBreader::getReader(int code)
|
||||
{
|
||||
switch(code)
|
||||
{
|
||||
case COLOR_RGB2YUV_YV12:
|
||||
case COLOR_RGB2YUV_I420:
|
||||
return new RGB888Reader();
|
||||
case COLOR_BGR2YUV_YV12:
|
||||
case COLOR_BGR2YUV_I420:
|
||||
return new BGR888Reader();
|
||||
case COLOR_RGBA2YUV_I420:
|
||||
case COLOR_RGBA2YUV_YV12:
|
||||
return new RGBA8888Reader();
|
||||
case COLOR_BGRA2YUV_YV12:
|
||||
case COLOR_BGRA2YUV_I420:
|
||||
return new BGRA8888Reader();
|
||||
default:
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
RGBwriter* RGBwriter::getWriter(int code)
|
||||
{
|
||||
switch(code)
|
||||
{
|
||||
case COLOR_YUV2RGB_NV12:
|
||||
case COLOR_YUV2RGB_NV21:
|
||||
case COLOR_YUV2RGB_YV12:
|
||||
case COLOR_YUV2RGB_IYUV:
|
||||
case COLOR_YUV2RGB_UYVY:
|
||||
//case COLOR_YUV2RGB_VYUY:
|
||||
case COLOR_YUV2RGB_YUY2:
|
||||
case COLOR_YUV2RGB_YVYU:
|
||||
case COLOR_YUV2RGB:
|
||||
return new RGB888Writer();
|
||||
case COLOR_YUV2BGR_NV12:
|
||||
case COLOR_YUV2BGR_NV21:
|
||||
case COLOR_YUV2BGR_YV12:
|
||||
case COLOR_YUV2BGR_IYUV:
|
||||
case COLOR_YUV2BGR_UYVY:
|
||||
//case COLOR_YUV2BGR_VYUY:
|
||||
case COLOR_YUV2BGR_YUY2:
|
||||
case COLOR_YUV2BGR_YVYU:
|
||||
case COLOR_YUV2BGR:
|
||||
return new BGR888Writer();
|
||||
case COLOR_YUV2RGBA_NV12:
|
||||
case COLOR_YUV2RGBA_NV21:
|
||||
case COLOR_YUV2RGBA_YV12:
|
||||
case COLOR_YUV2RGBA_IYUV:
|
||||
case COLOR_YUV2RGBA_UYVY:
|
||||
//case COLOR_YUV2RGBA_VYUY:
|
||||
case COLOR_YUV2RGBA_YUY2:
|
||||
case COLOR_YUV2RGBA_YVYU:
|
||||
return new RGBA8888Writer();
|
||||
case COLOR_YUV2BGRA_NV12:
|
||||
case COLOR_YUV2BGRA_NV21:
|
||||
case COLOR_YUV2BGRA_YV12:
|
||||
case COLOR_YUV2BGRA_IYUV:
|
||||
case COLOR_YUV2BGRA_UYVY:
|
||||
//case COLOR_YUV2BGRA_VYUY:
|
||||
case COLOR_YUV2BGRA_YUY2:
|
||||
case COLOR_YUV2BGRA_YVYU:
|
||||
return new BGRA8888Writer();
|
||||
default:
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
GRAYwriter* GRAYwriter::getWriter(int code)
|
||||
{
|
||||
switch(code)
|
||||
{
|
||||
case COLOR_YUV2GRAY_420:
|
||||
case COLOR_YUV2GRAY_UYVY:
|
||||
case COLOR_YUV2GRAY_YUY2:
|
||||
return new GRAYwriter();
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
YUVwriter* YUVwriter::getWriter(int code)
|
||||
{
|
||||
switch(code)
|
||||
{
|
||||
case COLOR_RGB2YUV_YV12:
|
||||
case COLOR_BGR2YUV_YV12:
|
||||
case COLOR_RGBA2YUV_YV12:
|
||||
case COLOR_BGRA2YUV_YV12:
|
||||
return new YV12Writer();
|
||||
case COLOR_RGB2YUV_I420:
|
||||
case COLOR_BGR2YUV_I420:
|
||||
case COLOR_RGBA2YUV_I420:
|
||||
case COLOR_BGRA2YUV_I420:
|
||||
return new I420Writer();
|
||||
default:
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
template<class convertor>
|
||||
void referenceYUV2RGB(const Mat& yuv, Mat& rgb, YUVreader* yuvReader, RGBwriter* rgbWriter)
|
||||
{
|
||||
convertor cvt;
|
||||
|
||||
for(int row = 0; row < rgb.rows; ++row)
|
||||
for(int col = 0; col < rgb.cols; ++col)
|
||||
rgbWriter->write(rgb, row, col, cvt.convert(yuvReader->read(yuv, row, col)));
|
||||
}
|
||||
|
||||
template<class convertor>
|
||||
void referenceYUV2GRAY(const Mat& yuv, Mat& rgb, YUVreader* yuvReader, GRAYwriter* grayWriter)
|
||||
{
|
||||
convertor cvt;
|
||||
|
||||
for(int row = 0; row < rgb.rows; ++row)
|
||||
for(int col = 0; col < rgb.cols; ++col)
|
||||
grayWriter->write(rgb, row, col, cvt.convert(yuvReader->read(yuv, row, col)));
|
||||
}
|
||||
|
||||
template<class convertor>
|
||||
void referenceRGB2YUV(const Mat& rgb, Mat& yuv, RGBreader* rgbReader, YUVwriter* yuvWriter)
|
||||
{
|
||||
convertor cvt;
|
||||
|
||||
for(int row = 0; row < rgb.rows; ++row)
|
||||
for(int col = 0; col < rgb.cols; ++col)
|
||||
yuvWriter->write(yuv, row, col, cvt.convert(rgbReader->read(rgb, row, col)));
|
||||
}
|
||||
|
||||
struct ConversionYUV
|
||||
{
|
||||
explicit ConversionYUV( const int code )
|
||||
{
|
||||
yuvReader_ = YUVreader :: getReader(code);
|
||||
yuvWriter_ = YUVwriter :: getWriter(code);
|
||||
rgbReader_ = RGBreader :: getReader(code);
|
||||
rgbWriter_ = RGBwriter :: getWriter(code);
|
||||
grayWriter_ = GRAYwriter:: getWriter(code);
|
||||
}
|
||||
|
||||
~ConversionYUV()
|
||||
{
|
||||
if (yuvReader_)
|
||||
delete yuvReader_;
|
||||
|
||||
if (yuvWriter_)
|
||||
delete yuvWriter_;
|
||||
|
||||
if (rgbReader_)
|
||||
delete rgbReader_;
|
||||
|
||||
if (rgbWriter_)
|
||||
delete rgbWriter_;
|
||||
|
||||
if (grayWriter_)
|
||||
delete grayWriter_;
|
||||
}
|
||||
|
||||
int getDcn()
|
||||
{
|
||||
return (rgbWriter_ != 0) ? rgbWriter_->channels() : ((grayWriter_ != 0) ? grayWriter_->channels() : yuvWriter_->channels());
|
||||
}
|
||||
|
||||
int getScn()
|
||||
{
|
||||
return (yuvReader_ != 0) ? yuvReader_->channels() : rgbReader_->channels();
|
||||
}
|
||||
|
||||
Size getSrcSize( const Size& imgSize )
|
||||
{
|
||||
return (yuvReader_ != 0) ? yuvReader_->size(imgSize) : imgSize;
|
||||
}
|
||||
|
||||
Size getDstSize( const Size& imgSize )
|
||||
{
|
||||
return (yuvWriter_ != 0) ? yuvWriter_->size(imgSize) : imgSize;
|
||||
}
|
||||
|
||||
bool requiresEvenHeight()
|
||||
{
|
||||
return (yuvReader_ != 0) ? yuvReader_->requiresEvenHeight() : ((yuvWriter_ != 0) ? yuvWriter_->requiresEvenHeight() : false);
|
||||
}
|
||||
|
||||
bool requiresEvenWidth()
|
||||
{
|
||||
return (yuvReader_ != 0) ? yuvReader_->requiresEvenWidth() : ((yuvWriter_ != 0) ? yuvWriter_->requiresEvenWidth() : false);
|
||||
}
|
||||
|
||||
YUVreader* yuvReader_;
|
||||
YUVwriter* yuvWriter_;
|
||||
RGBreader* rgbReader_;
|
||||
RGBwriter* rgbWriter_;
|
||||
GRAYwriter* grayWriter_;
|
||||
};
|
||||
|
||||
CV_ENUM(YUVCVTS, COLOR_YUV2RGB_NV12, COLOR_YUV2BGR_NV12, COLOR_YUV2RGB_NV21, COLOR_YUV2BGR_NV21,
|
||||
COLOR_YUV2RGBA_NV12, COLOR_YUV2BGRA_NV12, COLOR_YUV2RGBA_NV21, COLOR_YUV2BGRA_NV21,
|
||||
COLOR_YUV2RGB_YV12, COLOR_YUV2BGR_YV12, COLOR_YUV2RGB_IYUV, COLOR_YUV2BGR_IYUV,
|
||||
COLOR_YUV2RGBA_YV12, COLOR_YUV2BGRA_YV12, COLOR_YUV2RGBA_IYUV, COLOR_YUV2BGRA_IYUV,
|
||||
COLOR_YUV2RGB_UYVY, COLOR_YUV2BGR_UYVY, COLOR_YUV2RGBA_UYVY, COLOR_YUV2BGRA_UYVY,
|
||||
COLOR_YUV2RGB_YUY2, COLOR_YUV2BGR_YUY2, COLOR_YUV2RGB_YVYU, COLOR_YUV2BGR_YVYU,
|
||||
COLOR_YUV2RGBA_YUY2, COLOR_YUV2BGRA_YUY2, COLOR_YUV2RGBA_YVYU, COLOR_YUV2BGRA_YVYU,
|
||||
COLOR_YUV2GRAY_420, COLOR_YUV2GRAY_UYVY, COLOR_YUV2GRAY_YUY2,
|
||||
COLOR_YUV2BGR, COLOR_YUV2RGB, COLOR_RGB2YUV_YV12, COLOR_BGR2YUV_YV12, COLOR_RGBA2YUV_YV12,
|
||||
COLOR_BGRA2YUV_YV12, COLOR_RGB2YUV_I420, COLOR_BGR2YUV_I420, COLOR_RGBA2YUV_I420, COLOR_BGRA2YUV_I420)
|
||||
|
||||
typedef ::testing::TestWithParam<YUVCVTS> Imgproc_ColorYUV;
|
||||
|
||||
TEST_P(Imgproc_ColorYUV, accuracy)
|
||||
{
|
||||
int code = GetParam();
|
||||
RNG& random = theRNG();
|
||||
|
||||
ConversionYUV cvt(code);
|
||||
|
||||
const int scn = cvt.getScn();
|
||||
const int dcn = cvt.getDcn();
|
||||
for(int iter = 0; iter < 30; ++iter)
|
||||
{
|
||||
Size sz(random.uniform(1, 641), random.uniform(1, 481));
|
||||
|
||||
if(cvt.requiresEvenWidth()) sz.width += sz.width % 2;
|
||||
if(cvt.requiresEvenHeight()) sz.height += sz.height % 2;
|
||||
|
||||
Size srcSize = cvt.getSrcSize(sz);
|
||||
Mat src = Mat(srcSize.height, srcSize.width * scn, CV_8UC1).reshape(scn);
|
||||
|
||||
Size dstSize = cvt.getDstSize(sz);
|
||||
Mat dst = Mat(dstSize.height, dstSize.width * dcn, CV_8UC1).reshape(dcn);
|
||||
Mat gold(dstSize, CV_8UC(dcn));
|
||||
|
||||
random.fill(src, RNG::UNIFORM, 0, 256);
|
||||
|
||||
if(cvt.rgbWriter_)
|
||||
referenceYUV2RGB<YUV2RGB_Converter> (src, gold, cvt.yuvReader_, cvt.rgbWriter_);
|
||||
else if(cvt.grayWriter_)
|
||||
referenceYUV2GRAY<YUV2GRAY_Converter>(src, gold, cvt.yuvReader_, cvt.grayWriter_);
|
||||
else if(cvt.yuvWriter_)
|
||||
referenceRGB2YUV<RGB2YUV_Converter> (src, gold, cvt.rgbReader_, cvt.yuvWriter_);
|
||||
|
||||
cv::cvtColor(src, dst, code, -1);
|
||||
|
||||
EXPECT_EQ(0, countOfDifferencies(gold, dst));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(Imgproc_ColorYUV, roi_accuracy)
|
||||
{
|
||||
int code = GetParam();
|
||||
RNG& random = theRNG();
|
||||
|
||||
ConversionYUV cvt(code);
|
||||
|
||||
const int scn = cvt.getScn();
|
||||
const int dcn = cvt.getDcn();
|
||||
for(int iter = 0; iter < 30; ++iter)
|
||||
{
|
||||
Size sz(random.uniform(1, 641), random.uniform(1, 481));
|
||||
|
||||
if(cvt.requiresEvenWidth()) sz.width += sz.width % 2;
|
||||
if(cvt.requiresEvenHeight()) sz.height += sz.height % 2;
|
||||
|
||||
int roi_offset_top = random.uniform(0, 6);
|
||||
int roi_offset_bottom = random.uniform(0, 6);
|
||||
int roi_offset_left = random.uniform(0, 6);
|
||||
int roi_offset_right = random.uniform(0, 6);
|
||||
|
||||
Size srcSize = cvt.getSrcSize(sz);
|
||||
Mat src_full(srcSize.height + roi_offset_top + roi_offset_bottom, srcSize.width + roi_offset_left + roi_offset_right, CV_8UC(scn));
|
||||
|
||||
Size dstSize = cvt.getDstSize(sz);
|
||||
Mat dst_full(dstSize.height + roi_offset_left + roi_offset_right, dstSize.width + roi_offset_top + roi_offset_bottom, CV_8UC(dcn), Scalar::all(0));
|
||||
Mat gold_full(dst_full.size(), CV_8UC(dcn), Scalar::all(0));
|
||||
|
||||
random.fill(src_full, RNG::UNIFORM, 0, 256);
|
||||
|
||||
Mat src = src_full(Range(roi_offset_top, roi_offset_top + srcSize.height), Range(roi_offset_left, roi_offset_left + srcSize.width));
|
||||
Mat dst = dst_full(Range(roi_offset_left, roi_offset_left + dstSize.height), Range(roi_offset_top, roi_offset_top + dstSize.width));
|
||||
Mat gold = gold_full(Range(roi_offset_left, roi_offset_left + dstSize.height), Range(roi_offset_top, roi_offset_top + dstSize.width));
|
||||
|
||||
if(cvt.rgbWriter_)
|
||||
referenceYUV2RGB<YUV2RGB_Converter> (src, gold, cvt.yuvReader_, cvt.rgbWriter_);
|
||||
else if(cvt.grayWriter_)
|
||||
referenceYUV2GRAY<YUV2GRAY_Converter>(src, gold, cvt.yuvReader_, cvt.grayWriter_);
|
||||
else if(cvt.yuvWriter_)
|
||||
referenceRGB2YUV<RGB2YUV_Converter> (src, gold, cvt.rgbReader_, cvt.yuvWriter_);
|
||||
|
||||
cv::cvtColor(src, dst, code, -1);
|
||||
|
||||
EXPECT_EQ(0, countOfDifferencies(gold_full, dst_full));
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(cvt420, Imgproc_ColorYUV,
|
||||
::testing::Values((int)COLOR_YUV2RGB_NV12, (int)COLOR_YUV2BGR_NV12, (int)COLOR_YUV2RGB_NV21, (int)COLOR_YUV2BGR_NV21,
|
||||
(int)COLOR_YUV2RGBA_NV12, (int)COLOR_YUV2BGRA_NV12, (int)COLOR_YUV2RGBA_NV21, (int)COLOR_YUV2BGRA_NV21,
|
||||
(int)COLOR_YUV2RGB_YV12, (int)COLOR_YUV2BGR_YV12, (int)COLOR_YUV2RGB_IYUV, (int)COLOR_YUV2BGR_IYUV,
|
||||
(int)COLOR_YUV2RGBA_YV12, (int)COLOR_YUV2BGRA_YV12, (int)COLOR_YUV2RGBA_IYUV, (int)COLOR_YUV2BGRA_IYUV,
|
||||
(int)COLOR_YUV2GRAY_420, (int)COLOR_RGB2YUV_YV12, (int)COLOR_BGR2YUV_YV12, (int)COLOR_RGBA2YUV_YV12,
|
||||
(int)COLOR_BGRA2YUV_YV12, (int)COLOR_RGB2YUV_I420, (int)COLOR_BGR2YUV_I420, (int)COLOR_RGBA2YUV_I420,
|
||||
(int)COLOR_BGRA2YUV_I420));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(cvt422, Imgproc_ColorYUV,
|
||||
::testing::Values((int)COLOR_YUV2RGB_UYVY, (int)COLOR_YUV2BGR_UYVY, (int)COLOR_YUV2RGBA_UYVY, (int)COLOR_YUV2BGRA_UYVY,
|
||||
(int)COLOR_YUV2RGB_YUY2, (int)COLOR_YUV2BGR_YUY2, (int)COLOR_YUV2RGB_YVYU, (int)COLOR_YUV2BGR_YVYU,
|
||||
(int)COLOR_YUV2RGBA_YUY2, (int)COLOR_YUV2BGRA_YUY2, (int)COLOR_YUV2RGBA_YVYU, (int)COLOR_YUV2BGRA_YVYU,
|
||||
(int)COLOR_YUV2GRAY_UYVY, (int)COLOR_YUV2GRAY_YUY2));
|
||||
|
||||
}} // namespace
|
||||
305
3rdparty/opencv-4.5.4/modules/imgproc/test/test_distancetransform.cpp
vendored
Normal file
305
3rdparty/opencv-4.5.4/modules/imgproc/test/test_distancetransform.cpp
vendored
Normal file
@@ -0,0 +1,305 @@
|
||||
/*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.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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_DisTransTest : public cvtest::ArrayTest
|
||||
{
|
||||
public:
|
||||
CV_DisTransTest();
|
||||
|
||||
protected:
|
||||
void get_test_array_types_and_sizes( int test_case_idx, vector<vector<Size> >& sizes, vector<vector<int> >& types );
|
||||
double get_success_error_level( int test_case_idx, int i, int j );
|
||||
void run_func();
|
||||
void prepare_to_validation( int );
|
||||
|
||||
void get_minmax_bounds( int i, int j, int type, Scalar& low, Scalar& high );
|
||||
int prepare_test_case( int test_case_idx );
|
||||
|
||||
int mask_size;
|
||||
int dist_type;
|
||||
int fill_labels;
|
||||
float mask[3];
|
||||
};
|
||||
|
||||
|
||||
CV_DisTransTest::CV_DisTransTest()
|
||||
{
|
||||
test_array[INPUT].push_back(NULL);
|
||||
test_array[OUTPUT].push_back(NULL);
|
||||
test_array[OUTPUT].push_back(NULL);
|
||||
test_array[REF_OUTPUT].push_back(NULL);
|
||||
test_array[REF_OUTPUT].push_back(NULL);
|
||||
optional_mask = false;
|
||||
element_wise_relative_error = true;
|
||||
}
|
||||
|
||||
|
||||
void CV_DisTransTest::get_test_array_types_and_sizes( int test_case_idx,
|
||||
vector<vector<Size> >& sizes, vector<vector<int> >& types )
|
||||
{
|
||||
RNG& rng = ts->get_rng();
|
||||
cvtest::ArrayTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
|
||||
|
||||
types[INPUT][0] = CV_8UC1;
|
||||
types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_32FC1;
|
||||
types[OUTPUT][1] = types[REF_OUTPUT][1] = CV_32SC1;
|
||||
|
||||
if( cvtest::randInt(rng) & 1 )
|
||||
{
|
||||
mask_size = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
mask_size = 5;
|
||||
}
|
||||
|
||||
dist_type = cvtest::randInt(rng) % 3;
|
||||
dist_type = dist_type == 0 ? CV_DIST_C : dist_type == 1 ? CV_DIST_L1 : CV_DIST_L2;
|
||||
|
||||
// for now, check only the "labeled" distance transform mode
|
||||
fill_labels = 0;
|
||||
|
||||
if( !fill_labels )
|
||||
sizes[OUTPUT][1] = sizes[REF_OUTPUT][1] = cvSize(0,0);
|
||||
}
|
||||
|
||||
|
||||
double CV_DisTransTest::get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ )
|
||||
{
|
||||
Size sz = test_mat[INPUT][0].size();
|
||||
return dist_type == CV_DIST_C || dist_type == CV_DIST_L1 ? 0 : 0.01*MAX(sz.width, sz.height);
|
||||
}
|
||||
|
||||
|
||||
void CV_DisTransTest::get_minmax_bounds( int i, int j, int type, Scalar& low, Scalar& high )
|
||||
{
|
||||
cvtest::ArrayTest::get_minmax_bounds( i, j, type, low, high );
|
||||
if( i == INPUT && CV_MAT_DEPTH(type) == CV_8U )
|
||||
{
|
||||
low = Scalar::all(0);
|
||||
high = Scalar::all(10);
|
||||
}
|
||||
}
|
||||
|
||||
int CV_DisTransTest::prepare_test_case( int test_case_idx )
|
||||
{
|
||||
int code = cvtest::ArrayTest::prepare_test_case( test_case_idx );
|
||||
if( code > 0 )
|
||||
{
|
||||
// the function's response to an "all-nonzeros" image is not determined,
|
||||
// so put at least one zero point
|
||||
Mat& mat = test_mat[INPUT][0];
|
||||
RNG& rng = ts->get_rng();
|
||||
int i = cvtest::randInt(rng) % mat.rows;
|
||||
int j = cvtest::randInt(rng) % mat.cols;
|
||||
mat.at<uchar>(i,j) = 0;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
void CV_DisTransTest::run_func()
|
||||
{
|
||||
cvDistTransform( test_array[INPUT][0], test_array[OUTPUT][0], dist_type, mask_size,
|
||||
dist_type == CV_DIST_USER ? mask : 0, test_array[OUTPUT][1] );
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
cvTsDistTransform( const CvMat* _src, CvMat* _dst, int dist_type,
|
||||
int mask_size, float* _mask, CvMat* /*_labels*/ )
|
||||
{
|
||||
int i, j, k;
|
||||
int width = _src->cols, height = _src->rows;
|
||||
const float init_val = 1e6;
|
||||
float mask[3];
|
||||
CvMat* temp;
|
||||
int ofs[16] = {0};
|
||||
float delta[16];
|
||||
int tstep, count;
|
||||
|
||||
assert( mask_size == 3 || mask_size == 5 );
|
||||
|
||||
if( dist_type == CV_DIST_USER )
|
||||
memcpy( mask, _mask, sizeof(mask) );
|
||||
else if( dist_type == CV_DIST_C )
|
||||
{
|
||||
mask_size = 3;
|
||||
mask[0] = mask[1] = 1.f;
|
||||
}
|
||||
else if( dist_type == CV_DIST_L1 )
|
||||
{
|
||||
mask_size = 3;
|
||||
mask[0] = 1.f;
|
||||
mask[1] = 2.f;
|
||||
}
|
||||
else if( mask_size == 3 )
|
||||
{
|
||||
mask[0] = 0.955f;
|
||||
mask[1] = 1.3693f;
|
||||
}
|
||||
else
|
||||
{
|
||||
mask[0] = 1.0f;
|
||||
mask[1] = 1.4f;
|
||||
mask[2] = 2.1969f;
|
||||
}
|
||||
|
||||
temp = cvCreateMat( height + mask_size-1, width + mask_size-1, CV_32F );
|
||||
tstep = temp->step / sizeof(float);
|
||||
|
||||
if( mask_size == 3 )
|
||||
{
|
||||
count = 4;
|
||||
ofs[0] = -1; delta[0] = mask[0];
|
||||
ofs[1] = -tstep-1; delta[1] = mask[1];
|
||||
ofs[2] = -tstep; delta[2] = mask[0];
|
||||
ofs[3] = -tstep+1; delta[3] = mask[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
count = 8;
|
||||
ofs[0] = -1; delta[0] = mask[0];
|
||||
ofs[1] = -tstep-2; delta[1] = mask[2];
|
||||
ofs[2] = -tstep-1; delta[2] = mask[1];
|
||||
ofs[3] = -tstep; delta[3] = mask[0];
|
||||
ofs[4] = -tstep+1; delta[4] = mask[1];
|
||||
ofs[5] = -tstep+2; delta[5] = mask[2];
|
||||
ofs[6] = -tstep*2-1; delta[6] = mask[2];
|
||||
ofs[7] = -tstep*2+1; delta[7] = mask[2];
|
||||
}
|
||||
|
||||
for( i = 0; i < mask_size/2; i++ )
|
||||
{
|
||||
float* t0 = (float*)(temp->data.ptr + i*temp->step);
|
||||
float* t1 = (float*)(temp->data.ptr + (temp->rows - i - 1)*temp->step);
|
||||
|
||||
for( j = 0; j < width + mask_size - 1; j++ )
|
||||
t0[j] = t1[j] = init_val;
|
||||
}
|
||||
|
||||
for( i = 0; i < height; i++ )
|
||||
{
|
||||
uchar* s = _src->data.ptr + i*_src->step;
|
||||
float* tmp = (float*)(temp->data.ptr + temp->step*(i + (mask_size/2))) + (mask_size/2);
|
||||
|
||||
for( j = 0; j < mask_size/2; j++ )
|
||||
tmp[-j-1] = tmp[j + width] = init_val;
|
||||
|
||||
for( j = 0; j < width; j++ )
|
||||
{
|
||||
if( s[j] == 0 )
|
||||
tmp[j] = 0;
|
||||
else
|
||||
{
|
||||
float min_dist = init_val;
|
||||
for( k = 0; k < count; k++ )
|
||||
{
|
||||
float t = tmp[j+ofs[k]] + delta[k];
|
||||
if( min_dist > t )
|
||||
min_dist = t;
|
||||
}
|
||||
tmp[j] = min_dist;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( i = height - 1; i >= 0; i-- )
|
||||
{
|
||||
float* d = (float*)(_dst->data.ptr + i*_dst->step);
|
||||
float* tmp = (float*)(temp->data.ptr + temp->step*(i + (mask_size/2))) + (mask_size/2);
|
||||
|
||||
for( j = width - 1; j >= 0; j-- )
|
||||
{
|
||||
float min_dist = tmp[j];
|
||||
if( min_dist > mask[0] )
|
||||
{
|
||||
for( k = 0; k < count; k++ )
|
||||
{
|
||||
float t = tmp[j-ofs[k]] + delta[k];
|
||||
if( min_dist > t )
|
||||
min_dist = t;
|
||||
}
|
||||
tmp[j] = min_dist;
|
||||
}
|
||||
d[j] = min_dist;
|
||||
}
|
||||
}
|
||||
|
||||
cvReleaseMat( &temp );
|
||||
}
|
||||
|
||||
|
||||
void CV_DisTransTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
{
|
||||
CvMat _input = cvMat(test_mat[INPUT][0]), _output = cvMat(test_mat[REF_OUTPUT][0]);
|
||||
|
||||
cvTsDistTransform( &_input, &_output, dist_type, mask_size, mask, 0 );
|
||||
}
|
||||
|
||||
|
||||
TEST(Imgproc_DistanceTransform, accuracy) { CV_DisTransTest test; test.safe_run(); }
|
||||
|
||||
BIGDATA_TEST(Imgproc_DistanceTransform, large_image_12218)
|
||||
{
|
||||
const int lls_maxcnt = 79992000; // labels's maximum count
|
||||
const int lls_mincnt = 1; // labels's minimum count
|
||||
int i, j, nz;
|
||||
Mat src(8000, 20000, CV_8UC1), dst, labels;
|
||||
for( i = 0; i < src.rows; i++ )
|
||||
for( j = 0; j < src.cols; j++ )
|
||||
src.at<uchar>(i, j) = (j > (src.cols / 2)) ? 0 : 255;
|
||||
|
||||
distanceTransform(src, dst, labels, cv::DIST_L2, cv::DIST_MASK_3, DIST_LABEL_PIXEL);
|
||||
|
||||
double scale = (double)lls_mincnt / (double)lls_maxcnt;
|
||||
labels.convertTo(labels, CV_32SC1, scale);
|
||||
Size size = labels.size();
|
||||
nz = cv::countNonZero(labels);
|
||||
EXPECT_EQ(nz, (size.height*size.width / 2));
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
683
3rdparty/opencv-4.5.4/modules/imgproc/test/test_drawing.cpp
vendored
Normal file
683
3rdparty/opencv-4.5.4/modules/imgproc/test/test_drawing.cpp
vendored
Normal file
@@ -0,0 +1,683 @@
|
||||
/*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 DRAW_TEST_IMAGE
|
||||
|
||||
class CV_DrawingTest : public cvtest::BaseTest
|
||||
{
|
||||
public:
|
||||
CV_DrawingTest(){}
|
||||
protected:
|
||||
void run( int );
|
||||
virtual void draw( Mat& img ) = 0;
|
||||
virtual int checkLineIterator( Mat& img) = 0;
|
||||
virtual int checkLineVirtualIterator() = 0;
|
||||
};
|
||||
|
||||
void CV_DrawingTest::run( int )
|
||||
{
|
||||
Mat testImg, valImg;
|
||||
const string fname = "../highgui/drawing/image.png";
|
||||
string path = ts->get_data_path(), filename;
|
||||
filename = path + fname;
|
||||
|
||||
draw( testImg );
|
||||
|
||||
valImg = imread( filename );
|
||||
if( valImg.empty() )
|
||||
{
|
||||
//imwrite( filename, testImg );
|
||||
ts->printf( ts->LOG, "test image can not be read");
|
||||
#ifdef HAVE_PNG
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
|
||||
#else
|
||||
ts->printf( ts->LOG, "PNG image support is not available");
|
||||
ts->set_failed_test_info(cvtest::TS::OK);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// image should match exactly
|
||||
float err = (float)cvtest::norm( testImg, valImg, NORM_L1 );
|
||||
float Eps = 1;
|
||||
if( err > Eps)
|
||||
{
|
||||
ts->printf( ts->LOG, "NORM_L1 between testImg and valImg is equal %f (larger than %f)\n", err, Eps );
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
|
||||
}
|
||||
else
|
||||
{
|
||||
ts->set_failed_test_info(checkLineIterator( testImg ));
|
||||
}
|
||||
}
|
||||
ts->set_failed_test_info(checkLineVirtualIterator());
|
||||
ts->set_failed_test_info(cvtest::TS::OK);
|
||||
}
|
||||
|
||||
class CV_DrawingTest_CPP : public CV_DrawingTest
|
||||
{
|
||||
public:
|
||||
CV_DrawingTest_CPP() {}
|
||||
protected:
|
||||
virtual void draw( Mat& img );
|
||||
virtual int checkLineIterator( Mat& img);
|
||||
virtual int checkLineVirtualIterator();
|
||||
};
|
||||
|
||||
void CV_DrawingTest_CPP::draw( Mat& img )
|
||||
{
|
||||
Size imgSize( 600, 400 );
|
||||
img.create( imgSize, CV_8UC3 );
|
||||
|
||||
vector<Point> polyline(4);
|
||||
polyline[0] = Point(0, 0);
|
||||
polyline[1] = Point(imgSize.width, 0);
|
||||
polyline[2] = Point(imgSize.width, imgSize.height);
|
||||
polyline[3] = Point(0, imgSize.height);
|
||||
const Point* pts = &polyline[0];
|
||||
int n = (int)polyline.size();
|
||||
fillPoly( img, &pts, &n, 1, Scalar::all(255) );
|
||||
|
||||
Point p1(1,1), p2(3,3);
|
||||
if( clipLine(Rect(0,0,imgSize.width,imgSize.height), p1, p2) && clipLine(imgSize, p1, p2) )
|
||||
circle( img, Point(300,100), 40, Scalar(0,0,255), 3 ); // draw
|
||||
|
||||
p2 = Point(3,imgSize.height+1000);
|
||||
if( clipLine(Rect(0,0,imgSize.width,imgSize.height), p1, p2) && clipLine(imgSize, p1, p2) )
|
||||
circle( img, Point(500,300), 50, cvColorToScalar(255,CV_8UC3), 5, 8, 1 ); // draw
|
||||
|
||||
p1 = Point(imgSize.width,1), p2 = Point(imgSize.width,3);
|
||||
if( clipLine(Rect(0,0,imgSize.width,imgSize.height), p1, p2) && clipLine(imgSize, p1, p2) )
|
||||
circle( img, Point(390,100), 10, Scalar(0,0,255), 3 ); // not draw
|
||||
|
||||
p1 = Point(imgSize.width-1,1), p2 = Point(imgSize.width,3);
|
||||
if( clipLine(Rect(0,0,imgSize.width,imgSize.height), p1, p2) && clipLine(imgSize, p1, p2) )
|
||||
ellipse( img, Point(390,100), Size(20,30), 60, 0, 220.0, Scalar(0,200,0), 4 ); //draw
|
||||
|
||||
ellipse( img, RotatedRect(Point(100,200),Size(200,100),160), Scalar(200,200,255), 5 );
|
||||
|
||||
polyline.clear();
|
||||
ellipse2Poly( Point(430,180), Size(100,150), 30, 0, 150, 20, polyline );
|
||||
pts = &polyline[0];
|
||||
n = (int)polyline.size();
|
||||
polylines( img, &pts, &n, 1, false, Scalar(0,0,150), 4, CV_AA );
|
||||
n = 0;
|
||||
for( vector<Point>::const_iterator it = polyline.begin(); n < (int)polyline.size()-1; ++it, n++ )
|
||||
{
|
||||
line( img, *it, *(it+1), Scalar(50,250,100));
|
||||
}
|
||||
|
||||
polyline.clear();
|
||||
ellipse2Poly( Point(500,300), Size(50,80), 0, 0, 180, 10, polyline );
|
||||
pts = &polyline[0];
|
||||
n = (int)polyline.size();
|
||||
polylines( img, &pts, &n, 1, true, Scalar(100,200,100), 20 );
|
||||
fillConvexPoly( img, pts, n, Scalar(0, 80, 0) );
|
||||
|
||||
polyline.resize(8);
|
||||
// external rectengular
|
||||
polyline[0] = Point(0, 0);
|
||||
polyline[1] = Point(80, 0);
|
||||
polyline[2] = Point(80, 80);
|
||||
polyline[3] = Point(0, 80);
|
||||
// internal rectangular
|
||||
polyline[4] = Point(20, 20);
|
||||
polyline[5] = Point(60, 20);
|
||||
polyline[6] = Point(60, 60);
|
||||
polyline[7] = Point(20, 60);
|
||||
const Point* ppts[] = {&polyline[0], &polyline[0]+4};
|
||||
int pn[] = {4, 4};
|
||||
fillPoly( img, ppts, pn, 2, Scalar(100, 100, 0), 8, 0, Point(500, 20) );
|
||||
|
||||
rectangle( img, Point(0, 300), Point(50, 398), Scalar(0,0,255) );
|
||||
|
||||
string text1 = "OpenCV";
|
||||
int baseline = 0, thickness = 3, fontFace = FONT_HERSHEY_SCRIPT_SIMPLEX;
|
||||
float fontScale = 2;
|
||||
Size textSize = getTextSize( text1, fontFace, fontScale, thickness, &baseline);
|
||||
baseline += thickness;
|
||||
Point textOrg((img.cols - textSize.width)/2, (img.rows + textSize.height)/2);
|
||||
rectangle(img, textOrg + Point(0, baseline), textOrg + Point(textSize.width, -textSize.height), Scalar(0,0,255));
|
||||
line(img, textOrg + Point(0, thickness), textOrg + Point(textSize.width, thickness), Scalar(0, 0, 255));
|
||||
putText(img, text1, textOrg, fontFace, fontScale, Scalar(150,0,150), thickness, 8);
|
||||
|
||||
string text2 = "abcdefghijklmnopqrstuvwxyz1234567890";
|
||||
Scalar color(200,0,0);
|
||||
fontScale = 0.5, thickness = 1;
|
||||
int dist = 5;
|
||||
|
||||
textSize = getTextSize( text2, FONT_HERSHEY_SIMPLEX, fontScale, thickness, &baseline);
|
||||
textOrg = Point(5,5)+Point(0,textSize.height+dist);
|
||||
putText(img, text2, textOrg, FONT_HERSHEY_SIMPLEX, fontScale, color, thickness, CV_AA);
|
||||
|
||||
fontScale = 1;
|
||||
textSize = getTextSize( text2, FONT_HERSHEY_PLAIN, fontScale, thickness, &baseline);
|
||||
textOrg += Point(0,textSize.height+dist);
|
||||
putText(img, text2, textOrg, FONT_HERSHEY_PLAIN, fontScale, color, thickness, CV_AA);
|
||||
|
||||
fontScale = 0.5;
|
||||
textSize = getTextSize( text2, FONT_HERSHEY_DUPLEX, fontScale, thickness, &baseline);
|
||||
textOrg += Point(0,textSize.height+dist);
|
||||
putText(img, text2, textOrg, FONT_HERSHEY_DUPLEX, fontScale, color, thickness, CV_AA);
|
||||
|
||||
textSize = getTextSize( text2, FONT_HERSHEY_COMPLEX, fontScale, thickness, &baseline);
|
||||
textOrg += Point(0,textSize.height+dist);
|
||||
putText(img, text2, textOrg, FONT_HERSHEY_COMPLEX, fontScale, color, thickness, CV_AA);
|
||||
|
||||
textSize = getTextSize( text2, FONT_HERSHEY_TRIPLEX, fontScale, thickness, &baseline);
|
||||
textOrg += Point(0,textSize.height+dist);
|
||||
putText(img, text2, textOrg, FONT_HERSHEY_TRIPLEX, fontScale, color, thickness, CV_AA);
|
||||
|
||||
fontScale = 1;
|
||||
textSize = getTextSize( text2, FONT_HERSHEY_COMPLEX_SMALL, fontScale, thickness, &baseline);
|
||||
textOrg += Point(0,180) + Point(0,textSize.height+dist);
|
||||
putText(img, text2, textOrg, FONT_HERSHEY_COMPLEX_SMALL, fontScale, color, thickness, CV_AA);
|
||||
|
||||
textSize = getTextSize( text2, FONT_HERSHEY_SCRIPT_SIMPLEX, fontScale, thickness, &baseline);
|
||||
textOrg += Point(0,textSize.height+dist);
|
||||
putText(img, text2, textOrg, FONT_HERSHEY_SCRIPT_SIMPLEX, fontScale, color, thickness, CV_AA);
|
||||
|
||||
textSize = getTextSize( text2, FONT_HERSHEY_SCRIPT_COMPLEX, fontScale, thickness, &baseline);
|
||||
textOrg += Point(0,textSize.height+dist);
|
||||
putText(img, text2, textOrg, FONT_HERSHEY_SCRIPT_COMPLEX, fontScale, color, thickness, CV_AA);
|
||||
|
||||
dist = 15, fontScale = 0.5;
|
||||
textSize = getTextSize( text2, FONT_ITALIC, fontScale, thickness, &baseline);
|
||||
textOrg += Point(0,textSize.height+dist);
|
||||
putText(img, text2, textOrg, FONT_ITALIC, fontScale, color, thickness, CV_AA);
|
||||
}
|
||||
|
||||
int CV_DrawingTest_CPP::checkLineIterator( Mat& img )
|
||||
{
|
||||
LineIterator it( img, Point(0,300), Point(1000, 300) );
|
||||
for(int i = 0; i < it.count; ++it, i++ )
|
||||
{
|
||||
Vec3b v = (Vec3b)(*(*it)) - img.at<Vec3b>(300,i);
|
||||
float err = (float)cvtest::norm( v, NORM_L2 );
|
||||
if( err != 0 )
|
||||
{
|
||||
ts->printf( ts->LOG, "LineIterator works incorrect" );
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT);
|
||||
}
|
||||
}
|
||||
ts->set_failed_test_info(cvtest::TS::OK);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CV_DrawingTest_CPP::checkLineVirtualIterator( )
|
||||
{
|
||||
RNG randomGenerator(1);
|
||||
for (size_t test = 0; test < 10000; ++test)
|
||||
{
|
||||
int width = randomGenerator.uniform(0, 512+1);
|
||||
int height = randomGenerator.uniform(0, 512+1);
|
||||
int x1 = randomGenerator.uniform(-512, 1024+1);
|
||||
int y1 = randomGenerator.uniform(-512, 1024+1);
|
||||
int x2 = randomGenerator.uniform(-512, 1024+1);
|
||||
int y2 = randomGenerator.uniform(-512, 1024+1);
|
||||
int x3 = randomGenerator.uniform(-512, 1024+1);
|
||||
int y3 = randomGenerator.uniform(-512, 1024+1);
|
||||
int channels = randomGenerator.uniform(1, 3+1);
|
||||
Mat m(cv::Size(width, height), CV_MAKETYPE(8U, channels));
|
||||
Point p1(x1, y1);
|
||||
Point p2(x2, y2);
|
||||
Point offset(x3, y3);
|
||||
LineIterator it( m, p1, p2 );
|
||||
LineIterator vit(Rect(offset.x, offset.y, width, height), p1 + offset, p2 + offset);
|
||||
if (it.count != vit.count)
|
||||
{
|
||||
ts->printf( ts->LOG, "virtual LineIterator works incorrectly" );
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = 0; i < it.count; ++it, ++vit, i++ )
|
||||
{
|
||||
Point pIt = it.pos();
|
||||
Point pVit = vit.pos() - offset;
|
||||
if (pIt != pVit)
|
||||
{
|
||||
ts->printf( ts->LOG, "virtual LineIterator works incorrectly" );
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ts->set_failed_test_info(cvtest::TS::OK);
|
||||
return 0;
|
||||
}
|
||||
|
||||
class CV_DrawingTest_Far : public CV_DrawingTest_CPP
|
||||
{
|
||||
public:
|
||||
CV_DrawingTest_Far() {}
|
||||
protected:
|
||||
virtual void draw(Mat& img);
|
||||
};
|
||||
|
||||
void CV_DrawingTest_Far::draw(Mat& img)
|
||||
{
|
||||
Size imgSize(32768 + 600, 400);
|
||||
img.create(imgSize, CV_8UC3);
|
||||
|
||||
vector<Point> polyline(4);
|
||||
polyline[0] = Point(32768 + 0, 0);
|
||||
polyline[1] = Point(imgSize.width, 0);
|
||||
polyline[2] = Point(imgSize.width, imgSize.height);
|
||||
polyline[3] = Point(32768 + 0, imgSize.height);
|
||||
const Point* pts = &polyline[0];
|
||||
int n = (int)polyline.size();
|
||||
fillPoly(img, &pts, &n, 1, Scalar::all(255));
|
||||
|
||||
Point p1(32768 + 1, 1), p2(32768 + 3, 3);
|
||||
if (clipLine(Rect(32768 + 0, 0, imgSize.width, imgSize.height), p1, p2) && clipLine(imgSize, p1, p2))
|
||||
circle(img, Point(32768 + 300, 100), 40, Scalar(0, 0, 255), 3); // draw
|
||||
|
||||
p2 = Point(32768 + 3, imgSize.height + 1000);
|
||||
if (clipLine(Rect(32768 + 0, 0, imgSize.width, imgSize.height), p1, p2) && clipLine(imgSize, p1, p2))
|
||||
circle(img, Point(65536 + 500, 300), 50, cvColorToScalar(255, CV_8UC3), 5, 8, 1); // draw
|
||||
|
||||
p1 = Point(imgSize.width, 1), p2 = Point(imgSize.width, 3);
|
||||
if (clipLine(Rect(32768 + 0, 0, imgSize.width, imgSize.height), p1, p2) && clipLine(imgSize, p1, p2))
|
||||
circle(img, Point(32768 + 390, 100), 10, Scalar(0, 0, 255), 3); // not draw
|
||||
|
||||
p1 = Point(imgSize.width - 1, 1), p2 = Point(imgSize.width, 3);
|
||||
if (clipLine(Rect(32768 + 0, 0, imgSize.width, imgSize.height), p1, p2) && clipLine(imgSize, p1, p2))
|
||||
ellipse(img, Point(32768 + 390, 100), Size(20, 30), 60, 0, 220.0, Scalar(0, 200, 0), 4); //draw
|
||||
|
||||
ellipse(img, RotatedRect(Point(32768 + 100, 200), Size(200, 100), 160), Scalar(200, 200, 255), 5);
|
||||
|
||||
polyline.clear();
|
||||
ellipse2Poly(Point(32768 + 430, 180), Size(100, 150), 30, 0, 150, 20, polyline);
|
||||
pts = &polyline[0];
|
||||
n = (int)polyline.size();
|
||||
polylines(img, &pts, &n, 1, false, Scalar(0, 0, 150), 4, CV_AA);
|
||||
n = 0;
|
||||
for (vector<Point>::const_iterator it = polyline.begin(); n < (int)polyline.size() - 1; ++it, n++)
|
||||
{
|
||||
line(img, *it, *(it + 1), Scalar(50, 250, 100));
|
||||
}
|
||||
|
||||
polyline.clear();
|
||||
ellipse2Poly(Point(32768 + 500, 300), Size(50, 80), 0, 0, 180, 10, polyline);
|
||||
pts = &polyline[0];
|
||||
n = (int)polyline.size();
|
||||
polylines(img, &pts, &n, 1, true, Scalar(100, 200, 100), 20);
|
||||
fillConvexPoly(img, pts, n, Scalar(0, 80, 0));
|
||||
|
||||
polyline.resize(8);
|
||||
// external rectengular
|
||||
polyline[0] = Point(32768 + 0, 0);
|
||||
polyline[1] = Point(32768 + 80, 0);
|
||||
polyline[2] = Point(32768 + 80, 80);
|
||||
polyline[3] = Point(32768 + 0, 80);
|
||||
// internal rectangular
|
||||
polyline[4] = Point(32768 + 20, 20);
|
||||
polyline[5] = Point(32768 + 60, 20);
|
||||
polyline[6] = Point(32768 + 60, 60);
|
||||
polyline[7] = Point(32768 + 20, 60);
|
||||
const Point* ppts[] = { &polyline[0], &polyline[0] + 4 };
|
||||
int pn[] = { 4, 4 };
|
||||
fillPoly(img, ppts, pn, 2, Scalar(100, 100, 0), 8, 0, Point(500, 20));
|
||||
|
||||
rectangle(img, Point(32768 + 0, 300), Point(32768 + 50, 398), Scalar(0, 0, 255));
|
||||
|
||||
string text1 = "OpenCV";
|
||||
int baseline = 0, thickness = 3, fontFace = FONT_HERSHEY_SCRIPT_SIMPLEX;
|
||||
float fontScale = 2;
|
||||
Size textSize = getTextSize(text1, fontFace, fontScale, thickness, &baseline);
|
||||
baseline += thickness;
|
||||
Point textOrg((32768 + img.cols - textSize.width) / 2, (img.rows + textSize.height) / 2);
|
||||
rectangle(img, textOrg + Point(0, baseline), textOrg + Point(textSize.width, -textSize.height), Scalar(0, 0, 255));
|
||||
line(img, textOrg + Point(0, thickness), textOrg + Point(textSize.width, thickness), Scalar(0, 0, 255));
|
||||
putText(img, text1, textOrg, fontFace, fontScale, Scalar(150, 0, 150), thickness, 8);
|
||||
|
||||
string text2 = "abcdefghijklmnopqrstuvwxyz1234567890";
|
||||
Scalar color(200, 0, 0);
|
||||
fontScale = 0.5, thickness = 1;
|
||||
int dist = 5;
|
||||
|
||||
textSize = getTextSize(text2, FONT_HERSHEY_SIMPLEX, fontScale, thickness, &baseline);
|
||||
textOrg = Point(32768 + 5, 5) + Point(0, textSize.height + dist);
|
||||
putText(img, text2, textOrg, FONT_HERSHEY_SIMPLEX, fontScale, color, thickness, CV_AA);
|
||||
|
||||
fontScale = 1;
|
||||
textSize = getTextSize(text2, FONT_HERSHEY_PLAIN, fontScale, thickness, &baseline);
|
||||
textOrg += Point(0, textSize.height + dist);
|
||||
putText(img, text2, textOrg, FONT_HERSHEY_PLAIN, fontScale, color, thickness, CV_AA);
|
||||
|
||||
fontScale = 0.5;
|
||||
textSize = getTextSize(text2, FONT_HERSHEY_DUPLEX, fontScale, thickness, &baseline);
|
||||
textOrg += Point(0, textSize.height + dist);
|
||||
putText(img, text2, textOrg, FONT_HERSHEY_DUPLEX, fontScale, color, thickness, CV_AA);
|
||||
|
||||
textSize = getTextSize(text2, FONT_HERSHEY_COMPLEX, fontScale, thickness, &baseline);
|
||||
textOrg += Point(0, textSize.height + dist);
|
||||
putText(img, text2, textOrg, FONT_HERSHEY_COMPLEX, fontScale, color, thickness, CV_AA);
|
||||
|
||||
textSize = getTextSize(text2, FONT_HERSHEY_TRIPLEX, fontScale, thickness, &baseline);
|
||||
textOrg += Point(0, textSize.height + dist);
|
||||
putText(img, text2, textOrg, FONT_HERSHEY_TRIPLEX, fontScale, color, thickness, CV_AA);
|
||||
|
||||
fontScale = 1;
|
||||
textSize = getTextSize(text2, FONT_HERSHEY_COMPLEX_SMALL, fontScale, thickness, &baseline);
|
||||
textOrg += Point(0, 180) + Point(0, textSize.height + dist);
|
||||
putText(img, text2, textOrg, FONT_HERSHEY_COMPLEX_SMALL, fontScale, color, thickness, CV_AA);
|
||||
|
||||
textSize = getTextSize(text2, FONT_HERSHEY_SCRIPT_SIMPLEX, fontScale, thickness, &baseline);
|
||||
textOrg += Point(0, textSize.height + dist);
|
||||
putText(img, text2, textOrg, FONT_HERSHEY_SCRIPT_SIMPLEX, fontScale, color, thickness, CV_AA);
|
||||
|
||||
textSize = getTextSize(text2, FONT_HERSHEY_SCRIPT_COMPLEX, fontScale, thickness, &baseline);
|
||||
textOrg += Point(0, textSize.height + dist);
|
||||
putText(img, text2, textOrg, FONT_HERSHEY_SCRIPT_COMPLEX, fontScale, color, thickness, CV_AA);
|
||||
|
||||
dist = 15, fontScale = 0.5;
|
||||
textSize = getTextSize(text2, FONT_ITALIC, fontScale, thickness, &baseline);
|
||||
textOrg += Point(0, textSize.height + dist);
|
||||
putText(img, text2, textOrg, FONT_ITALIC, fontScale, color, thickness, CV_AA);
|
||||
|
||||
img = img(Rect(32768, 0, 600, 400)).clone();
|
||||
}
|
||||
|
||||
TEST(Drawing, cpp_regression) { CV_DrawingTest_CPP test; test.safe_run(); }
|
||||
TEST(Drawing, far_regression) { CV_DrawingTest_Far test; test.safe_run(); }
|
||||
|
||||
class CV_FillConvexPolyTest : public cvtest::BaseTest
|
||||
{
|
||||
public:
|
||||
CV_FillConvexPolyTest() {}
|
||||
~CV_FillConvexPolyTest() {}
|
||||
protected:
|
||||
void run(int)
|
||||
{
|
||||
vector<Point> line1;
|
||||
vector<Point> line2;
|
||||
|
||||
line1.push_back(Point(1, 1));
|
||||
line1.push_back(Point(5, 1));
|
||||
line1.push_back(Point(5, 8));
|
||||
line1.push_back(Point(1, 8));
|
||||
|
||||
line2.push_back(Point(2, 2));
|
||||
line2.push_back(Point(10, 2));
|
||||
line2.push_back(Point(10, 16));
|
||||
line2.push_back(Point(2, 16));
|
||||
|
||||
Mat gray0(10,10,CV_8U, Scalar(0));
|
||||
fillConvexPoly(gray0, line1, Scalar(255), 8, 0);
|
||||
int nz1 = countNonZero(gray0);
|
||||
|
||||
fillConvexPoly(gray0, line2, Scalar(0), 8, 1);
|
||||
int nz2 = countNonZero(gray0)/255;
|
||||
|
||||
CV_Assert( nz1 == 40 && nz2 == 0 );
|
||||
}
|
||||
};
|
||||
|
||||
TEST(Drawing, fillconvexpoly_clipping) { CV_FillConvexPolyTest test; test.safe_run(); }
|
||||
|
||||
class CV_DrawingTest_UTF8 : public cvtest::BaseTest
|
||||
{
|
||||
public:
|
||||
CV_DrawingTest_UTF8() {}
|
||||
~CV_DrawingTest_UTF8() {}
|
||||
protected:
|
||||
void run(int)
|
||||
{
|
||||
vector<string> lines;
|
||||
lines.push_back("abcdefghijklmnopqrstuvwxyz1234567890");
|
||||
// cyrillic letters small
|
||||
lines.push_back("\xD0\xB0\xD0\xB1\xD0\xB2\xD0\xB3\xD0\xB4\xD0\xB5\xD1\x91\xD0\xB6\xD0\xB7"
|
||||
"\xD0\xB8\xD0\xB9\xD0\xBA\xD0\xBB\xD0\xBC\xD0\xBD\xD0\xBE\xD0\xBF\xD1\x80"
|
||||
"\xD1\x81\xD1\x82\xD1\x83\xD1\x84\xD1\x85\xD1\x86\xD1\x87\xD1\x88\xD1\x89"
|
||||
"\xD1\x8A\xD1\x8B\xD1\x8C\xD1\x8D\xD1\x8E\xD1\x8F");
|
||||
// cyrillic letters capital
|
||||
lines.push_back("\xD0\x90\xD0\x91\xD0\x92\xD0\x93\xD0\x94\xD0\x95\xD0\x81\xD0\x96\xD0\x97"
|
||||
"\xD0\x98\xD0\x99\xD0\x9A\xD0\x9B\xD0\x9C\xD0\x9D\xD0\x9E\xD0\x9F\xD0\xA0"
|
||||
"\xD0\xA1\xD0\xA2\xD0\xA3\xD0\xA4\xD0\xA5\xD0\xA6\xD0\xA7\xD0\xA8\xD0\xA9"
|
||||
"\xD0\xAA\xD0\xAB\xD0\xAC\xD0\xAD\xD0\xAE\xD0\xAF");
|
||||
// bounds
|
||||
lines.push_back("-\xD0\x80-\xD0\x8E-\xD0\x8F-");
|
||||
lines.push_back("-\xD1\x90-\xD1\x91-\xD1\xBF-");
|
||||
// bad utf8
|
||||
lines.push_back("-\x81-\x82-\x83-");
|
||||
lines.push_back("--\xF0--");
|
||||
lines.push_back("-\xF0");
|
||||
|
||||
vector<int> fonts;
|
||||
fonts.push_back(FONT_HERSHEY_SIMPLEX);
|
||||
fonts.push_back(FONT_HERSHEY_PLAIN);
|
||||
fonts.push_back(FONT_HERSHEY_DUPLEX);
|
||||
fonts.push_back(FONT_HERSHEY_COMPLEX);
|
||||
fonts.push_back(FONT_HERSHEY_TRIPLEX);
|
||||
fonts.push_back(FONT_HERSHEY_COMPLEX_SMALL);
|
||||
fonts.push_back(FONT_HERSHEY_SCRIPT_SIMPLEX);
|
||||
fonts.push_back(FONT_HERSHEY_SCRIPT_COMPLEX);
|
||||
|
||||
vector<Mat> results;
|
||||
Size bigSize(0, 0);
|
||||
for (vector<int>::const_iterator font = fonts.begin(); font != fonts.end(); ++font)
|
||||
{
|
||||
for (int italic = 0; italic <= FONT_ITALIC; italic += FONT_ITALIC)
|
||||
{
|
||||
for (vector<string>::const_iterator line = lines.begin(); line != lines.end(); ++line)
|
||||
{
|
||||
const float fontScale = 1;
|
||||
const int thickness = 1;
|
||||
const Scalar color(20,20,20);
|
||||
int baseline = 0;
|
||||
|
||||
Size textSize = getTextSize(*line, *font | italic, fontScale, thickness, &baseline);
|
||||
Point textOrg(0, textSize.height + 2);
|
||||
Mat img(textSize + Size(0, baseline), CV_8UC3, Scalar(255, 255, 255));
|
||||
putText(img, *line, textOrg, *font | italic, fontScale, color, thickness, CV_AA);
|
||||
|
||||
results.push_back(img);
|
||||
bigSize.width = max(bigSize.width, img.size().width);
|
||||
bigSize.height += img.size().height + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int shift = 0;
|
||||
Mat result(bigSize, CV_8UC3, Scalar(100, 100, 100));
|
||||
for (vector<Mat>::const_iterator img = results.begin(); img != results.end(); ++img)
|
||||
{
|
||||
Rect roi(Point(0, shift), img->size());
|
||||
Mat sub(result, roi);
|
||||
img->copyTo(sub);
|
||||
shift += img->size().height + 1;
|
||||
}
|
||||
if (cvtest::debugLevel > 0)
|
||||
imwrite("all_fonts.png", result);
|
||||
}
|
||||
};
|
||||
|
||||
TEST(Drawing, utf8_support) { CV_DrawingTest_UTF8 test; test.safe_run(); }
|
||||
|
||||
|
||||
TEST(Drawing, _914)
|
||||
{
|
||||
const int rows = 256;
|
||||
const int cols = 256;
|
||||
|
||||
Mat img(rows, cols, CV_8UC1, Scalar(255));
|
||||
|
||||
line(img, Point(0, 10), Point(255, 10), Scalar(0), 2, 4);
|
||||
line(img, Point(-5, 20), Point(260, 20), Scalar(0), 2, 4);
|
||||
line(img, Point(10, 0), Point(10, 255), Scalar(0), 2, 4);
|
||||
|
||||
double x0 = 0.0/pow(2.0, -2.0);
|
||||
double x1 = 255.0/pow(2.0, -2.0);
|
||||
double y = 30.5/pow(2.0, -2.0);
|
||||
|
||||
line(img, Point(int(x0), int(y)), Point(int(x1), int(y)), Scalar(0), 2, 4, 2);
|
||||
|
||||
int pixelsDrawn = rows*cols - countNonZero(img);
|
||||
ASSERT_EQ( (3*rows + cols)*3 - 3*9, pixelsDrawn);
|
||||
}
|
||||
|
||||
TEST(Drawing, polylines_empty)
|
||||
{
|
||||
Mat img(100, 100, CV_8UC1, Scalar(0));
|
||||
vector<Point> pts; // empty
|
||||
polylines(img, pts, false, Scalar(255));
|
||||
int cnt = countNonZero(img);
|
||||
ASSERT_EQ(cnt, 0);
|
||||
}
|
||||
|
||||
TEST(Drawing, polylines)
|
||||
{
|
||||
Mat img(100, 100, CV_8UC1, Scalar(0));
|
||||
vector<Point> pts;
|
||||
pts.push_back(Point(0, 0));
|
||||
pts.push_back(Point(20, 0));
|
||||
polylines(img, pts, false, Scalar(255));
|
||||
int cnt = countNonZero(img);
|
||||
ASSERT_EQ(cnt, 21);
|
||||
}
|
||||
|
||||
TEST(Drawing, longline)
|
||||
{
|
||||
Mat mat = Mat::zeros(256, 256, CV_8UC1);
|
||||
|
||||
line(mat, cv::Point(34, 204), cv::Point(46400, 47400), cv::Scalar(255), 3);
|
||||
EXPECT_EQ(310, cv::countNonZero(mat));
|
||||
|
||||
Point pt[6];
|
||||
pt[0].x = 32;
|
||||
pt[0].y = 204;
|
||||
pt[1].x = 34;
|
||||
pt[1].y = 202;
|
||||
pt[2].x = 87;
|
||||
pt[2].y = 255;
|
||||
pt[3].x = 82;
|
||||
pt[3].y = 255;
|
||||
pt[4].x = 37;
|
||||
pt[4].y = 210;
|
||||
pt[5].x = 37;
|
||||
pt[5].y = 209;
|
||||
fillConvexPoly(mat, pt, 6, cv::Scalar(0));
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(mat));
|
||||
}
|
||||
|
||||
|
||||
TEST(Drawing, putText_no_garbage)
|
||||
{
|
||||
Size sz(640, 480);
|
||||
Mat mat = Mat::zeros(sz, CV_8UC1);
|
||||
|
||||
mat = Scalar::all(0);
|
||||
putText(mat, "029", Point(10, 350), 0, 10, Scalar(128), 15);
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(mat(Rect(0, 0, 10, sz.height))));
|
||||
EXPECT_EQ(0, cv::countNonZero(mat(Rect(sz.width-10, 0, 10, sz.height))));
|
||||
EXPECT_EQ(0, cv::countNonZero(mat(Rect(205, 0, 10, sz.height))));
|
||||
EXPECT_EQ(0, cv::countNonZero(mat(Rect(405, 0, 10, sz.height))));
|
||||
}
|
||||
|
||||
|
||||
TEST(Drawing, line)
|
||||
{
|
||||
Mat mat = Mat::zeros(Size(100,100), CV_8UC1);
|
||||
|
||||
ASSERT_THROW(line(mat, Point(1,1),Point(99,99),Scalar(255),0), cv::Exception);
|
||||
}
|
||||
|
||||
TEST(Drawing, regression_16308)
|
||||
{
|
||||
Mat_<uchar> img(Size(100, 100), (uchar)0);
|
||||
circle(img, Point(50, 50), 50, 255, 1, LINE_AA);
|
||||
EXPECT_NE(0, (int)img.at<uchar>(0, 50));
|
||||
EXPECT_NE(0, (int)img.at<uchar>(50, 0));
|
||||
EXPECT_NE(0, (int)img.at<uchar>(50, 99));
|
||||
EXPECT_NE(0, (int)img.at<uchar>(99, 50));
|
||||
}
|
||||
|
||||
TEST(Drawing, fillpoly_circle)
|
||||
{
|
||||
Mat img_c(640, 480, CV_8UC3, Scalar::all(0));
|
||||
Mat img_fp = img_c.clone(), img_fcp = img_c.clone(), img_fp3 = img_c.clone();
|
||||
|
||||
Point center1(img_c.cols/2, img_c.rows/2);
|
||||
Point center2(img_c.cols/10, img_c.rows*3/4);
|
||||
Point center3 = Point(img_c.cols, img_c.rows) - center2;
|
||||
int radius = img_c.rows/4;
|
||||
int radius_small = img_c.cols/15;
|
||||
Scalar color(0, 0, 255);
|
||||
|
||||
circle(img_c, center1, radius, color, -1);
|
||||
|
||||
// check that circle, fillConvexPoly and fillPoly
|
||||
// give almost the same result then asked to draw a single circle
|
||||
vector<Point> vtx;
|
||||
ellipse2Poly(center1, Size(radius, radius), 0, 0, 360, 1, vtx);
|
||||
fillConvexPoly(img_fcp, vtx, color);
|
||||
fillPoly(img_fp, vtx, color);
|
||||
double diff_fp = cv::norm(img_c, img_fp, NORM_L1)/(255*radius*2*CV_PI);
|
||||
double diff_fcp = cv::norm(img_c, img_fcp, NORM_L1)/(255*radius*2*CV_PI);
|
||||
EXPECT_LT(diff_fp, 1.);
|
||||
EXPECT_LT(diff_fcp, 1.);
|
||||
|
||||
// check that fillPoly can draw 3 disjoint circles at once
|
||||
circle(img_c, center2, radius_small, color, -1);
|
||||
circle(img_c, center3, radius_small, color, -1);
|
||||
|
||||
vector<vector<Point> > vtx3(3);
|
||||
vtx3[0] = vtx;
|
||||
ellipse2Poly(center2, Size(radius_small, radius_small), 0, 0, 360, 1, vtx3[1]);
|
||||
ellipse2Poly(center3, Size(radius_small, radius_small), 0, 0, 360, 1, vtx3[2]);
|
||||
fillPoly(img_fp3, vtx3, color);
|
||||
double diff_fp3 = cv::norm(img_c, img_fp3, NORM_L1)/(255*(radius+radius_small*2)*2*CV_PI);
|
||||
EXPECT_LT(diff_fp3, 1.);
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
93
3rdparty/opencv-4.5.4/modules/imgproc/test/test_emd.cpp
vendored
Normal file
93
3rdparty/opencv-4.5.4/modules/imgproc/test/test_emd.cpp
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
/*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.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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_EMDTest : public cvtest::BaseTest
|
||||
{
|
||||
public:
|
||||
CV_EMDTest();
|
||||
protected:
|
||||
void run(int);
|
||||
};
|
||||
|
||||
|
||||
CV_EMDTest::CV_EMDTest()
|
||||
{
|
||||
}
|
||||
|
||||
void CV_EMDTest::run( int )
|
||||
{
|
||||
int code = cvtest::TS::OK;
|
||||
const double success_error_level = 1e-6;
|
||||
#define M 10000
|
||||
double emd0 = 2460./210;
|
||||
static float cost[] =
|
||||
{
|
||||
16, 16, 13, 22, 17,
|
||||
14, 14, 13, 19, 15,
|
||||
19, 19, 20, 23, M,
|
||||
M , 0, M, 0, 0
|
||||
};
|
||||
static float w1[] = { 50, 60, 50, 50 },
|
||||
w2[] = { 30, 20, 70, 30, 60 };
|
||||
Mat _w1(4, 1, CV_32F, w1);
|
||||
Mat _w2(5, 1, CV_32F, w2);
|
||||
Mat _cost(_w1.rows, _w2.rows, CV_32F, cost);
|
||||
|
||||
float emd = EMD( _w1, _w2, -1, _cost );
|
||||
if( fabs( emd - emd0 ) > success_error_level*emd0 )
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG,
|
||||
"The computed distance is %.2f, while it should be %.2f\n", emd, emd0 );
|
||||
code = cvtest::TS::FAIL_BAD_ACCURACY;
|
||||
}
|
||||
|
||||
if( code < 0 )
|
||||
ts->set_failed_test_info( code );
|
||||
}
|
||||
|
||||
TEST(Imgproc_EMD, regression) { CV_EMDTest test; test.safe_run(); }
|
||||
|
||||
}} // namespace
|
||||
/* End of file. */
|
||||
2359
3rdparty/opencv-4.5.4/modules/imgproc/test/test_filter.cpp
vendored
Normal file
2359
3rdparty/opencv-4.5.4/modules/imgproc/test/test_filter.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
105
3rdparty/opencv-4.5.4/modules/imgproc/test/test_fitellipse.cpp
vendored
Normal file
105
3rdparty/opencv-4.5.4/modules/imgproc/test/test_fitellipse.cpp
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
// 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) 2016, Itseez, Inc, all rights reserved.
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
// return true if point lies inside ellipse
|
||||
static bool check_pt_in_ellipse(const Point2f& pt, const RotatedRect& el) {
|
||||
Point2f to_pt = pt - el.center;
|
||||
double pt_angle = atan2(to_pt.y, to_pt.x);
|
||||
double el_angle = el.angle * CV_PI / 180;
|
||||
double x_dist = 0.5 * el.size.width * cos(pt_angle + el_angle);
|
||||
double y_dist = 0.5 * el.size.height * sin(pt_angle + el_angle);
|
||||
double el_dist = sqrt(x_dist * x_dist + y_dist * y_dist);
|
||||
return cv::norm(to_pt) < el_dist;
|
||||
}
|
||||
|
||||
// Return true if mass center of fitted points lies inside ellipse
|
||||
static bool fit_and_check_ellipse(const vector<Point2f>& pts) {
|
||||
RotatedRect ellipse = fitEllipseDirect(pts); // fitEllipseAMS() also works fine
|
||||
|
||||
Point2f mass_center;
|
||||
for (size_t i = 0; i < pts.size(); i++) {
|
||||
mass_center += pts[i];
|
||||
}
|
||||
mass_center /= (float)pts.size();
|
||||
|
||||
return check_pt_in_ellipse(mass_center, ellipse);
|
||||
}
|
||||
|
||||
TEST(Imgproc_FitEllipse_Issue_4515, accuracy) {
|
||||
vector<Point2f> pts;
|
||||
pts.push_back(Point2f(327, 317));
|
||||
pts.push_back(Point2f(328, 316));
|
||||
pts.push_back(Point2f(329, 315));
|
||||
pts.push_back(Point2f(330, 314));
|
||||
pts.push_back(Point2f(331, 314));
|
||||
pts.push_back(Point2f(332, 314));
|
||||
pts.push_back(Point2f(333, 315));
|
||||
pts.push_back(Point2f(333, 316));
|
||||
pts.push_back(Point2f(333, 317));
|
||||
pts.push_back(Point2f(333, 318));
|
||||
pts.push_back(Point2f(333, 319));
|
||||
pts.push_back(Point2f(333, 320));
|
||||
|
||||
EXPECT_TRUE(fit_and_check_ellipse(pts));
|
||||
}
|
||||
|
||||
TEST(Imgproc_FitEllipse_Issue_6544, accuracy) {
|
||||
vector<Point2f> pts;
|
||||
pts.push_back(Point2f(924.784f, 764.160f));
|
||||
pts.push_back(Point2f(928.388f, 615.903f));
|
||||
pts.push_back(Point2f(847.4f, 888.014f));
|
||||
pts.push_back(Point2f(929.406f, 741.675f));
|
||||
pts.push_back(Point2f(904.564f, 825.605f));
|
||||
pts.push_back(Point2f(926.742f, 760.746f));
|
||||
pts.push_back(Point2f(863.479f, 873.406f));
|
||||
pts.push_back(Point2f(910.987f, 808.863f));
|
||||
pts.push_back(Point2f(929.145f, 744.976f));
|
||||
pts.push_back(Point2f(917.474f, 791.823f));
|
||||
|
||||
EXPECT_TRUE(fit_and_check_ellipse(pts));
|
||||
}
|
||||
|
||||
TEST(Imgproc_FitEllipse_Issue_10270, accuracy) {
|
||||
vector<Point2f> pts;
|
||||
float scale = 1;
|
||||
Point2f shift(0, 0);
|
||||
pts.push_back(Point2f(0, 1)*scale+shift);
|
||||
pts.push_back(Point2f(0, 2)*scale+shift);
|
||||
pts.push_back(Point2f(0, 3)*scale+shift);
|
||||
pts.push_back(Point2f(2, 3)*scale+shift);
|
||||
pts.push_back(Point2f(0, 4)*scale+shift);
|
||||
|
||||
// check that we get almost vertical ellipse centered around (1, 3)
|
||||
RotatedRect e = fitEllipse(pts);
|
||||
EXPECT_LT(std::min(fabs(e.angle-180), fabs(e.angle)), 10.);
|
||||
EXPECT_NEAR(e.center.x, 1, 1);
|
||||
EXPECT_NEAR(e.center.y, 3, 1);
|
||||
EXPECT_LT(e.size.width*3, e.size.height);
|
||||
}
|
||||
|
||||
TEST(Imgproc_FitEllipse_JavaCase, accuracy) {
|
||||
vector<Point2f> pts;
|
||||
float scale = 1;
|
||||
Point2f shift(0, 0);
|
||||
pts.push_back(Point2f(0, 0)*scale+shift);
|
||||
pts.push_back(Point2f(1, 1)*scale+shift);
|
||||
pts.push_back(Point2f(-1, 1)*scale+shift);
|
||||
pts.push_back(Point2f(-1, -1)*scale+shift);
|
||||
pts.push_back(Point2f(1, -1)*scale+shift);
|
||||
|
||||
// check that we get almost vertical ellipse centered around (1, 3)
|
||||
RotatedRect e = fitEllipse(pts);
|
||||
EXPECT_NEAR(e.center.x, 0, 0.01);
|
||||
EXPECT_NEAR(e.center.y, 0, 0.01);
|
||||
EXPECT_NEAR(e.size.width, sqrt(2.)*2, 0.4);
|
||||
EXPECT_NEAR(e.size.height, sqrt(2.)*2, 0.4);
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
440
3rdparty/opencv-4.5.4/modules/imgproc/test/test_fitellipse_ams.cpp
vendored
Normal file
440
3rdparty/opencv-4.5.4/modules/imgproc/test/test_fitellipse_ams.cpp
vendored
Normal file
@@ -0,0 +1,440 @@
|
||||
// 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) 2016, Itseez, Inc, all rights reserved.
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
TEST(Imgproc_FitEllipseAMS_Issue_1, accuracy) {
|
||||
vector<Point2f>pts;
|
||||
pts.push_back(Point2f(173.41854895999165f, 125.84473135880411f));
|
||||
pts.push_back(Point2f(180.63769498640912f, 130.960006577589f));
|
||||
pts.push_back(Point2f(174.99173759130173f, 137.34265632926764f));
|
||||
pts.push_back(Point2f(170.9044645313217f, 141.68017556480243f));
|
||||
pts.push_back(Point2f(163.48965388499656f, 141.9404438924043f));
|
||||
pts.push_back(Point2f(159.37687818401147f, 148.60835331594876f));
|
||||
pts.push_back(Point2f(150.38917629356735f, 155.68825577720446f));
|
||||
pts.push_back(Point2f(147.16319653316862f, 157.06039984963923f));
|
||||
pts.push_back(Point2f(141.73118707843207f, 157.2570155198414f));
|
||||
pts.push_back(Point2f(130.61569602948597f, 159.40742182929364f));
|
||||
pts.push_back(Point2f(127.00573042229027f, 161.34430232187867f));
|
||||
pts.push_back(Point2f(120.49383815053747f, 163.72610883128334f));
|
||||
pts.push_back(Point2f(114.62383760040998f, 162.6788666385239f));
|
||||
pts.push_back(Point2f(108.84871269183333f, 161.90597054388132f));
|
||||
pts.push_back(Point2f(103.04574087829076f, 167.44352944383985f));
|
||||
pts.push_back(Point2f(96.31623870161255f, 163.71641295746116f));
|
||||
pts.push_back(Point2f(89.86174417295126f, 157.2967811253635f));
|
||||
pts.push_back(Point2f(84.27940674801192f, 168.6331304010667f));
|
||||
pts.push_back(Point2f(76.61995117937661f, 159.4445412678832f));
|
||||
pts.push_back(Point2f(72.22526316142418f, 154.60770776728293f));
|
||||
pts.push_back(Point2f(64.97742405067658f, 152.3687174339018f));
|
||||
pts.push_back(Point2f(58.34612797237003f, 155.61116802371583f));
|
||||
pts.push_back(Point2f(55.59089117268539f, 148.56245696566418f));
|
||||
pts.push_back(Point2f(45.22711195983706f, 145.6713241271927f));
|
||||
pts.push_back(Point2f(40.090542298840234f, 142.36141304004002f));
|
||||
pts.push_back(Point2f(31.788996807277414f, 136.26164877915585f));
|
||||
pts.push_back(Point2f(27.27613006088805f, 137.46860042141503f));
|
||||
pts.push_back(Point2f(23.972392188502226f, 129.17993872328594f));
|
||||
pts.push_back(Point2f(20.688046711616977f, 121.52750840733087f));
|
||||
pts.push_back(Point2f(14.635115184257643f, 115.36942800110485f));
|
||||
pts.push_back(Point2f(14.850919318756809f, 109.43609786936987f));
|
||||
pts.push_back(Point2f(7.476847697758103f, 102.67657265589285f));
|
||||
pts.push_back(Point2f(1.8896944088091914f, 95.78878215565676f));
|
||||
pts.push_back(Point2f(1.731997022935417f, 88.17674033990495f));
|
||||
pts.push_back(Point2f(1.6780841363402033f, 80.65581939883002f));
|
||||
pts.push_back(Point2f(0.035330281415411946f, 73.1088693846768f));
|
||||
pts.push_back(Point2f(0.14652518786238033f, 65.42769523404296f));
|
||||
pts.push_back(Point2f(6.99914645302843f, 58.436451064804245f));
|
||||
pts.push_back(Point2f(6.719616410428614f, 50.15263031354927f));
|
||||
pts.push_back(Point2f(5.122267598477748f, 46.03603214691343f));
|
||||
|
||||
bool AMSGoodQ;
|
||||
float tol = 0.01f;
|
||||
|
||||
RotatedRect ellipseAMSTrue = cv::RotatedRect(Point2f(94.4037f, 84.743f), Size2f(190.614f, 153.543f), 19.832f);
|
||||
RotatedRect ellipseAMSTest = fitEllipseAMS(pts);
|
||||
Point2f ellipseAMSTrueVertices[4];
|
||||
Point2f ellipseAMSTestVertices[4];
|
||||
ellipseAMSTest.points(ellipseAMSTestVertices);
|
||||
ellipseAMSTrue.points(ellipseAMSTrueVertices);
|
||||
float AMSDiff = 0.0f;
|
||||
for (size_t i=0; i <=3; i++) {
|
||||
Point2f diff = ellipseAMSTrueVertices[i] - ellipseAMSTestVertices[0];
|
||||
float d = diff.x * diff.x + diff.y * diff.y;
|
||||
for (size_t j=1; i <=3; i++) {
|
||||
diff = ellipseAMSTrueVertices[i] - ellipseAMSTestVertices[j];
|
||||
float dd = diff.x * diff.x + diff.y * diff.y;
|
||||
if(dd<d){d=dd;}
|
||||
}
|
||||
AMSDiff += std::sqrt(d);
|
||||
}
|
||||
AMSGoodQ = AMSDiff < tol;
|
||||
|
||||
EXPECT_TRUE(AMSGoodQ);
|
||||
}
|
||||
|
||||
TEST(Imgproc_FitEllipseAMS_Issue_2, accuracy) {
|
||||
vector<Point2f>pts;
|
||||
pts.push_back(Point2f(436.59985753246326f, 99.52113368023126f));
|
||||
pts.push_back(Point2f(454.40214161915856f, 160.47565296546912f));
|
||||
pts.push_back(Point2f(406.01996690372687f, 215.41999534561575f));
|
||||
pts.push_back(Point2f(362.8738685722881f, 262.1842668997318f));
|
||||
pts.push_back(Point2f(300.72864073265407f, 290.8182699272777f));
|
||||
pts.push_back(Point2f(247.62963883830972f, 311.383137106776f));
|
||||
pts.push_back(Point2f(194.15394659099445f, 313.30260991427565f));
|
||||
pts.push_back(Point2f(138.934393338296f, 310.50203123324223f));
|
||||
pts.push_back(Point2f(91.66999301197541f, 300.57303988670515f));
|
||||
pts.push_back(Point2f(28.286233855826133f, 268.0670159317756f));
|
||||
|
||||
bool AMSGoodQ;
|
||||
float tol = 0.01f;
|
||||
|
||||
RotatedRect ellipseAMSTrue = cv::RotatedRect(Point2f(223.917f, 169.701f), Size2f(456.628f, 277.809f), -12.6378f);
|
||||
RotatedRect ellipseAMSTest = fitEllipseAMS(pts);
|
||||
Point2f ellipseAMSTrueVertices[4];
|
||||
Point2f ellipseAMSTestVertices[4];
|
||||
ellipseAMSTest.points(ellipseAMSTestVertices);
|
||||
ellipseAMSTrue.points(ellipseAMSTrueVertices);
|
||||
float AMSDiff = 0.0f;
|
||||
for (size_t i=0; i <=3; i++) {
|
||||
Point2f diff = ellipseAMSTrueVertices[i] - ellipseAMSTestVertices[0];
|
||||
float d = diff.x * diff.x + diff.y * diff.y;
|
||||
for (size_t j=1; i <=3; i++) {
|
||||
diff = ellipseAMSTrueVertices[i] - ellipseAMSTestVertices[j];
|
||||
float dd = diff.x * diff.x + diff.y * diff.y;
|
||||
if(dd<d){d=dd;}
|
||||
}
|
||||
AMSDiff += std::sqrt(d);
|
||||
}
|
||||
AMSGoodQ = AMSDiff < tol;
|
||||
|
||||
EXPECT_TRUE(AMSGoodQ);
|
||||
}
|
||||
|
||||
|
||||
TEST(Imgproc_FitEllipseAMS_Issue_3, accuracy) {
|
||||
vector<Point2f>pts;
|
||||
pts.push_back(Point2f(459.59217920219083f, 480.1054989283611f));
|
||||
pts.push_back(Point2f(427.2759071813645f, 501.82653857689616f));
|
||||
pts.push_back(Point2f(388.35145730295574f, 520.9488690267101f));
|
||||
pts.push_back(Point2f(349.53248668650656f, 522.9153107979839f));
|
||||
pts.push_back(Point2f(309.56018996762094f, 527.449631776843f));
|
||||
pts.push_back(Point2f(272.07480726768665f, 508.12367135706165f));
|
||||
pts.push_back(Point2f(234.69230939247115f, 519.8943877180591f));
|
||||
pts.push_back(Point2f(201.65185545142472f, 509.47870288702813f));
|
||||
pts.push_back(Point2f(169.37222144138462f, 498.2681549419808f));
|
||||
pts.push_back(Point2f(147.96233740677815f, 467.0923094529034f));
|
||||
pts.push_back(Point2f(109.68331701139209f, 433.39069422941986f));
|
||||
pts.push_back(Point2f(81.95454413977822f, 397.34325168750087f));
|
||||
pts.push_back(Point2f(63.74923800767195f, 371.939105294963f));
|
||||
pts.push_back(Point2f(39.966434417279885f, 329.9581349942296f));
|
||||
pts.push_back(Point2f(21.581668415402532f, 292.6692716276865f));
|
||||
pts.push_back(Point2f(13.687334926511767f, 248.91164234903772f));
|
||||
pts.push_back(Point2f(0.0f, 201.25693715845716f));
|
||||
pts.push_back(Point2f(3.90259455356599f, 155.68155247210575f));
|
||||
pts.push_back(Point2f(39.683930802331844f, 110.26290871953987f));
|
||||
pts.push_back(Point2f(47.85826684019932f, 70.82454140948524f));
|
||||
|
||||
bool AMSGoodQ;
|
||||
float tol = 0.01f;
|
||||
|
||||
RotatedRect ellipseAMSTrue = cv::RotatedRect(Point2f(266.796f, 260.167f), Size2f(580.374f, 469.465f), 50.3961f);
|
||||
RotatedRect ellipseAMSTest = fitEllipseAMS(pts);
|
||||
Point2f ellipseAMSTrueVertices[4];
|
||||
Point2f ellipseAMSTestVertices[4];
|
||||
ellipseAMSTest.points(ellipseAMSTestVertices);
|
||||
ellipseAMSTrue.points(ellipseAMSTrueVertices);
|
||||
float AMSDiff = 0.0f;
|
||||
for (size_t i=0; i <=3; i++) {
|
||||
Point2f diff = ellipseAMSTrueVertices[i] - ellipseAMSTestVertices[0];
|
||||
float d = diff.x * diff.x + diff.y * diff.y;
|
||||
for (size_t j=1; i <=3; i++) {
|
||||
diff = ellipseAMSTrueVertices[i] - ellipseAMSTestVertices[j];
|
||||
float dd = diff.x * diff.x + diff.y * diff.y;
|
||||
if(dd<d){d=dd;}
|
||||
}
|
||||
AMSDiff += std::sqrt(d);
|
||||
}
|
||||
AMSGoodQ = AMSDiff < tol;
|
||||
|
||||
EXPECT_TRUE(AMSGoodQ);
|
||||
}
|
||||
|
||||
TEST(Imgproc_FitEllipseAMS_Issue_4, accuracy) {
|
||||
vector<Point2f>pts;
|
||||
pts.push_back(Point2f(461.1761758124861f, 79.55196261616746f));
|
||||
pts.push_back(Point2f(470.5034888757249f, 100.56760245239015f));
|
||||
pts.push_back(Point2f(470.7814479849749f, 127.45783922150272f));
|
||||
pts.push_back(Point2f(465.214384653262f, 157.51792078285405f));
|
||||
pts.push_back(Point2f(465.3739691861813f, 185.89204350118942f));
|
||||
pts.push_back(Point2f(443.36043162278366f, 214.43399982709002f));
|
||||
pts.push_back(Point2f(435.04682693174095f, 239.2657073987589f));
|
||||
pts.push_back(Point2f(444.48553588292697f, 262.0816619678671f));
|
||||
pts.push_back(Point2f(407.1290185495328f, 285.07828783776347f));
|
||||
pts.push_back(Point2f(397.71436554935804f, 304.782713567108f));
|
||||
pts.push_back(Point2f(391.65678619785854f, 323.6809382153118f));
|
||||
pts.push_back(Point2f(366.3904205781036f, 328.09416679736563f));
|
||||
pts.push_back(Point2f(341.7656517790918f, 346.9672607008338f));
|
||||
pts.push_back(Point2f(335.8021864809171f, 358.22416661090296f));
|
||||
pts.push_back(Point2f(313.29224574204227f, 373.3267160317279f));
|
||||
pts.push_back(Point2f(291.121216115417f, 377.3339312050791f));
|
||||
pts.push_back(Point2f(284.20367595990547f, 389.5930108233698f));
|
||||
pts.push_back(Point2f(270.9682061106809f, 388.4352006517971f));
|
||||
pts.push_back(Point2f(253.10188273008825f, 392.35120876055373f));
|
||||
pts.push_back(Point2f(234.2306946938868f, 407.0773705761117f));
|
||||
pts.push_back(Point2f(217.0544384092144f, 407.54850609237235f));
|
||||
pts.push_back(Point2f(198.40910966657933f, 423.7008860314684f));
|
||||
pts.push_back(Point2f(175.47011114845057f, 420.4223434173364f));
|
||||
pts.push_back(Point2f(154.92083551695902f, 418.5288198459268f));
|
||||
pts.push_back(Point2f(136.52988517939698f, 417.8311217226818f));
|
||||
pts.push_back(Point2f(114.74657291069317f, 410.1534699388714f));
|
||||
pts.push_back(Point2f(78.9220388330042f, 397.6266608135022f));
|
||||
pts.push_back(Point2f(76.82658673144391f, 404.27399269891055f));
|
||||
pts.push_back(Point2f(50.953595435605116f, 386.3824077178053f));
|
||||
pts.push_back(Point2f(43.603489077456985f, 368.7894972436907f));
|
||||
pts.push_back(Point2f(19.37402592752713f, 343.3511017547511f));
|
||||
pts.push_back(Point2f(8.714663367287343f, 322.2148323327599f));
|
||||
pts.push_back(Point2f(0., 288.7836318007535f));
|
||||
pts.push_back(Point2f(3.98686689837605f, 263.1748167870333f));
|
||||
pts.push_back(Point2f(9.536389714519785f, 233.02995195684738f));
|
||||
pts.push_back(Point2f(17.83246556512455f, 205.6536519851621f));
|
||||
pts.push_back(Point2f(33.00593702846919f, 180.52628138608327f));
|
||||
pts.push_back(Point2f(41.572400996463394f, 153.95185568689314f));
|
||||
pts.push_back(Point2f(54.55733659450332f, 136.54322891729444f));
|
||||
pts.push_back(Point2f(78.60990563833005f, 112.76538180538182f));
|
||||
|
||||
bool AMSGoodQ;
|
||||
float tol = 0.01f;
|
||||
|
||||
RotatedRect ellipseAMSTrue = cv::RotatedRect(Point2f(237.108f, 207.32f), Size2f(517.287f, 357.591f), -36.3653f);
|
||||
RotatedRect ellipseAMSTest = fitEllipseAMS(pts);
|
||||
Point2f ellipseAMSTrueVertices[4];
|
||||
Point2f ellipseAMSTestVertices[4];
|
||||
ellipseAMSTest.points(ellipseAMSTestVertices);
|
||||
ellipseAMSTrue.points(ellipseAMSTrueVertices);
|
||||
float AMSDiff = 0.0f;
|
||||
for (size_t i=0; i <=3; i++) {
|
||||
Point2f diff = ellipseAMSTrueVertices[i] - ellipseAMSTestVertices[0];
|
||||
float d = diff.x * diff.x + diff.y * diff.y;
|
||||
for (size_t j=1; i <=3; i++) {
|
||||
diff = ellipseAMSTrueVertices[i] - ellipseAMSTestVertices[j];
|
||||
float dd = diff.x * diff.x + diff.y * diff.y;
|
||||
if(dd<d){d=dd;}
|
||||
}
|
||||
AMSDiff += std::sqrt(d);
|
||||
}
|
||||
AMSGoodQ = AMSDiff < tol;
|
||||
|
||||
EXPECT_TRUE(AMSGoodQ);
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST(Imgproc_FitEllipseAMS_Issue_5, accuracy) {
|
||||
vector<Point2f>pts;
|
||||
pts.push_back(Point2f(509.60609444351917f, 484.8233016998119f));
|
||||
pts.push_back(Point2f(508.55357451809846f, 498.61004779125176f));
|
||||
pts.push_back(Point2f(495.59325478416525f, 507.9238702677585f));
|
||||
pts.push_back(Point2f(455.32905012177747f, 517.7518674113691f));
|
||||
pts.push_back(Point2f(461.24821761238667f, 524.2115477440211f));
|
||||
pts.push_back(Point2f(438.8983455906825f, 528.424911702069f));
|
||||
pts.push_back(Point2f(425.9259699875303f, 532.5700430134499f));
|
||||
pts.push_back(Point2f(405.77496728300616f, 535.7295008444993f));
|
||||
pts.push_back(Point2f(384.31968113982475f, 536.3076260371831f));
|
||||
pts.push_back(Point2f(381.5356536818977f, 540.183355729414f));
|
||||
pts.push_back(Point2f(378.2530503455792f, 540.2871855284832f));
|
||||
pts.push_back(Point2f(357.7242088314752f, 543.473075733281f));
|
||||
pts.push_back(Point2f(339.27871831324853f, 541.2099003613087f));
|
||||
pts.push_back(Point2f(339.22481874867435f, 541.1105421426018f));
|
||||
pts.push_back(Point2f(331.50337377509396f, 539.7296050163102f));
|
||||
pts.push_back(Point2f(317.8306501537862f, 540.9077275195326f));
|
||||
pts.push_back(Point2f(304.9192648323086f, 541.3434792768918f));
|
||||
pts.push_back(Point2f(297.33855427908617f, 543.0590309600501f));
|
||||
pts.push_back(Point2f(288.95330515997694f, 543.8756702506837f));
|
||||
pts.push_back(Point2f(278.5850913122515f, 538.1343888329859f));
|
||||
pts.push_back(Point2f(266.05355938101724f, 538.4115695907074f));
|
||||
pts.push_back(Point2f(255.30186994366096f, 534.2459272411796f));
|
||||
pts.push_back(Point2f(238.52054973466758f, 537.5007401480628f));
|
||||
pts.push_back(Point2f(228.444463024996f, 533.8992361116678f));
|
||||
pts.push_back(Point2f(217.8111623149833f, 538.2269193558991f));
|
||||
pts.push_back(Point2f(209.43502138981037f, 532.8057062984569f));
|
||||
pts.push_back(Point2f(193.33570716763276f, 527.2038128630041f));
|
||||
pts.push_back(Point2f(172.66725340039625f, 526.4020881005537f));
|
||||
pts.push_back(Point2f(158.33654199771337f, 525.2093856704676f));
|
||||
pts.push_back(Point2f(148.65905485249067f, 521.0146762179431f));
|
||||
pts.push_back(Point2f(147.6615365176719f, 517.4315201992808f));
|
||||
pts.push_back(Point2f(122.43568509949394f, 514.2089723387337f));
|
||||
pts.push_back(Point2f(110.88482982039073f, 509.14004840857046f));
|
||||
pts.push_back(Point2f(107.10516681523065f, 502.49943180234266f));
|
||||
pts.push_back(Point2f(82.66611013934804f, 494.0581153893113f));
|
||||
pts.push_back(Point2f(63.573319848965966f, 485.6772487054385f));
|
||||
pts.push_back(Point2f(47.65729058071245f, 475.4468806518075f));
|
||||
pts.push_back(Point2f(19.96819458379347f, 463.98285210241943f));
|
||||
pts.push_back(Point2f(27.855803175234342f, 450.2298664426336f));
|
||||
pts.push_back(Point2f(12.832198085636549f, 435.6317753810441f));
|
||||
|
||||
bool AMSGoodQ;
|
||||
float tol = 0.01f;
|
||||
|
||||
RotatedRect ellipseAMSTrue = cv::RotatedRect(Point2f(265.252f, 451.597f), Size2f(503.386f, 174.674f), 5.31814f);
|
||||
RotatedRect ellipseAMSTest = fitEllipseAMS(pts);
|
||||
Point2f ellipseAMSTrueVertices[4];
|
||||
Point2f ellipseAMSTestVertices[4];
|
||||
ellipseAMSTest.points(ellipseAMSTestVertices);
|
||||
ellipseAMSTrue.points(ellipseAMSTrueVertices);
|
||||
float AMSDiff = 0.0f;
|
||||
for (size_t i=0; i <=3; i++) {
|
||||
Point2f diff = ellipseAMSTrueVertices[i] - ellipseAMSTestVertices[0];
|
||||
float d = diff.x * diff.x + diff.y * diff.y;
|
||||
for (size_t j=1; i <=3; i++) {
|
||||
diff = ellipseAMSTrueVertices[i] - ellipseAMSTestVertices[j];
|
||||
float dd = diff.x * diff.x + diff.y * diff.y;
|
||||
if(dd<d){d=dd;}
|
||||
}
|
||||
AMSDiff += std::sqrt(d);
|
||||
}
|
||||
AMSGoodQ = AMSDiff < tol;
|
||||
|
||||
EXPECT_TRUE(AMSGoodQ);
|
||||
}
|
||||
|
||||
TEST(Imgproc_FitEllipseAMS_Issue_6, accuracy) {
|
||||
vector<Point2f>pts;
|
||||
pts.push_back(Point2f(414.90156479295905f, 29.063453659930833f));
|
||||
pts.push_back(Point2f(393.79576036337977f, 58.59512774879134f));
|
||||
pts.push_back(Point2f(387.9100725249931f, 94.65067695657254f));
|
||||
pts.push_back(Point2f(351.6987114318621f, 124.6049267560123f));
|
||||
pts.push_back(Point2f(335.3270519942532f, 154.52182750730412f));
|
||||
pts.push_back(Point2f(329.2955843262556f, 179.38031343427303f));
|
||||
pts.push_back(Point2f(322.7316812937696f, 201.88774427737036f));
|
||||
pts.push_back(Point2f(301.48326350826585f, 217.63331351026562f));
|
||||
pts.push_back(Point2f(287.4603938315088f, 228.68790184154113f));
|
||||
pts.push_back(Point2f(273.36617750656023f, 234.48397257849905f));
|
||||
pts.push_back(Point2f(270.7787206270782f, 242.85279436204632f));
|
||||
pts.push_back(Point2f(268.6973828073692f, 246.10891460870312f));
|
||||
pts.push_back(Point2f(261.60715070464255f, 252.65744793902192f));
|
||||
pts.push_back(Point2f(262.9041824871923f, 257.1813047575656f));
|
||||
pts.push_back(Point2f(263.3210079177046f, 260.0532193246593f));
|
||||
pts.push_back(Point2f(248.49568488533242f, 264.56723557175013f));
|
||||
pts.push_back(Point2f(245.4134174127509f, 264.87259401292f));
|
||||
pts.push_back(Point2f(244.73208618171216f, 272.32307359830884f));
|
||||
pts.push_back(Point2f(232.82093196087555f, 272.0239734764616f));
|
||||
pts.push_back(Point2f(235.28539413113458f, 276.8668447478244f));
|
||||
pts.push_back(Point2f(231.9766571511147f, 277.71179872893083f));
|
||||
pts.push_back(Point2f(227.23880706209866f, 284.5588878789101f));
|
||||
pts.push_back(Point2f(222.53202223537826f, 282.2293154479012f));
|
||||
pts.push_back(Point2f(217.27525654729595f, 297.42961148365725f));
|
||||
pts.push_back(Point2f(212.19490057230672f, 294.5344078014253f));
|
||||
pts.push_back(Point2f(207.47417472945446f, 301.72230412668307f));
|
||||
pts.push_back(Point2f(202.11143229969164f, 298.8588627545512f));
|
||||
pts.push_back(Point2f(196.62967096845824f, 309.39738607353223f));
|
||||
pts.push_back(Point2f(190.37809841992106f, 318.3250479151242f));
|
||||
pts.push_back(Point2f(183.1296129732803f, 322.35242231955453f));
|
||||
pts.push_back(Point2f(171.58530535265993f, 330.4981441404153f));
|
||||
pts.push_back(Point2f(160.40092880652247f, 337.47275990208226f));
|
||||
pts.push_back(Point2f(149.44888762618092f, 343.42296086656717f));
|
||||
pts.push_back(Point2f(139.7923528305302f, 353.4821948045352f));
|
||||
pts.push_back(Point2f(121.08414969113318f, 359.7010225709457f));
|
||||
pts.push_back(Point2f(100.10629739219641f, 375.3155744055458f));
|
||||
pts.push_back(Point2f(78.15715630786733f, 389.0311284319413f));
|
||||
pts.push_back(Point2f(51.22820988075294f, 396.98646504159547f));
|
||||
pts.push_back(Point2f(30.71132492338431f, 402.85098740402844f));
|
||||
pts.push_back(Point2f(10.994737323179852f, 394.6764602972333f));
|
||||
|
||||
bool AMSGoodQ;
|
||||
float tol = 0.01f;
|
||||
|
||||
RotatedRect ellipseAMSTrue = cv::RotatedRect(Point2f(192.467f, 204.404f), Size2f(551.397f, 165.068f), 136.913f);
|
||||
RotatedRect ellipseAMSTest = fitEllipseAMS(pts);
|
||||
Point2f ellipseAMSTrueVertices[4];
|
||||
Point2f ellipseAMSTestVertices[4];
|
||||
ellipseAMSTest.points(ellipseAMSTestVertices);
|
||||
ellipseAMSTrue.points(ellipseAMSTrueVertices);
|
||||
float AMSDiff = 0.0f;
|
||||
for (size_t i=0; i <=3; i++) {
|
||||
Point2f diff = ellipseAMSTrueVertices[i] - ellipseAMSTestVertices[0];
|
||||
float d = diff.x * diff.x + diff.y * diff.y;
|
||||
for (size_t j=1; i <=3; i++) {
|
||||
diff = ellipseAMSTrueVertices[i] - ellipseAMSTestVertices[j];
|
||||
float dd = diff.x * diff.x + diff.y * diff.y;
|
||||
if(dd<d){d=dd;}
|
||||
}
|
||||
AMSDiff += std::sqrt(d);
|
||||
}
|
||||
AMSGoodQ = AMSDiff < tol;
|
||||
|
||||
EXPECT_TRUE(AMSGoodQ);
|
||||
}
|
||||
|
||||
TEST(Imgproc_FitEllipseAMS_Issue_7, accuracy) {
|
||||
vector<Point2f>pts;
|
||||
pts.push_back(Point2f(386.7497806918209f, 119.55623710363142f));
|
||||
pts.push_back(Point2f(399.0712613744503f, 132.61095972401034f));
|
||||
pts.push_back(Point2f(400.3582576852657f, 146.71942033652573f));
|
||||
pts.push_back(Point2f(383.31046706707906f, 160.13631428164982f));
|
||||
pts.push_back(Point2f(387.1626582455823f, 173.82700569763574f));
|
||||
pts.push_back(Point2f(378.88843308401425f, 186.10333319745317f));
|
||||
pts.push_back(Point2f(367.55061701208f, 201.41492900400164f));
|
||||
pts.push_back(Point2f(360.3254967185148f, 209.03834085076022f));
|
||||
pts.push_back(Point2f(346.2645164278429f, 222.03214282040395f));
|
||||
pts.push_back(Point2f(342.3483403634167f, 230.58290419787073f));
|
||||
pts.push_back(Point2f(326.2900969991908f, 240.23679566682756f));
|
||||
pts.push_back(Point2f(324.5622396580625f, 249.56961396707823f));
|
||||
pts.push_back(Point2f(304.23417130914095f, 259.6693711280021f));
|
||||
pts.push_back(Point2f(295.54035697534675f, 270.82284542557704f));
|
||||
pts.push_back(Point2f(291.7403057147348f, 276.1536825048371f));
|
||||
pts.push_back(Point2f(269.19344116558665f, 287.1705579044651f));
|
||||
pts.push_back(Point2f(256.5350613899267f, 274.91264707500943f));
|
||||
pts.push_back(Point2f(245.93644351417183f, 286.12398028743064f));
|
||||
pts.push_back(Point2f(232.40892420943732f, 282.73986583867065f));
|
||||
pts.push_back(Point2f(216.17957969101082f, 293.22229708237705f));
|
||||
pts.push_back(Point2f(205.66843722622573f, 295.7032575625158f));
|
||||
pts.push_back(Point2f(192.219969335765f, 302.6968969534755f));
|
||||
pts.push_back(Point2f(178.37758801730416f, 295.56656776633287f));
|
||||
pts.push_back(Point2f(167.60089103756644f, 301.4629292267722f));
|
||||
pts.push_back(Point2f(157.44802813915317f, 298.90830855734504f));
|
||||
pts.push_back(Point2f(138.44311818820313f, 293.951927187897f));
|
||||
pts.push_back(Point2f(128.92747660038592f, 291.4122695492978f));
|
||||
pts.push_back(Point2f(119.75160909865994f, 282.5809454721714f));
|
||||
pts.push_back(Point2f(98.48443737042328f, 290.39938776333247f));
|
||||
pts.push_back(Point2f(88.05275635126131f, 280.11156058895745f));
|
||||
pts.push_back(Point2f(82.45799026448167f, 271.46668468419773f));
|
||||
pts.push_back(Point2f(68.04031962064084f, 267.8136468580707f));
|
||||
pts.push_back(Point2f(58.99967170878713f, 263.8859310392943f));
|
||||
pts.push_back(Point2f(41.256097220823484f, 260.6041605773932f));
|
||||
pts.push_back(Point2f(40.66198797608645f, 246.64973068177196f));
|
||||
pts.push_back(Point2f(31.085484380646008f, 239.28615601336074f));
|
||||
pts.push_back(Point2f(24.069417111444253f, 225.2228746297288f));
|
||||
pts.push_back(Point2f(22.10122953275156f, 212.75509683149195f));
|
||||
pts.push_back(Point2f(9.929991244497518f, 203.20662088477752f));
|
||||
pts.push_back(Point2f(0.0f, 190.04891498441148f));
|
||||
|
||||
bool AMSGoodQ;
|
||||
float tol = 0.01f;
|
||||
|
||||
RotatedRect ellipseAMSTrue = cv::RotatedRect(Point2f(197.292f, 134.64f), Size2f(401.092f, 320.051f), 165.429f);
|
||||
RotatedRect ellipseAMSTest = fitEllipseAMS(pts);
|
||||
Point2f ellipseAMSTrueVertices[4];
|
||||
Point2f ellipseAMSTestVertices[4];
|
||||
ellipseAMSTest.points(ellipseAMSTestVertices);
|
||||
ellipseAMSTrue.points(ellipseAMSTrueVertices);
|
||||
float AMSDiff = 0.0f;
|
||||
for (size_t i=0; i <=3; i++) {
|
||||
Point2f diff = ellipseAMSTrueVertices[i] - ellipseAMSTestVertices[0];
|
||||
float d = diff.x * diff.x + diff.y * diff.y;
|
||||
for (size_t j=1; i <=3; i++) {
|
||||
diff = ellipseAMSTrueVertices[i] - ellipseAMSTestVertices[j];
|
||||
float dd = diff.x * diff.x + diff.y * diff.y;
|
||||
if(dd<d){d=dd;}
|
||||
}
|
||||
AMSDiff += std::sqrt(d);
|
||||
}
|
||||
AMSGoodQ = AMSDiff < tol;
|
||||
|
||||
EXPECT_TRUE(AMSGoodQ);
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
440
3rdparty/opencv-4.5.4/modules/imgproc/test/test_fitellipse_direct.cpp
vendored
Normal file
440
3rdparty/opencv-4.5.4/modules/imgproc/test/test_fitellipse_direct.cpp
vendored
Normal file
@@ -0,0 +1,440 @@
|
||||
// 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) 2016, Itseez, Inc, all rights reserved.
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
TEST(Imgproc_FitEllipseDirect_Issue_1, accuracy) {
|
||||
vector<Point2f>pts;
|
||||
pts.push_back(Point2f(173.41854895999165f, 125.84473135880411f));
|
||||
pts.push_back(Point2f(180.63769498640912f, 130.960006577589f));
|
||||
pts.push_back(Point2f(174.99173759130173f, 137.34265632926764f));
|
||||
pts.push_back(Point2f(170.9044645313217f, 141.68017556480243f));
|
||||
pts.push_back(Point2f(163.48965388499656f, 141.9404438924043f));
|
||||
pts.push_back(Point2f(159.37687818401147f, 148.60835331594876f));
|
||||
pts.push_back(Point2f(150.38917629356735f, 155.68825577720446f));
|
||||
pts.push_back(Point2f(147.16319653316862f, 157.06039984963923f));
|
||||
pts.push_back(Point2f(141.73118707843207f, 157.2570155198414f));
|
||||
pts.push_back(Point2f(130.61569602948597f, 159.40742182929364f));
|
||||
pts.push_back(Point2f(127.00573042229027f, 161.34430232187867f));
|
||||
pts.push_back(Point2f(120.49383815053747f, 163.72610883128334f));
|
||||
pts.push_back(Point2f(114.62383760040998f, 162.6788666385239f));
|
||||
pts.push_back(Point2f(108.84871269183333f, 161.90597054388132f));
|
||||
pts.push_back(Point2f(103.04574087829076f, 167.44352944383985f));
|
||||
pts.push_back(Point2f(96.31623870161255f, 163.71641295746116f));
|
||||
pts.push_back(Point2f(89.86174417295126f, 157.2967811253635f));
|
||||
pts.push_back(Point2f(84.27940674801192f, 168.6331304010667f));
|
||||
pts.push_back(Point2f(76.61995117937661f, 159.4445412678832f));
|
||||
pts.push_back(Point2f(72.22526316142418f, 154.60770776728293f));
|
||||
pts.push_back(Point2f(64.97742405067658f, 152.3687174339018f));
|
||||
pts.push_back(Point2f(58.34612797237003f, 155.61116802371583f));
|
||||
pts.push_back(Point2f(55.59089117268539f, 148.56245696566418f));
|
||||
pts.push_back(Point2f(45.22711195983706f, 145.6713241271927f));
|
||||
pts.push_back(Point2f(40.090542298840234f, 142.36141304004002f));
|
||||
pts.push_back(Point2f(31.788996807277414f, 136.26164877915585f));
|
||||
pts.push_back(Point2f(27.27613006088805f, 137.46860042141503f));
|
||||
pts.push_back(Point2f(23.972392188502226f, 129.17993872328594f));
|
||||
pts.push_back(Point2f(20.688046711616977f, 121.52750840733087f));
|
||||
pts.push_back(Point2f(14.635115184257643f, 115.36942800110485f));
|
||||
pts.push_back(Point2f(14.850919318756809f, 109.43609786936987f));
|
||||
pts.push_back(Point2f(7.476847697758103f, 102.67657265589285f));
|
||||
pts.push_back(Point2f(1.8896944088091914f, 95.78878215565676f));
|
||||
pts.push_back(Point2f(1.731997022935417f, 88.17674033990495f));
|
||||
pts.push_back(Point2f(1.6780841363402033f, 80.65581939883002f));
|
||||
pts.push_back(Point2f(0.035330281415411946f, 73.1088693846768f));
|
||||
pts.push_back(Point2f(0.14652518786238033f, 65.42769523404296f));
|
||||
pts.push_back(Point2f(6.99914645302843f, 58.436451064804245f));
|
||||
pts.push_back(Point2f(6.719616410428614f, 50.15263031354927f));
|
||||
pts.push_back(Point2f(5.122267598477748f, 46.03603214691343f));
|
||||
|
||||
bool directGoodQ;
|
||||
float tol = 0.01f;
|
||||
|
||||
RotatedRect ellipseDirectTrue = cv::RotatedRect(Point2f(91.3256f, 90.4668f),Size2f(187.211f, 140.031f), 21.5808f);
|
||||
RotatedRect ellipseDirectTest = fitEllipseDirect(pts);
|
||||
Point2f ellipseDirectTrueVertices[4];
|
||||
Point2f ellipseDirectTestVertices[4];
|
||||
ellipseDirectTest.points(ellipseDirectTestVertices);
|
||||
ellipseDirectTrue.points(ellipseDirectTrueVertices);
|
||||
float directDiff = 0.0f;
|
||||
for (size_t i=0; i <=3; i++) {
|
||||
Point2f diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[0];
|
||||
float d = diff.x * diff.x + diff.y * diff.y;
|
||||
for (size_t j=1; i <=3; i++) {
|
||||
diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[j];
|
||||
float dd = diff.x * diff.x + diff.y * diff.y;
|
||||
if(dd<d){d=dd;}
|
||||
}
|
||||
directDiff += std::sqrt(d);
|
||||
}
|
||||
directGoodQ = directDiff < tol;
|
||||
|
||||
EXPECT_TRUE(directGoodQ);
|
||||
}
|
||||
|
||||
TEST(Imgproc_FitEllipseDirect_Issue_2, accuracy) {
|
||||
vector<Point2f>pts;
|
||||
pts.push_back(Point2f(436.59985753246326f, 99.52113368023126f));
|
||||
pts.push_back(Point2f(454.40214161915856f, 160.47565296546912f));
|
||||
pts.push_back(Point2f(406.01996690372687f, 215.41999534561575f));
|
||||
pts.push_back(Point2f(362.8738685722881f, 262.1842668997318f));
|
||||
pts.push_back(Point2f(300.72864073265407f, 290.8182699272777f));
|
||||
pts.push_back(Point2f(247.62963883830972f, 311.383137106776f));
|
||||
pts.push_back(Point2f(194.15394659099445f, 313.30260991427565f));
|
||||
pts.push_back(Point2f(138.934393338296f, 310.50203123324223f));
|
||||
pts.push_back(Point2f(91.66999301197541f, 300.57303988670515f));
|
||||
pts.push_back(Point2f(28.286233855826133f, 268.0670159317756f));
|
||||
|
||||
bool directGoodQ;
|
||||
float tol = 0.01f;
|
||||
|
||||
RotatedRect ellipseDirectTrue = cv::RotatedRect(Point2f(228.232f, 174.879f),Size2f(450.68f, 265.556f), 166.181f);
|
||||
RotatedRect ellipseDirectTest = fitEllipseDirect(pts);
|
||||
Point2f ellipseDirectTrueVertices[4];
|
||||
Point2f ellipseDirectTestVertices[4];
|
||||
ellipseDirectTest.points(ellipseDirectTestVertices);
|
||||
ellipseDirectTrue.points(ellipseDirectTrueVertices);
|
||||
float directDiff = 0.0f;
|
||||
for (size_t i=0; i <=3; i++) {
|
||||
Point2f diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[0];
|
||||
float d = diff.x * diff.x + diff.y * diff.y;
|
||||
for (size_t j=1; i <=3; i++) {
|
||||
diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[j];
|
||||
float dd = diff.x * diff.x + diff.y * diff.y;
|
||||
if(dd<d){d=dd;}
|
||||
}
|
||||
directDiff += std::sqrt(d);
|
||||
}
|
||||
directGoodQ = directDiff < tol;
|
||||
|
||||
EXPECT_TRUE(directGoodQ);
|
||||
}
|
||||
|
||||
|
||||
TEST(Imgproc_FitEllipseDirect_Issue_3, accuracy) {
|
||||
vector<Point2f>pts;
|
||||
pts.push_back(Point2f(459.59217920219083f, 480.1054989283611f));
|
||||
pts.push_back(Point2f(427.2759071813645f, 501.82653857689616f));
|
||||
pts.push_back(Point2f(388.35145730295574f, 520.9488690267101f));
|
||||
pts.push_back(Point2f(349.53248668650656f, 522.9153107979839f));
|
||||
pts.push_back(Point2f(309.56018996762094f, 527.449631776843f));
|
||||
pts.push_back(Point2f(272.07480726768665f, 508.12367135706165f));
|
||||
pts.push_back(Point2f(234.69230939247115f, 519.8943877180591f));
|
||||
pts.push_back(Point2f(201.65185545142472f, 509.47870288702813f));
|
||||
pts.push_back(Point2f(169.37222144138462f, 498.2681549419808f));
|
||||
pts.push_back(Point2f(147.96233740677815f, 467.0923094529034f));
|
||||
pts.push_back(Point2f(109.68331701139209f, 433.39069422941986f));
|
||||
pts.push_back(Point2f(81.95454413977822f, 397.34325168750087f));
|
||||
pts.push_back(Point2f(63.74923800767195f, 371.939105294963f));
|
||||
pts.push_back(Point2f(39.966434417279885f, 329.9581349942296f));
|
||||
pts.push_back(Point2f(21.581668415402532f, 292.6692716276865f));
|
||||
pts.push_back(Point2f(13.687334926511767f, 248.91164234903772f));
|
||||
pts.push_back(Point2f(0.0f, 201.25693715845716f));
|
||||
pts.push_back(Point2f(3.90259455356599f, 155.68155247210575f));
|
||||
pts.push_back(Point2f(39.683930802331844f, 110.26290871953987f));
|
||||
pts.push_back(Point2f(47.85826684019932f, 70.82454140948524f));
|
||||
|
||||
bool directGoodQ;
|
||||
float tol = 0.01f;
|
||||
|
||||
RotatedRect ellipseDirectTrue = cv::RotatedRect(Point2f(255.326f, 272.626f),Size2f(570.999f, 434.23f), 49.0265f);
|
||||
RotatedRect ellipseDirectTest = fitEllipseDirect(pts);
|
||||
Point2f ellipseDirectTrueVertices[4];
|
||||
Point2f ellipseDirectTestVertices[4];
|
||||
ellipseDirectTest.points(ellipseDirectTestVertices);
|
||||
ellipseDirectTrue.points(ellipseDirectTrueVertices);
|
||||
float directDiff = 0.0f;
|
||||
for (size_t i=0; i <=3; i++) {
|
||||
Point2f diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[0];
|
||||
float d = diff.x * diff.x + diff.y * diff.y;
|
||||
for (size_t j=1; i <=3; i++) {
|
||||
diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[j];
|
||||
float dd = diff.x * diff.x + diff.y * diff.y;
|
||||
if(dd<d){d=dd;}
|
||||
}
|
||||
directDiff += std::sqrt(d);
|
||||
}
|
||||
directGoodQ = directDiff < tol;
|
||||
|
||||
EXPECT_TRUE(directGoodQ);
|
||||
}
|
||||
|
||||
TEST(Imgproc_FitEllipseDirect_Issue_4, accuracy) {
|
||||
vector<Point2f>pts;
|
||||
pts.push_back(Point2f(461.1761758124861f, 79.55196261616746f));
|
||||
pts.push_back(Point2f(470.5034888757249f, 100.56760245239015f));
|
||||
pts.push_back(Point2f(470.7814479849749f, 127.45783922150272f));
|
||||
pts.push_back(Point2f(465.214384653262f, 157.51792078285405f));
|
||||
pts.push_back(Point2f(465.3739691861813f, 185.89204350118942f));
|
||||
pts.push_back(Point2f(443.36043162278366f, 214.43399982709002f));
|
||||
pts.push_back(Point2f(435.04682693174095f, 239.2657073987589f));
|
||||
pts.push_back(Point2f(444.48553588292697f, 262.0816619678671f));
|
||||
pts.push_back(Point2f(407.1290185495328f, 285.07828783776347f));
|
||||
pts.push_back(Point2f(397.71436554935804f, 304.782713567108f));
|
||||
pts.push_back(Point2f(391.65678619785854f, 323.6809382153118f));
|
||||
pts.push_back(Point2f(366.3904205781036f, 328.09416679736563f));
|
||||
pts.push_back(Point2f(341.7656517790918f, 346.9672607008338f));
|
||||
pts.push_back(Point2f(335.8021864809171f, 358.22416661090296f));
|
||||
pts.push_back(Point2f(313.29224574204227f, 373.3267160317279f));
|
||||
pts.push_back(Point2f(291.121216115417f, 377.3339312050791f));
|
||||
pts.push_back(Point2f(284.20367595990547f, 389.5930108233698f));
|
||||
pts.push_back(Point2f(270.9682061106809f, 388.4352006517971f));
|
||||
pts.push_back(Point2f(253.10188273008825f, 392.35120876055373f));
|
||||
pts.push_back(Point2f(234.2306946938868f, 407.0773705761117f));
|
||||
pts.push_back(Point2f(217.0544384092144f, 407.54850609237235f));
|
||||
pts.push_back(Point2f(198.40910966657933f, 423.7008860314684f));
|
||||
pts.push_back(Point2f(175.47011114845057f, 420.4223434173364f));
|
||||
pts.push_back(Point2f(154.92083551695902f, 418.5288198459268f));
|
||||
pts.push_back(Point2f(136.52988517939698f, 417.8311217226818f));
|
||||
pts.push_back(Point2f(114.74657291069317f, 410.1534699388714f));
|
||||
pts.push_back(Point2f(78.9220388330042f, 397.6266608135022f));
|
||||
pts.push_back(Point2f(76.82658673144391f, 404.27399269891055f));
|
||||
pts.push_back(Point2f(50.953595435605116f, 386.3824077178053f));
|
||||
pts.push_back(Point2f(43.603489077456985f, 368.7894972436907f));
|
||||
pts.push_back(Point2f(19.37402592752713f, 343.3511017547511f));
|
||||
pts.push_back(Point2f(8.714663367287343f, 322.2148323327599f));
|
||||
pts.push_back(Point2f(0., 288.7836318007535f));
|
||||
pts.push_back(Point2f(3.98686689837605f, 263.1748167870333f));
|
||||
pts.push_back(Point2f(9.536389714519785f, 233.02995195684738f));
|
||||
pts.push_back(Point2f(17.83246556512455f, 205.6536519851621f));
|
||||
pts.push_back(Point2f(33.00593702846919f, 180.52628138608327f));
|
||||
pts.push_back(Point2f(41.572400996463394f, 153.95185568689314f));
|
||||
pts.push_back(Point2f(54.55733659450332f, 136.54322891729444f));
|
||||
pts.push_back(Point2f(78.60990563833005f, 112.76538180538182f));
|
||||
|
||||
bool directGoodQ;
|
||||
float tol = 0.01f;
|
||||
|
||||
RotatedRect ellipseDirectTrue = cv::RotatedRect(Point2f(236.836f, 208.089f),Size2f(515.893f, 357.166f), -35.9996f);
|
||||
RotatedRect ellipseDirectTest = fitEllipseDirect(pts);
|
||||
Point2f ellipseDirectTrueVertices[4];
|
||||
Point2f ellipseDirectTestVertices[4];
|
||||
ellipseDirectTest.points(ellipseDirectTestVertices);
|
||||
ellipseDirectTrue.points(ellipseDirectTrueVertices);
|
||||
float directDiff = 0.0f;
|
||||
for (size_t i=0; i <=3; i++) {
|
||||
Point2f diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[0];
|
||||
float d = diff.x * diff.x + diff.y * diff.y;
|
||||
for (size_t j=1; i <=3; i++) {
|
||||
diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[j];
|
||||
float dd = diff.x * diff.x + diff.y * diff.y;
|
||||
if(dd<d){d=dd;}
|
||||
}
|
||||
directDiff += std::sqrt(d);
|
||||
}
|
||||
directGoodQ = directDiff < tol;
|
||||
|
||||
EXPECT_TRUE(directGoodQ);
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST(Imgproc_FitEllipseDirect_Issue_5, accuracy) {
|
||||
vector<Point2f>pts;
|
||||
pts.push_back(Point2f(509.60609444351917f, 484.8233016998119f));
|
||||
pts.push_back(Point2f(508.55357451809846f, 498.61004779125176f));
|
||||
pts.push_back(Point2f(495.59325478416525f, 507.9238702677585f));
|
||||
pts.push_back(Point2f(455.32905012177747f, 517.7518674113691f));
|
||||
pts.push_back(Point2f(461.24821761238667f, 524.2115477440211f));
|
||||
pts.push_back(Point2f(438.8983455906825f, 528.424911702069f));
|
||||
pts.push_back(Point2f(425.9259699875303f, 532.5700430134499f));
|
||||
pts.push_back(Point2f(405.77496728300616f, 535.7295008444993f));
|
||||
pts.push_back(Point2f(384.31968113982475f, 536.3076260371831f));
|
||||
pts.push_back(Point2f(381.5356536818977f, 540.183355729414f));
|
||||
pts.push_back(Point2f(378.2530503455792f, 540.2871855284832f));
|
||||
pts.push_back(Point2f(357.7242088314752f, 543.473075733281f));
|
||||
pts.push_back(Point2f(339.27871831324853f, 541.2099003613087f));
|
||||
pts.push_back(Point2f(339.22481874867435f, 541.1105421426018f));
|
||||
pts.push_back(Point2f(331.50337377509396f, 539.7296050163102f));
|
||||
pts.push_back(Point2f(317.8306501537862f, 540.9077275195326f));
|
||||
pts.push_back(Point2f(304.9192648323086f, 541.3434792768918f));
|
||||
pts.push_back(Point2f(297.33855427908617f, 543.0590309600501f));
|
||||
pts.push_back(Point2f(288.95330515997694f, 543.8756702506837f));
|
||||
pts.push_back(Point2f(278.5850913122515f, 538.1343888329859f));
|
||||
pts.push_back(Point2f(266.05355938101724f, 538.4115695907074f));
|
||||
pts.push_back(Point2f(255.30186994366096f, 534.2459272411796f));
|
||||
pts.push_back(Point2f(238.52054973466758f, 537.5007401480628f));
|
||||
pts.push_back(Point2f(228.444463024996f, 533.8992361116678f));
|
||||
pts.push_back(Point2f(217.8111623149833f, 538.2269193558991f));
|
||||
pts.push_back(Point2f(209.43502138981037f, 532.8057062984569f));
|
||||
pts.push_back(Point2f(193.33570716763276f, 527.2038128630041f));
|
||||
pts.push_back(Point2f(172.66725340039625f, 526.4020881005537f));
|
||||
pts.push_back(Point2f(158.33654199771337f, 525.2093856704676f));
|
||||
pts.push_back(Point2f(148.65905485249067f, 521.0146762179431f));
|
||||
pts.push_back(Point2f(147.6615365176719f, 517.4315201992808f));
|
||||
pts.push_back(Point2f(122.43568509949394f, 514.2089723387337f));
|
||||
pts.push_back(Point2f(110.88482982039073f, 509.14004840857046f));
|
||||
pts.push_back(Point2f(107.10516681523065f, 502.49943180234266f));
|
||||
pts.push_back(Point2f(82.66611013934804f, 494.0581153893113f));
|
||||
pts.push_back(Point2f(63.573319848965966f, 485.6772487054385f));
|
||||
pts.push_back(Point2f(47.65729058071245f, 475.4468806518075f));
|
||||
pts.push_back(Point2f(19.96819458379347f, 463.98285210241943f));
|
||||
pts.push_back(Point2f(27.855803175234342f, 450.2298664426336f));
|
||||
pts.push_back(Point2f(12.832198085636549f, 435.6317753810441f));
|
||||
|
||||
bool directGoodQ;
|
||||
float tol = 0.01f;
|
||||
|
||||
RotatedRect ellipseDirectTrue = cv::RotatedRect(Point2f(264.354f, 457.336f),Size2f(493.728f, 162.9f), 5.36186f);
|
||||
RotatedRect ellipseDirectTest = fitEllipseDirect(pts);
|
||||
Point2f ellipseDirectTrueVertices[4];
|
||||
Point2f ellipseDirectTestVertices[4];
|
||||
ellipseDirectTest.points(ellipseDirectTestVertices);
|
||||
ellipseDirectTrue.points(ellipseDirectTrueVertices);
|
||||
float directDiff = 0.0f;
|
||||
for (size_t i=0; i <=3; i++) {
|
||||
Point2f diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[0];
|
||||
float d = diff.x * diff.x + diff.y * diff.y;
|
||||
for (size_t j=1; i <=3; i++) {
|
||||
diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[j];
|
||||
float dd = diff.x * diff.x + diff.y * diff.y;
|
||||
if(dd<d){d=dd;}
|
||||
}
|
||||
directDiff += std::sqrt(d);
|
||||
}
|
||||
directGoodQ = directDiff < tol;
|
||||
|
||||
EXPECT_TRUE(directGoodQ);
|
||||
}
|
||||
|
||||
TEST(Imgproc_FitEllipseDirect_Issue_6, accuracy) {
|
||||
vector<Point2f>pts;
|
||||
pts.push_back(Point2f(414.90156479295905f, 29.063453659930833f));
|
||||
pts.push_back(Point2f(393.79576036337977f, 58.59512774879134f));
|
||||
pts.push_back(Point2f(387.9100725249931f, 94.65067695657254f));
|
||||
pts.push_back(Point2f(351.6987114318621f, 124.6049267560123f));
|
||||
pts.push_back(Point2f(335.3270519942532f, 154.52182750730412f));
|
||||
pts.push_back(Point2f(329.2955843262556f, 179.38031343427303f));
|
||||
pts.push_back(Point2f(322.7316812937696f, 201.88774427737036f));
|
||||
pts.push_back(Point2f(301.48326350826585f, 217.63331351026562f));
|
||||
pts.push_back(Point2f(287.4603938315088f, 228.68790184154113f));
|
||||
pts.push_back(Point2f(273.36617750656023f, 234.48397257849905f));
|
||||
pts.push_back(Point2f(270.7787206270782f, 242.85279436204632f));
|
||||
pts.push_back(Point2f(268.6973828073692f, 246.10891460870312f));
|
||||
pts.push_back(Point2f(261.60715070464255f, 252.65744793902192f));
|
||||
pts.push_back(Point2f(262.9041824871923f, 257.1813047575656f));
|
||||
pts.push_back(Point2f(263.3210079177046f, 260.0532193246593f));
|
||||
pts.push_back(Point2f(248.49568488533242f, 264.56723557175013f));
|
||||
pts.push_back(Point2f(245.4134174127509f, 264.87259401292f));
|
||||
pts.push_back(Point2f(244.73208618171216f, 272.32307359830884f));
|
||||
pts.push_back(Point2f(232.82093196087555f, 272.0239734764616f));
|
||||
pts.push_back(Point2f(235.28539413113458f, 276.8668447478244f));
|
||||
pts.push_back(Point2f(231.9766571511147f, 277.71179872893083f));
|
||||
pts.push_back(Point2f(227.23880706209866f, 284.5588878789101f));
|
||||
pts.push_back(Point2f(222.53202223537826f, 282.2293154479012f));
|
||||
pts.push_back(Point2f(217.27525654729595f, 297.42961148365725f));
|
||||
pts.push_back(Point2f(212.19490057230672f, 294.5344078014253f));
|
||||
pts.push_back(Point2f(207.47417472945446f, 301.72230412668307f));
|
||||
pts.push_back(Point2f(202.11143229969164f, 298.8588627545512f));
|
||||
pts.push_back(Point2f(196.62967096845824f, 309.39738607353223f));
|
||||
pts.push_back(Point2f(190.37809841992106f, 318.3250479151242f));
|
||||
pts.push_back(Point2f(183.1296129732803f, 322.35242231955453f));
|
||||
pts.push_back(Point2f(171.58530535265993f, 330.4981441404153f));
|
||||
pts.push_back(Point2f(160.40092880652247f, 337.47275990208226f));
|
||||
pts.push_back(Point2f(149.44888762618092f, 343.42296086656717f));
|
||||
pts.push_back(Point2f(139.7923528305302f, 353.4821948045352f));
|
||||
pts.push_back(Point2f(121.08414969113318f, 359.7010225709457f));
|
||||
pts.push_back(Point2f(100.10629739219641f, 375.3155744055458f));
|
||||
pts.push_back(Point2f(78.15715630786733f, 389.0311284319413f));
|
||||
pts.push_back(Point2f(51.22820988075294f, 396.98646504159547f));
|
||||
pts.push_back(Point2f(30.71132492338431f, 402.85098740402844f));
|
||||
pts.push_back(Point2f(10.994737323179852f, 394.6764602972333f));
|
||||
|
||||
bool directGoodQ;
|
||||
float tol = 0.01f;
|
||||
|
||||
RotatedRect ellipseDirectTrue = cv::RotatedRect(Point2f(207.145f, 223.308f),Size2f(499.583f, 117.473f), -42.6851f);
|
||||
RotatedRect ellipseDirectTest = fitEllipseDirect(pts);
|
||||
Point2f ellipseDirectTrueVertices[4];
|
||||
Point2f ellipseDirectTestVertices[4];
|
||||
ellipseDirectTest.points(ellipseDirectTestVertices);
|
||||
ellipseDirectTrue.points(ellipseDirectTrueVertices);
|
||||
float directDiff = 0.0f;
|
||||
for (size_t i=0; i <=3; i++) {
|
||||
Point2f diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[0];
|
||||
float d = diff.x * diff.x + diff.y * diff.y;
|
||||
for (size_t j=1; i <=3; i++) {
|
||||
diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[j];
|
||||
float dd = diff.x * diff.x + diff.y * diff.y;
|
||||
if(dd<d){d=dd;}
|
||||
}
|
||||
directDiff += std::sqrt(d);
|
||||
}
|
||||
directGoodQ = directDiff < tol;
|
||||
|
||||
EXPECT_TRUE(directGoodQ);
|
||||
}
|
||||
|
||||
TEST(Imgproc_FitEllipseDirect_Issue_7, accuracy) {
|
||||
vector<Point2f>pts;
|
||||
pts.push_back(Point2f(386.7497806918209f, 119.55623710363142f));
|
||||
pts.push_back(Point2f(399.0712613744503f, 132.61095972401034f));
|
||||
pts.push_back(Point2f(400.3582576852657f, 146.71942033652573f));
|
||||
pts.push_back(Point2f(383.31046706707906f, 160.13631428164982f));
|
||||
pts.push_back(Point2f(387.1626582455823f, 173.82700569763574f));
|
||||
pts.push_back(Point2f(378.88843308401425f, 186.10333319745317f));
|
||||
pts.push_back(Point2f(367.55061701208f, 201.41492900400164f));
|
||||
pts.push_back(Point2f(360.3254967185148f, 209.03834085076022f));
|
||||
pts.push_back(Point2f(346.2645164278429f, 222.03214282040395f));
|
||||
pts.push_back(Point2f(342.3483403634167f, 230.58290419787073f));
|
||||
pts.push_back(Point2f(326.2900969991908f, 240.23679566682756f));
|
||||
pts.push_back(Point2f(324.5622396580625f, 249.56961396707823f));
|
||||
pts.push_back(Point2f(304.23417130914095f, 259.6693711280021f));
|
||||
pts.push_back(Point2f(295.54035697534675f, 270.82284542557704f));
|
||||
pts.push_back(Point2f(291.7403057147348f, 276.1536825048371f));
|
||||
pts.push_back(Point2f(269.19344116558665f, 287.1705579044651f));
|
||||
pts.push_back(Point2f(256.5350613899267f, 274.91264707500943f));
|
||||
pts.push_back(Point2f(245.93644351417183f, 286.12398028743064f));
|
||||
pts.push_back(Point2f(232.40892420943732f, 282.73986583867065f));
|
||||
pts.push_back(Point2f(216.17957969101082f, 293.22229708237705f));
|
||||
pts.push_back(Point2f(205.66843722622573f, 295.7032575625158f));
|
||||
pts.push_back(Point2f(192.219969335765f, 302.6968969534755f));
|
||||
pts.push_back(Point2f(178.37758801730416f, 295.56656776633287f));
|
||||
pts.push_back(Point2f(167.60089103756644f, 301.4629292267722f));
|
||||
pts.push_back(Point2f(157.44802813915317f, 298.90830855734504f));
|
||||
pts.push_back(Point2f(138.44311818820313f, 293.951927187897f));
|
||||
pts.push_back(Point2f(128.92747660038592f, 291.4122695492978f));
|
||||
pts.push_back(Point2f(119.75160909865994f, 282.5809454721714f));
|
||||
pts.push_back(Point2f(98.48443737042328f, 290.39938776333247f));
|
||||
pts.push_back(Point2f(88.05275635126131f, 280.11156058895745f));
|
||||
pts.push_back(Point2f(82.45799026448167f, 271.46668468419773f));
|
||||
pts.push_back(Point2f(68.04031962064084f, 267.8136468580707f));
|
||||
pts.push_back(Point2f(58.99967170878713f, 263.8859310392943f));
|
||||
pts.push_back(Point2f(41.256097220823484f, 260.6041605773932f));
|
||||
pts.push_back(Point2f(40.66198797608645f, 246.64973068177196f));
|
||||
pts.push_back(Point2f(31.085484380646008f, 239.28615601336074f));
|
||||
pts.push_back(Point2f(24.069417111444253f, 225.2228746297288f));
|
||||
pts.push_back(Point2f(22.10122953275156f, 212.75509683149195f));
|
||||
pts.push_back(Point2f(9.929991244497518f, 203.20662088477752f));
|
||||
pts.push_back(Point2f(0.0f, 190.04891498441148f));
|
||||
|
||||
bool directGoodQ;
|
||||
float tol = 0.01f;
|
||||
|
||||
RotatedRect ellipseDirectTrue = cv::RotatedRect(Point2f(199.463f, 150.997f),Size2f(390.341f, 286.01f), -12.9696f);
|
||||
RotatedRect ellipseDirectTest = fitEllipseDirect(pts);
|
||||
Point2f ellipseDirectTrueVertices[4];
|
||||
Point2f ellipseDirectTestVertices[4];
|
||||
ellipseDirectTest.points(ellipseDirectTestVertices);
|
||||
ellipseDirectTrue.points(ellipseDirectTrueVertices);
|
||||
float directDiff = 0.0f;
|
||||
for (size_t i=0; i <=3; i++) {
|
||||
Point2f diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[0];
|
||||
float d = diff.x * diff.x + diff.y * diff.y;
|
||||
for (size_t j=1; i <=3; i++) {
|
||||
diff = ellipseDirectTrueVertices[i] - ellipseDirectTestVertices[j];
|
||||
float dd = diff.x * diff.x + diff.y * diff.y;
|
||||
if(dd<d){d=dd;}
|
||||
}
|
||||
directDiff += std::sqrt(d);
|
||||
}
|
||||
directGoodQ = directDiff < tol;
|
||||
|
||||
EXPECT_TRUE(directGoodQ);
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
545
3rdparty/opencv-4.5.4/modules/imgproc/test/test_floodfill.cpp
vendored
Normal file
545
3rdparty/opencv-4.5.4/modules/imgproc/test/test_floodfill.cpp
vendored
Normal file
@@ -0,0 +1,545 @@
|
||||
/*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.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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_FloodFillTest : public cvtest::ArrayTest
|
||||
{
|
||||
public:
|
||||
CV_FloodFillTest();
|
||||
|
||||
protected:
|
||||
void get_test_array_types_and_sizes( int test_case_idx, vector<vector<Size> >& sizes, vector<vector<int> >& types );
|
||||
double get_success_error_level( int test_case_idx, int i, int j );
|
||||
void run_func();
|
||||
void prepare_to_validation( int );
|
||||
|
||||
void fill_array( int test_case_idx, int i, int j, Mat& arr );
|
||||
|
||||
/*int write_default_params(CvFileStorage* fs);
|
||||
void get_timing_test_array_types_and_sizes( int test_case_idx, vector<vector<Size> >& sizes, vector<vector<int> >& types
|
||||
CvSize** whole_sizes, bool *are_images );
|
||||
void print_timing_params( int test_case_idx, char* ptr, int params_left );*/
|
||||
Point seed_pt;
|
||||
Scalar new_val;
|
||||
Scalar l_diff, u_diff;
|
||||
int connectivity;
|
||||
bool use_mask, mask_only;
|
||||
int range_type;
|
||||
int new_mask_val;
|
||||
bool test_cpp;
|
||||
};
|
||||
|
||||
|
||||
CV_FloodFillTest::CV_FloodFillTest()
|
||||
{
|
||||
test_array[INPUT_OUTPUT].push_back(NULL);
|
||||
test_array[INPUT_OUTPUT].push_back(NULL);
|
||||
test_array[REF_INPUT_OUTPUT].push_back(NULL);
|
||||
test_array[REF_INPUT_OUTPUT].push_back(NULL);
|
||||
test_array[OUTPUT].push_back(NULL);
|
||||
test_array[REF_OUTPUT].push_back(NULL);
|
||||
optional_mask = false;
|
||||
element_wise_relative_error = true;
|
||||
|
||||
test_cpp = false;
|
||||
}
|
||||
|
||||
|
||||
void CV_FloodFillTest::get_test_array_types_and_sizes( int test_case_idx,
|
||||
vector<vector<Size> >& sizes,
|
||||
vector<vector<int> >& types )
|
||||
{
|
||||
RNG& rng = ts->get_rng();
|
||||
int depth, cn;
|
||||
int i;
|
||||
double buff[8];
|
||||
cvtest::ArrayTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
|
||||
|
||||
depth = cvtest::randInt(rng) % 3;
|
||||
depth = depth == 0 ? CV_8U : depth == 1 ? CV_32S : CV_32F;
|
||||
cn = cvtest::randInt(rng) & 1 ? 3 : 1;
|
||||
|
||||
use_mask = (cvtest::randInt(rng) & 1) != 0;
|
||||
connectivity = (cvtest::randInt(rng) & 1) ? 4 : 8;
|
||||
mask_only = use_mask && (cvtest::randInt(rng) & 1) != 0;
|
||||
new_mask_val = cvtest::randInt(rng) & 255;
|
||||
range_type = cvtest::randInt(rng) % 3;
|
||||
|
||||
types[INPUT_OUTPUT][0] = types[REF_INPUT_OUTPUT][0] = CV_MAKETYPE(depth, cn);
|
||||
types[INPUT_OUTPUT][1] = types[REF_INPUT_OUTPUT][1] = CV_8UC1;
|
||||
types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_64FC1;
|
||||
sizes[OUTPUT][0] = sizes[REF_OUTPUT][0] = cvSize(9,1);
|
||||
|
||||
if( !use_mask )
|
||||
sizes[INPUT_OUTPUT][1] = sizes[REF_INPUT_OUTPUT][1] = cvSize(0,0);
|
||||
else
|
||||
{
|
||||
Size sz = sizes[INPUT_OUTPUT][0];
|
||||
sizes[INPUT_OUTPUT][1] = sizes[REF_INPUT_OUTPUT][1] = Size(sz.width+2,sz.height+2);
|
||||
}
|
||||
|
||||
seed_pt.x = cvtest::randInt(rng) % sizes[INPUT_OUTPUT][0].width;
|
||||
seed_pt.y = cvtest::randInt(rng) % sizes[INPUT_OUTPUT][0].height;
|
||||
|
||||
if( range_type == 0 )
|
||||
l_diff = u_diff = Scalar::all(0.);
|
||||
else
|
||||
{
|
||||
Mat m( 1, 8, CV_16S, buff );
|
||||
rng.fill( m, RNG::NORMAL, Scalar::all(0), Scalar::all(32) );
|
||||
for( i = 0; i < 4; i++ )
|
||||
{
|
||||
l_diff.val[i] = fabs(m.at<short>(i)/16.);
|
||||
u_diff.val[i] = fabs(m.at<short>(i+4)/16.);
|
||||
}
|
||||
}
|
||||
|
||||
new_val = Scalar::all(0.);
|
||||
for( i = 0; i < cn; i++ )
|
||||
new_val.val[i] = cvtest::randReal(rng)*255;
|
||||
|
||||
test_cpp = (cvtest::randInt(rng) & 256) == 0;
|
||||
}
|
||||
|
||||
|
||||
double CV_FloodFillTest::get_success_error_level( int /*test_case_idx*/, int i, int j )
|
||||
{
|
||||
return i == OUTPUT ? FLT_EPSILON : j == 0 ? FLT_EPSILON : 0;
|
||||
}
|
||||
|
||||
|
||||
void CV_FloodFillTest::fill_array( int test_case_idx, int i, int j, Mat& arr )
|
||||
{
|
||||
RNG& rng = ts->get_rng();
|
||||
|
||||
if( i != INPUT && i != INPUT_OUTPUT )
|
||||
{
|
||||
cvtest::ArrayTest::fill_array( test_case_idx, i, j, arr );
|
||||
return;
|
||||
}
|
||||
|
||||
if( j == 0 )
|
||||
{
|
||||
Mat tmp = arr;
|
||||
Scalar m = Scalar::all(128);
|
||||
Scalar s = Scalar::all(10);
|
||||
|
||||
if( arr.depth() == CV_32FC1 )
|
||||
tmp.create(arr.size(), CV_MAKETYPE(CV_8U, arr.channels()));
|
||||
|
||||
if( range_type == 0 )
|
||||
s = Scalar::all(2);
|
||||
|
||||
rng.fill(tmp, RNG::NORMAL, m, s );
|
||||
if( arr.data != tmp.data )
|
||||
cvtest::convert(tmp, arr, arr.type());
|
||||
}
|
||||
else
|
||||
{
|
||||
Scalar l = Scalar::all(-2);
|
||||
Scalar u = Scalar::all(2);
|
||||
cvtest::randUni(rng, arr, l, u );
|
||||
rectangle( arr, Point(0,0), Point(arr.cols-1,arr.rows-1), Scalar::all(1), 1, 8, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CV_FloodFillTest::run_func()
|
||||
{
|
||||
int flags = connectivity + (mask_only ? CV_FLOODFILL_MASK_ONLY : 0) +
|
||||
(range_type == 1 ? CV_FLOODFILL_FIXED_RANGE : 0) + (new_mask_val << 8);
|
||||
double* odata = test_mat[OUTPUT][0].ptr<double>();
|
||||
|
||||
if(!test_cpp)
|
||||
{
|
||||
CvConnectedComp comp;
|
||||
cvFloodFill( test_array[INPUT_OUTPUT][0], cvPoint(seed_pt), cvScalar(new_val), cvScalar(l_diff), cvScalar(u_diff), &comp,
|
||||
flags, test_array[INPUT_OUTPUT][1] );
|
||||
odata[0] = comp.area;
|
||||
odata[1] = comp.rect.x;
|
||||
odata[2] = comp.rect.y;
|
||||
odata[3] = comp.rect.width;
|
||||
odata[4] = comp.rect.height;
|
||||
odata[5] = comp.value.val[0];
|
||||
odata[6] = comp.value.val[1];
|
||||
odata[7] = comp.value.val[2];
|
||||
odata[8] = comp.value.val[3];
|
||||
}
|
||||
else
|
||||
{
|
||||
cv::Mat img = cv::cvarrToMat(test_array[INPUT_OUTPUT][0]),
|
||||
mask = test_array[INPUT_OUTPUT][1] ? cv::cvarrToMat(test_array[INPUT_OUTPUT][1]) : cv::Mat();
|
||||
cv::Rect rect;
|
||||
int area;
|
||||
if( mask.empty() )
|
||||
area = cv::floodFill( img, seed_pt, new_val, &rect, l_diff, u_diff, flags );
|
||||
else
|
||||
area = cv::floodFill( img, mask, seed_pt, new_val, &rect, l_diff, u_diff, flags );
|
||||
odata[0] = area;
|
||||
odata[1] = rect.x;
|
||||
odata[2] = rect.y;
|
||||
odata[3] = rect.width;
|
||||
odata[4] = rect.height;
|
||||
odata[5] = odata[6] = odata[7] = odata[8] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
typedef struct ff_offset_pair_t
|
||||
{
|
||||
int mofs, iofs;
|
||||
}
|
||||
ff_offset_pair_t;
|
||||
|
||||
static void
|
||||
cvTsFloodFill( CvMat* _img, CvPoint seed_pt, CvScalar new_val,
|
||||
CvScalar l_diff, CvScalar u_diff, CvMat* _mask,
|
||||
double* comp, int connectivity, int range_type,
|
||||
int new_mask_val, bool mask_only )
|
||||
{
|
||||
CvMemStorage* st = cvCreateMemStorage();
|
||||
ff_offset_pair_t p0, p;
|
||||
CvSeq* seq = cvCreateSeq( 0, sizeof(CvSeq), sizeof(p0), st );
|
||||
CvMat* tmp = _img;
|
||||
CvMat* mask;
|
||||
CvRect r = cvRect( 0, 0, -1, -1 );
|
||||
int area = 0;
|
||||
int i, j;
|
||||
ushort* m;
|
||||
float* img;
|
||||
int mstep, step;
|
||||
int cn = CV_MAT_CN(_img->type);
|
||||
int mdelta[8], idelta[8], ncount;
|
||||
int cols = _img->cols, rows = _img->rows;
|
||||
int u0 = 0, u1 = 0, u2 = 0;
|
||||
double s0 = 0, s1 = 0, s2 = 0;
|
||||
|
||||
if( CV_MAT_DEPTH(_img->type) == CV_8U || CV_MAT_DEPTH(_img->type) == CV_32S )
|
||||
{
|
||||
tmp = cvCreateMat( rows, cols, CV_MAKETYPE(CV_32F,CV_MAT_CN(_img->type)) );
|
||||
cvtest::convert(cvarrToMat(_img), cvarrToMat(tmp), -1);
|
||||
}
|
||||
|
||||
mask = cvCreateMat( rows + 2, cols + 2, CV_16UC1 );
|
||||
|
||||
if( _mask )
|
||||
cvtest::convert(cvarrToMat(_mask), cvarrToMat(mask), -1);
|
||||
else
|
||||
{
|
||||
Mat m_mask = cvarrToMat(mask);
|
||||
cvtest::set( m_mask, Scalar::all(0), Mat() );
|
||||
cvRectangle( mask, cvPoint(0,0), cvPoint(mask->cols-1,mask->rows-1), cvScalar(Scalar::all(1.)), 1, 8, 0 );
|
||||
}
|
||||
|
||||
new_mask_val = (new_mask_val != 0 ? new_mask_val : 1) << 8;
|
||||
|
||||
m = (ushort*)(mask->data.ptr + mask->step) + 1;
|
||||
mstep = mask->step / sizeof(m[0]);
|
||||
img = tmp->data.fl;
|
||||
step = tmp->step / sizeof(img[0]);
|
||||
|
||||
p0.mofs = seed_pt.y*mstep + seed_pt.x;
|
||||
p0.iofs = seed_pt.y*step + seed_pt.x*cn;
|
||||
|
||||
if( m[p0.mofs] )
|
||||
goto _exit_;
|
||||
|
||||
cvSeqPush( seq, &p0 );
|
||||
m[p0.mofs] = (ushort)new_mask_val;
|
||||
|
||||
if( connectivity == 4 )
|
||||
{
|
||||
ncount = 4;
|
||||
mdelta[0] = -mstep; idelta[0] = -step;
|
||||
mdelta[1] = -1; idelta[1] = -cn;
|
||||
mdelta[2] = 1; idelta[2] = cn;
|
||||
mdelta[3] = mstep; idelta[3] = step;
|
||||
}
|
||||
else
|
||||
{
|
||||
ncount = 8;
|
||||
mdelta[0] = -mstep-1; mdelta[1] = -mstep; mdelta[2] = -mstep+1;
|
||||
idelta[0] = -step-cn; idelta[1] = -step; idelta[2] = -step+cn;
|
||||
|
||||
mdelta[3] = -1; mdelta[4] = 1;
|
||||
idelta[3] = -cn; idelta[4] = cn;
|
||||
|
||||
mdelta[5] = mstep-1; mdelta[6] = mstep; mdelta[7] = mstep+1;
|
||||
idelta[5] = step-cn; idelta[6] = step; idelta[7] = step+cn;
|
||||
}
|
||||
|
||||
if( cn == 1 )
|
||||
{
|
||||
float a0 = (float)-l_diff.val[0];
|
||||
float b0 = (float)u_diff.val[0];
|
||||
|
||||
s0 = img[p0.iofs];
|
||||
|
||||
if( range_type < 2 )
|
||||
{
|
||||
a0 += (float)s0; b0 += (float)s0;
|
||||
}
|
||||
|
||||
while( seq->total )
|
||||
{
|
||||
cvSeqPop( seq, &p0 );
|
||||
float a = a0, b = b0;
|
||||
float* ptr = img + p0.iofs;
|
||||
ushort* mptr = m + p0.mofs;
|
||||
|
||||
if( range_type == 2 )
|
||||
a += ptr[0], b += ptr[0];
|
||||
|
||||
for( i = 0; i < ncount; i++ )
|
||||
{
|
||||
int md = mdelta[i], id = idelta[i];
|
||||
float v;
|
||||
if( !mptr[md] && a <= (v = ptr[id]) && v <= b )
|
||||
{
|
||||
mptr[md] = (ushort)new_mask_val;
|
||||
p.mofs = p0.mofs + md;
|
||||
p.iofs = p0.iofs + id;
|
||||
cvSeqPush( seq, &p );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
float a0 = (float)-l_diff.val[0];
|
||||
float a1 = (float)-l_diff.val[1];
|
||||
float a2 = (float)-l_diff.val[2];
|
||||
float b0 = (float)u_diff.val[0];
|
||||
float b1 = (float)u_diff.val[1];
|
||||
float b2 = (float)u_diff.val[2];
|
||||
|
||||
s0 = img[p0.iofs];
|
||||
s1 = img[p0.iofs + 1];
|
||||
s2 = img[p0.iofs + 2];
|
||||
|
||||
if( range_type < 2 )
|
||||
{
|
||||
a0 += (float)s0; b0 += (float)s0;
|
||||
a1 += (float)s1; b1 += (float)s1;
|
||||
a2 += (float)s2; b2 += (float)s2;
|
||||
}
|
||||
|
||||
while( seq->total )
|
||||
{
|
||||
cvSeqPop( seq, &p0 );
|
||||
float _a0 = a0, _a1 = a1, _a2 = a2;
|
||||
float _b0 = b0, _b1 = b1, _b2 = b2;
|
||||
float* ptr = img + p0.iofs;
|
||||
ushort* mptr = m + p0.mofs;
|
||||
|
||||
if( range_type == 2 )
|
||||
{
|
||||
_a0 += ptr[0]; _b0 += ptr[0];
|
||||
_a1 += ptr[1]; _b1 += ptr[1];
|
||||
_a2 += ptr[2]; _b2 += ptr[2];
|
||||
}
|
||||
|
||||
for( i = 0; i < ncount; i++ )
|
||||
{
|
||||
int md = mdelta[i], id = idelta[i];
|
||||
float v;
|
||||
if( !mptr[md] &&
|
||||
_a0 <= (v = ptr[id]) && v <= _b0 &&
|
||||
_a1 <= (v = ptr[id+1]) && v <= _b1 &&
|
||||
_a2 <= (v = ptr[id+2]) && v <= _b2 )
|
||||
{
|
||||
mptr[md] = (ushort)new_mask_val;
|
||||
p.mofs = p0.mofs + md;
|
||||
p.iofs = p0.iofs + id;
|
||||
cvSeqPush( seq, &p );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
r.x = r.width = seed_pt.x;
|
||||
r.y = r.height = seed_pt.y;
|
||||
|
||||
if( !mask_only )
|
||||
{
|
||||
s0 = new_val.val[0];
|
||||
s1 = new_val.val[1];
|
||||
s2 = new_val.val[2];
|
||||
|
||||
if( tmp != _img )
|
||||
{
|
||||
u0 = saturate_cast<uchar>(s0);
|
||||
u1 = saturate_cast<uchar>(s1);
|
||||
u2 = saturate_cast<uchar>(s2);
|
||||
|
||||
s0 = u0;
|
||||
s1 = u1;
|
||||
s2 = u2;
|
||||
}
|
||||
}
|
||||
else
|
||||
s0 = s1 = s2 = 0;
|
||||
|
||||
new_mask_val >>= 8;
|
||||
|
||||
for( i = 0; i < rows; i++ )
|
||||
{
|
||||
float* ptr = img + i*step;
|
||||
ushort* mptr = m + i*mstep;
|
||||
uchar* dmptr = _mask ? _mask->data.ptr + (i+1)*_mask->step + 1 : 0;
|
||||
double area0 = area;
|
||||
|
||||
for( j = 0; j < cols; j++ )
|
||||
{
|
||||
if( mptr[j] > 255 )
|
||||
{
|
||||
if( dmptr )
|
||||
dmptr[j] = (uchar)new_mask_val;
|
||||
if( !mask_only )
|
||||
{
|
||||
if( cn == 1 )
|
||||
ptr[j] = (float)s0;
|
||||
else
|
||||
{
|
||||
ptr[j*3] = (float)s0;
|
||||
ptr[j*3+1] = (float)s1;
|
||||
ptr[j*3+2] = (float)s2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( cn == 1 )
|
||||
s0 += ptr[j];
|
||||
else
|
||||
{
|
||||
s0 += ptr[j*3];
|
||||
s1 += ptr[j*3+1];
|
||||
s2 += ptr[j*3+2];
|
||||
}
|
||||
}
|
||||
|
||||
area++;
|
||||
if( r.x > j )
|
||||
r.x = j;
|
||||
if( r.width < j )
|
||||
r.width = j;
|
||||
}
|
||||
}
|
||||
|
||||
if( area != area0 )
|
||||
{
|
||||
if( r.y > i )
|
||||
r.y = i;
|
||||
if( r.height < i )
|
||||
r.height = i;
|
||||
}
|
||||
}
|
||||
|
||||
_exit_:
|
||||
cvReleaseMat( &mask );
|
||||
if( tmp != _img )
|
||||
{
|
||||
if( !mask_only )
|
||||
cvtest::convert(cvarrToMat(tmp), cvarrToMat(_img), -1);
|
||||
cvReleaseMat( &tmp );
|
||||
}
|
||||
|
||||
comp[0] = area;
|
||||
comp[1] = r.x;
|
||||
comp[2] = r.y;
|
||||
comp[3] = r.width - r.x + 1;
|
||||
comp[4] = r.height - r.y + 1;
|
||||
#if 0
|
||||
if( mask_only )
|
||||
{
|
||||
double t = area ? 1./area : 0;
|
||||
s0 *= t;
|
||||
s1 *= t;
|
||||
s2 *= t;
|
||||
}
|
||||
comp[5] = s0;
|
||||
comp[6] = s1;
|
||||
comp[7] = s2;
|
||||
#else
|
||||
comp[5] = new_val.val[0];
|
||||
comp[6] = new_val.val[1];
|
||||
comp[7] = new_val.val[2];
|
||||
#endif
|
||||
comp[8] = 0;
|
||||
|
||||
cvReleaseMemStorage(&st);
|
||||
}
|
||||
|
||||
|
||||
void CV_FloodFillTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
{
|
||||
double* comp = test_mat[REF_OUTPUT][0].ptr<double>();
|
||||
CvMat _input = cvMat(test_mat[REF_INPUT_OUTPUT][0]);
|
||||
CvMat _mask = cvMat(test_mat[REF_INPUT_OUTPUT][1]);
|
||||
cvTsFloodFill( &_input, cvPoint(seed_pt), cvScalar(new_val), cvScalar(l_diff), cvScalar(u_diff),
|
||||
_mask.data.ptr ? &_mask : 0,
|
||||
comp, connectivity, range_type,
|
||||
new_mask_val, mask_only );
|
||||
if(test_cpp)
|
||||
comp[5] = comp[6] = comp[7] = comp[8] = 0;
|
||||
}
|
||||
|
||||
TEST(Imgproc_FloodFill, accuracy) { CV_FloodFillTest test; test.safe_run(); }
|
||||
|
||||
TEST(Imgproc_FloodFill, maskValue)
|
||||
{
|
||||
const int n = 50;
|
||||
Mat img = Mat::zeros(n, n, CV_8U);
|
||||
Mat mask = Mat::zeros(n + 2, n + 2, CV_8U);
|
||||
|
||||
circle(img, Point(n/2, n/2), 20, Scalar(100), 4);
|
||||
|
||||
int flags = 4 + CV_FLOODFILL_MASK_ONLY;
|
||||
floodFill(img, mask, Point(n/2 + 13, n/2), Scalar(100), NULL, Scalar(), Scalar(), flags);
|
||||
|
||||
ASSERT_EQ(1, cvtest::norm(mask.rowRange(1, n-1).colRange(1, n-1), NORM_INF));
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
/* End of file. */
|
||||
526
3rdparty/opencv-4.5.4/modules/imgproc/test/test_goodfeaturetotrack.cpp
vendored
Normal file
526
3rdparty/opencv-4.5.4/modules/imgproc/test/test_goodfeaturetotrack.cpp
vendored
Normal file
@@ -0,0 +1,526 @@
|
||||
/*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.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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 {
|
||||
|
||||
enum { MINEIGENVAL=0, HARRIS=1, EIGENVALSVECS=2 };
|
||||
|
||||
|
||||
#if 0 //set 1 to switch ON debug message
|
||||
#define TEST_MESSAGE( message ) std::cout << message;
|
||||
#define TEST_MESSAGEL( message, val) std::cout << message << val << std::endl;
|
||||
#else
|
||||
#define TEST_MESSAGE( message )
|
||||
#define TEST_MESSAGEL( message, val)
|
||||
#endif
|
||||
|
||||
/////////////////////ref//////////////////////
|
||||
|
||||
struct greaterThanPtr
|
||||
{
|
||||
bool operator () (const float * a, const float * b) const
|
||||
{ return *a > *b; }
|
||||
};
|
||||
|
||||
static void
|
||||
test_cornerEigenValsVecs( const Mat& src, Mat& eigenv, int block_size,
|
||||
int _aperture_size, double k, int mode, int borderType, const Scalar& _borderValue )
|
||||
{
|
||||
int i, j;
|
||||
Scalar borderValue = _borderValue;
|
||||
int aperture_size = _aperture_size < 0 ? 3 : _aperture_size;
|
||||
Point anchor( aperture_size/2, aperture_size/2 );
|
||||
|
||||
CV_Assert( src.type() == CV_8UC1 || src.type() == CV_32FC1 );
|
||||
CV_Assert( eigenv.type() == CV_32FC1 );
|
||||
CV_Assert( ( src.rows == eigenv.rows ) &&
|
||||
(((mode == MINEIGENVAL)||(mode == HARRIS)) && (src.cols == eigenv.cols)) );
|
||||
|
||||
int type = src.type();
|
||||
int ftype = CV_32FC1;
|
||||
double kernel_scale = 1;
|
||||
|
||||
Mat dx2, dy2, dxdy(src.size(), CV_32F), kernel;
|
||||
|
||||
kernel = cvtest::calcSobelKernel2D( 1, 0, _aperture_size );
|
||||
cvtest::filter2D( src, dx2, ftype, kernel*kernel_scale, anchor, 0, borderType, borderValue );
|
||||
kernel = cvtest::calcSobelKernel2D( 0, 1, _aperture_size );
|
||||
cvtest::filter2D( src, dy2, ftype, kernel*kernel_scale, anchor, 0, borderType,borderValue );
|
||||
|
||||
double denom = (1 << (aperture_size-1))*block_size;
|
||||
|
||||
if( _aperture_size < 0 )
|
||||
denom *= 2.;
|
||||
if(type != ftype )
|
||||
denom *= 255.;
|
||||
|
||||
denom = 1. / (denom * denom);
|
||||
|
||||
for( i = 0; i < src.rows; i++ )
|
||||
{
|
||||
float* dxdyp = dxdy.ptr<float>(i);
|
||||
float* dx2p = dx2.ptr<float>(i);
|
||||
float* dy2p = dy2.ptr<float>(i);
|
||||
|
||||
for( j = 0; j < src.cols; j++ )
|
||||
{
|
||||
double xval = dx2p[j], yval = dy2p[j];
|
||||
dxdyp[j] = (float)(xval*yval*denom);
|
||||
dx2p[j] = (float)(xval*xval*denom);
|
||||
dy2p[j] = (float)(yval*yval*denom);
|
||||
}
|
||||
}
|
||||
|
||||
kernel = Mat::ones(block_size, block_size, CV_32F);
|
||||
anchor = Point(block_size/2, block_size/2);
|
||||
|
||||
cvtest::filter2D( dx2, dx2, ftype, kernel, anchor, 0, borderType, borderValue );
|
||||
cvtest::filter2D( dy2, dy2, ftype, kernel, anchor, 0, borderType, borderValue );
|
||||
cvtest::filter2D( dxdy, dxdy, ftype, kernel, anchor, 0, borderType, borderValue );
|
||||
|
||||
if( mode == MINEIGENVAL )
|
||||
{
|
||||
for( i = 0; i < src.rows; i++ )
|
||||
{
|
||||
float* eigenvp = eigenv.ptr<float>(i);
|
||||
const float* dxdyp = dxdy.ptr<float>(i);
|
||||
const float* dx2p = dx2.ptr<float>(i);
|
||||
const float* dy2p = dy2.ptr<float>(i);
|
||||
|
||||
for( j = 0; j < src.cols; j++ )
|
||||
{
|
||||
double a = dx2p[j], b = dxdyp[j], c = dy2p[j];
|
||||
double d = sqrt( ( a - c )*( a - c ) + 4*b*b );
|
||||
eigenvp[j] = (float)( 0.5*(a + c - d));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( mode == HARRIS )
|
||||
{
|
||||
|
||||
for( i = 0; i < src.rows; i++ )
|
||||
{
|
||||
float* eigenvp = eigenv.ptr<float>(i);
|
||||
const float* dxdyp = dxdy.ptr<float>(i);
|
||||
const float* dx2p = dx2.ptr<float>(i);
|
||||
const float* dy2p = dy2.ptr<float>(i);
|
||||
|
||||
for( j = 0; j < src.cols; j++ )
|
||||
{
|
||||
double a = dx2p[j], b = dxdyp[j], c = dy2p[j];
|
||||
eigenvp[j] = (float)(a*c - b*b - k*(a + c)*(a + c));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_goodFeaturesToTrack( InputArray _image, OutputArray _corners,
|
||||
int maxCorners, double qualityLevel, double minDistance,
|
||||
InputArray _mask, OutputArray _cornersQuality,
|
||||
int blockSize, int gradientSize, bool useHarrisDetector, double harrisK)
|
||||
{
|
||||
|
||||
CV_Assert( qualityLevel > 0 && minDistance >= 0 && maxCorners >= 0 );
|
||||
CV_Assert( _mask.empty() || (_mask.type() == CV_8UC1 && _mask.sameSize(_image)) );
|
||||
|
||||
|
||||
Mat image = _image.getMat(), mask = _mask.getMat();
|
||||
int aperture_size = gradientSize;
|
||||
int borderType = BORDER_DEFAULT;
|
||||
|
||||
Mat eig, tmp, tt;
|
||||
|
||||
eig.create( image.size(), CV_32F );
|
||||
|
||||
if( useHarrisDetector )
|
||||
test_cornerEigenValsVecs( image, eig, blockSize, aperture_size, harrisK, HARRIS, borderType, 0 );
|
||||
else
|
||||
test_cornerEigenValsVecs( image, eig, blockSize, aperture_size, 0, MINEIGENVAL, borderType, 0 );
|
||||
|
||||
double maxVal = 0;
|
||||
|
||||
cvtest::minMaxIdx( eig, 0, &maxVal, 0, 0, mask );
|
||||
cvtest::threshold( eig, eig, (float)(maxVal*qualityLevel), 0.f,THRESH_TOZERO );
|
||||
cvtest::dilate( eig, tmp, Mat(),Point(-1,-1),borderType,0);
|
||||
|
||||
Size imgsize = image.size();
|
||||
|
||||
vector<const float*> tmpCorners;
|
||||
|
||||
// collect list of pointers to features - put them into temporary image
|
||||
for( int y = 1; y < imgsize.height - 1; y++ )
|
||||
{
|
||||
const float* eig_data = (const float*)eig.ptr(y);
|
||||
const float* tmp_data = (const float*)tmp.ptr(y);
|
||||
const uchar* mask_data = mask.data ? mask.ptr(y) : 0;
|
||||
|
||||
for( int x = 1; x < imgsize.width - 1; x++ )
|
||||
{
|
||||
float val = eig_data[x];
|
||||
if( val != 0 && val == tmp_data[x] && (!mask_data || mask_data[x]) )
|
||||
{
|
||||
tmpCorners.push_back(eig_data + x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vector<Point2f> corners;
|
||||
vector<float> cornersQuality;
|
||||
size_t i, j, total = tmpCorners.size(), ncorners = 0;
|
||||
|
||||
std::sort( tmpCorners.begin(), tmpCorners.end(), greaterThanPtr() );
|
||||
|
||||
if(minDistance >= 1)
|
||||
{
|
||||
// Partition the image into larger grids
|
||||
int w = image.cols;
|
||||
int h = image.rows;
|
||||
|
||||
const int cell_size = cvRound(minDistance);
|
||||
const int grid_width = (w + cell_size - 1) / cell_size;
|
||||
const int grid_height = (h + cell_size - 1) / cell_size;
|
||||
|
||||
std::vector<std::vector<Point2f> > grid(grid_width*grid_height);
|
||||
|
||||
minDistance *= minDistance;
|
||||
|
||||
for( i = 0; i < total; i++ )
|
||||
{
|
||||
int ofs = (int)((const uchar*)tmpCorners[i] - eig.data);
|
||||
int y = (int)(ofs / eig.step);
|
||||
int x = (int)((ofs - y*eig.step)/sizeof(float));
|
||||
|
||||
bool good = true;
|
||||
|
||||
int x_cell = x / cell_size;
|
||||
int y_cell = y / cell_size;
|
||||
|
||||
int x1 = x_cell - 1;
|
||||
int y1 = y_cell - 1;
|
||||
int x2 = x_cell + 1;
|
||||
int y2 = y_cell + 1;
|
||||
|
||||
// boundary check
|
||||
x1 = std::max(0, x1);
|
||||
y1 = std::max(0, y1);
|
||||
x2 = std::min(grid_width-1, x2);
|
||||
y2 = std::min(grid_height-1, y2);
|
||||
|
||||
for( int yy = y1; yy <= y2; yy++ )
|
||||
{
|
||||
for( int xx = x1; xx <= x2; xx++ )
|
||||
{
|
||||
vector <Point2f> &m = grid[yy*grid_width + xx];
|
||||
|
||||
if( m.size() )
|
||||
{
|
||||
for(j = 0; j < m.size(); j++)
|
||||
{
|
||||
float dx = x - m[j].x;
|
||||
float dy = y - m[j].y;
|
||||
|
||||
if( dx*dx + dy*dy < minDistance )
|
||||
{
|
||||
good = false;
|
||||
goto break_out;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break_out:
|
||||
|
||||
if(good)
|
||||
{
|
||||
grid[y_cell*grid_width + x_cell].push_back(Point2f((float)x, (float)y));
|
||||
|
||||
cornersQuality.push_back(*tmpCorners[i]);
|
||||
|
||||
corners.push_back(Point2f((float)x, (float)y));
|
||||
++ncorners;
|
||||
|
||||
if( maxCorners > 0 && (int)ncorners == maxCorners )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( i = 0; i < total; i++ )
|
||||
{
|
||||
cornersQuality.push_back(*tmpCorners[i]);
|
||||
|
||||
int ofs = (int)((const uchar*)tmpCorners[i] - eig.data);
|
||||
int y = (int)(ofs / eig.step);
|
||||
int x = (int)((ofs - y*eig.step)/sizeof(float));
|
||||
|
||||
corners.push_back(Point2f((float)x, (float)y));
|
||||
++ncorners;
|
||||
|
||||
if( maxCorners > 0 && (int)ncorners == maxCorners )
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Mat(corners).convertTo(_corners, _corners.fixedType() ? _corners.type() : CV_32F);
|
||||
if (_cornersQuality.needed()) {
|
||||
Mat(cornersQuality).convertTo(_cornersQuality, _cornersQuality.fixedType() ? _cornersQuality.type() : CV_32F);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/////////////////end of ref code//////////////////////////
|
||||
|
||||
|
||||
|
||||
class CV_GoodFeatureToTTest : public cvtest::ArrayTest
|
||||
{
|
||||
public:
|
||||
CV_GoodFeatureToTTest();
|
||||
|
||||
protected:
|
||||
int prepare_test_case( int test_case_idx );
|
||||
void run_func();
|
||||
int validate_test_results( int test_case_idx );
|
||||
|
||||
Mat src, src_gray;
|
||||
Mat src_gray32f, src_gray8U;
|
||||
Mat mask;
|
||||
|
||||
int maxCorners;
|
||||
vector<Point2f> corners;
|
||||
vector<Point2f> Refcorners;
|
||||
vector<float> cornersQuality;
|
||||
vector<float> RefcornersQuality;
|
||||
double qualityLevel;
|
||||
double minDistance;
|
||||
int blockSize;
|
||||
int gradientSize;
|
||||
bool useHarrisDetector;
|
||||
double k;
|
||||
int SrcType;
|
||||
};
|
||||
|
||||
|
||||
CV_GoodFeatureToTTest::CV_GoodFeatureToTTest()
|
||||
{
|
||||
RNG& rng = ts->get_rng();
|
||||
maxCorners = rng.uniform( 50, 100 );
|
||||
qualityLevel = 0.01;
|
||||
minDistance = 10;
|
||||
blockSize = 3;
|
||||
gradientSize = 3;
|
||||
useHarrisDetector = false;
|
||||
k = 0.04;
|
||||
mask = Mat();
|
||||
test_case_count = 4;
|
||||
SrcType = 0;
|
||||
}
|
||||
|
||||
int CV_GoodFeatureToTTest::prepare_test_case( int test_case_idx )
|
||||
{
|
||||
const static int types[] = { CV_32FC1, CV_8UC1 };
|
||||
|
||||
cvtest::TS& tst = *cvtest::TS::ptr();
|
||||
src = imread(string(tst.get_data_path()) + "shared/fruits.png", IMREAD_COLOR);
|
||||
|
||||
CV_Assert(src.data != NULL);
|
||||
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
SrcType = types[test_case_idx & 0x1];
|
||||
useHarrisDetector = test_case_idx & 2 ? true : false;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void CV_GoodFeatureToTTest::run_func()
|
||||
{
|
||||
int cn = src_gray.channels();
|
||||
|
||||
CV_Assert( cn == 1 );
|
||||
CV_Assert( ( CV_MAT_DEPTH(SrcType) == CV_32FC1 ) || ( CV_MAT_DEPTH(SrcType) == CV_8UC1 ));
|
||||
|
||||
TEST_MESSAGEL (" maxCorners = ", maxCorners)
|
||||
if (useHarrisDetector)
|
||||
{
|
||||
TEST_MESSAGE (" useHarrisDetector = true\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
TEST_MESSAGE (" useHarrisDetector = false\n");
|
||||
}
|
||||
|
||||
if( CV_MAT_DEPTH(SrcType) == CV_32FC1)
|
||||
{
|
||||
if (src_gray.depth() != CV_32FC1 ) src_gray.convertTo(src_gray32f, CV_32FC1);
|
||||
else src_gray32f = src_gray.clone();
|
||||
|
||||
TEST_MESSAGE ("goodFeaturesToTrack 32f\n")
|
||||
|
||||
goodFeaturesToTrack( src_gray32f,
|
||||
corners,
|
||||
maxCorners,
|
||||
qualityLevel,
|
||||
minDistance,
|
||||
Mat(),
|
||||
cornersQuality,
|
||||
blockSize,
|
||||
gradientSize,
|
||||
useHarrisDetector,
|
||||
k );
|
||||
}
|
||||
else
|
||||
{
|
||||
if (src_gray.depth() != CV_8UC1 ) src_gray.convertTo(src_gray8U, CV_8UC1);
|
||||
else src_gray8U = src_gray.clone();
|
||||
|
||||
TEST_MESSAGE ("goodFeaturesToTrack 8U\n")
|
||||
|
||||
goodFeaturesToTrack( src_gray8U,
|
||||
corners,
|
||||
maxCorners,
|
||||
qualityLevel,
|
||||
minDistance,
|
||||
Mat(),
|
||||
cornersQuality,
|
||||
blockSize,
|
||||
gradientSize,
|
||||
useHarrisDetector,
|
||||
k );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int CV_GoodFeatureToTTest::validate_test_results( int test_case_idx )
|
||||
{
|
||||
static const double eps = 2e-6;
|
||||
|
||||
if( CV_MAT_DEPTH(SrcType) == CV_32FC1 )
|
||||
{
|
||||
if (src_gray.depth() != CV_32FC1 ) src_gray.convertTo(src_gray32f, CV_32FC1);
|
||||
else src_gray32f = src_gray.clone();
|
||||
|
||||
TEST_MESSAGE ("test_goodFeaturesToTrack 32f\n")
|
||||
|
||||
test_goodFeaturesToTrack( src_gray32f,
|
||||
Refcorners,
|
||||
maxCorners,
|
||||
qualityLevel,
|
||||
minDistance,
|
||||
Mat(),
|
||||
RefcornersQuality,
|
||||
blockSize,
|
||||
gradientSize,
|
||||
useHarrisDetector,
|
||||
k );
|
||||
}
|
||||
else
|
||||
{
|
||||
if (src_gray.depth() != CV_8UC1 ) src_gray.convertTo(src_gray8U, CV_8UC1);
|
||||
else src_gray8U = src_gray.clone();
|
||||
|
||||
TEST_MESSAGE ("test_goodFeaturesToTrack 8U\n")
|
||||
|
||||
test_goodFeaturesToTrack( src_gray8U,
|
||||
Refcorners,
|
||||
maxCorners,
|
||||
qualityLevel,
|
||||
minDistance,
|
||||
Mat(),
|
||||
RefcornersQuality,
|
||||
blockSize,
|
||||
gradientSize,
|
||||
useHarrisDetector,
|
||||
k );
|
||||
}
|
||||
|
||||
double e = cv::norm(corners, Refcorners); // TODO cvtest
|
||||
|
||||
if (e > eps)
|
||||
{
|
||||
TEST_MESSAGEL ("Number of features: Refcorners = ", Refcorners.size())
|
||||
TEST_MESSAGEL (" TestCorners = ", corners.size())
|
||||
TEST_MESSAGE ("\n")
|
||||
|
||||
EXPECT_LE(e, eps); // never true
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
|
||||
|
||||
for(int i = 0; i < (int)std::min((unsigned int)(corners.size()), (unsigned int)(Refcorners.size())); i++){
|
||||
if ( (corners[i].x != Refcorners[i].x) || (corners[i].y != Refcorners[i].y))
|
||||
printf("i = %i X %2.2f Xref %2.2f Y %2.2f Yref %2.2f\n",i,corners[i].x,Refcorners[i].x,corners[i].y,Refcorners[i].y);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TEST_MESSAGEL (" Refcorners = ", Refcorners.size())
|
||||
TEST_MESSAGEL (" TestCorners = ", corners.size())
|
||||
TEST_MESSAGE ("\n")
|
||||
|
||||
ts->set_failed_test_info(cvtest::TS::OK);
|
||||
}
|
||||
|
||||
e = cv::norm(cornersQuality, RefcornersQuality, NORM_RELATIVE | NORM_INF);
|
||||
|
||||
if (e > eps)
|
||||
{
|
||||
EXPECT_LE(e, eps); // never true
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
|
||||
|
||||
for(int i = 0; i < (int)std::min((unsigned int)(cornersQuality.size()), (unsigned int)(cornersQuality.size())); i++) {
|
||||
if (std::abs(cornersQuality[i] - RefcornersQuality[i]) > eps * std::max(cornersQuality[i], RefcornersQuality[i]))
|
||||
printf("i = %i Quality %2.6f Quality ref %2.6f\n", i, cornersQuality[i], RefcornersQuality[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return BaseTest::validate_test_results(test_case_idx);
|
||||
|
||||
}
|
||||
|
||||
TEST(Imgproc_GoodFeatureToT, accuracy) { CV_GoodFeatureToTTest test; test.safe_run(); }
|
||||
|
||||
|
||||
}} // namespace
|
||||
/* End of file. */
|
||||
178
3rdparty/opencv-4.5.4/modules/imgproc/test/test_grabcut.cpp
vendored
Normal file
178
3rdparty/opencv-4.5.4/modules/imgproc/test/test_grabcut.cpp
vendored
Normal file
@@ -0,0 +1,178 @@
|
||||
/*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_GrabcutTest : public cvtest::BaseTest
|
||||
{
|
||||
public:
|
||||
CV_GrabcutTest();
|
||||
~CV_GrabcutTest();
|
||||
protected:
|
||||
bool verify(const Mat& mask, const Mat& exp);
|
||||
void run(int);
|
||||
};
|
||||
|
||||
CV_GrabcutTest::CV_GrabcutTest() {}
|
||||
CV_GrabcutTest::~CV_GrabcutTest() {}
|
||||
|
||||
bool CV_GrabcutTest::verify(const Mat& mask, const Mat& exp)
|
||||
{
|
||||
const float maxDiffRatio = 0.005f;
|
||||
int expArea = countNonZero( exp );
|
||||
int nonIntersectArea = countNonZero( mask != exp );
|
||||
|
||||
float curRatio = (float)nonIntersectArea / (float)expArea;
|
||||
ts->printf( cvtest::TS::LOG, "nonIntersectArea/expArea = %f\n", curRatio );
|
||||
return curRatio < maxDiffRatio;
|
||||
}
|
||||
|
||||
void CV_GrabcutTest::run( int /* start_from */)
|
||||
{
|
||||
cvtest::DefaultRngAuto defRng;
|
||||
|
||||
Mat img = imread(string(ts->get_data_path()) + "shared/airplane.png");
|
||||
Mat mask_prob = imread(string(ts->get_data_path()) + "grabcut/mask_prob.png", 0);
|
||||
Mat exp_mask1 = imread(string(ts->get_data_path()) + "grabcut/exp_mask1.png", 0);
|
||||
Mat exp_mask2 = imread(string(ts->get_data_path()) + "grabcut/exp_mask2.png", 0);
|
||||
|
||||
if (img.empty() || (!mask_prob.empty() && img.size() != mask_prob.size()) ||
|
||||
(!exp_mask1.empty() && img.size() != exp_mask1.size()) ||
|
||||
(!exp_mask2.empty() && img.size() != exp_mask2.size()) )
|
||||
{
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_MISSING_TEST_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
Rect rect(Point(24, 126), Point(483, 294));
|
||||
Mat exp_bgdModel, exp_fgdModel;
|
||||
|
||||
Mat mask;
|
||||
Mat bgdModel, fgdModel;
|
||||
grabCut( img, mask, rect, bgdModel, fgdModel, 0, GC_INIT_WITH_RECT );
|
||||
bgdModel.copyTo(exp_bgdModel);
|
||||
fgdModel.copyTo(exp_fgdModel);
|
||||
grabCut( img, mask, rect, bgdModel, fgdModel, 2, GC_EVAL_FREEZE_MODEL );
|
||||
|
||||
// Multiply images by 255 for more visuality of test data.
|
||||
if( mask_prob.empty() )
|
||||
{
|
||||
mask.copyTo( mask_prob );
|
||||
imwrite(string(ts->get_data_path()) + "grabcut/mask_prob.png", mask_prob);
|
||||
}
|
||||
if( exp_mask1.empty() )
|
||||
{
|
||||
exp_mask1 = (mask & 1) * 255;
|
||||
imwrite(string(ts->get_data_path()) + "grabcut/exp_mask1.png", exp_mask1);
|
||||
}
|
||||
if (!verify((mask & 1) * 255, exp_mask1))
|
||||
{
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);
|
||||
return;
|
||||
}
|
||||
// The model should not be changed after calling with GC_EVAL_FREEZE_MODEL
|
||||
double sumBgdModel = cv::sum(cv::abs(bgdModel) - cv::abs(exp_bgdModel))[0];
|
||||
double sumFgdModel = cv::sum(cv::abs(fgdModel) - cv::abs(exp_fgdModel))[0];
|
||||
if (sumBgdModel >= 0.1 || sumFgdModel >= 0.1)
|
||||
{
|
||||
ts->printf(cvtest::TS::LOG, "sumBgdModel = %f, sumFgdModel = %f\n", sumBgdModel, sumFgdModel);
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);
|
||||
return;
|
||||
}
|
||||
|
||||
mask = mask_prob;
|
||||
bgdModel.release();
|
||||
fgdModel.release();
|
||||
rect = Rect();
|
||||
grabCut( img, mask, rect, bgdModel, fgdModel, 0, GC_INIT_WITH_MASK );
|
||||
grabCut( img, mask, rect, bgdModel, fgdModel, 1, GC_EVAL );
|
||||
|
||||
if( exp_mask2.empty() )
|
||||
{
|
||||
exp_mask2 = (mask & 1) * 255;
|
||||
imwrite(string(ts->get_data_path()) + "grabcut/exp_mask2.png", exp_mask2);
|
||||
}
|
||||
if (!verify((mask & 1) * 255, exp_mask2))
|
||||
{
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);
|
||||
return;
|
||||
}
|
||||
ts->set_failed_test_info(cvtest::TS::OK);
|
||||
}
|
||||
|
||||
TEST(Imgproc_GrabCut, regression) { CV_GrabcutTest test; test.safe_run(); }
|
||||
|
||||
TEST(Imgproc_GrabCut, repeatability)
|
||||
{
|
||||
cvtest::TS& ts = *cvtest::TS::ptr();
|
||||
|
||||
Mat image_1 = imread(string(ts.get_data_path()) + "grabcut/image1652.ppm", IMREAD_COLOR);
|
||||
Mat mask_1 = imread(string(ts.get_data_path()) + "grabcut/mask1652.ppm", IMREAD_GRAYSCALE);
|
||||
Rect roi_1(0, 0, 150, 150);
|
||||
|
||||
Mat image_2 = image_1.clone();
|
||||
Mat mask_2 = mask_1.clone();
|
||||
Rect roi_2 = roi_1;
|
||||
|
||||
Mat image_3 = image_1.clone();
|
||||
Mat mask_3 = mask_1.clone();
|
||||
Rect roi_3 = roi_1;
|
||||
|
||||
Mat bgdModel_1, fgdModel_1;
|
||||
Mat bgdModel_2, fgdModel_2;
|
||||
Mat bgdModel_3, fgdModel_3;
|
||||
|
||||
theRNG().state = 12378213;
|
||||
grabCut(image_1, mask_1, roi_1, bgdModel_1, fgdModel_1, 1, GC_INIT_WITH_MASK);
|
||||
theRNG().state = 12378213;
|
||||
grabCut(image_2, mask_2, roi_2, bgdModel_2, fgdModel_2, 1, GC_INIT_WITH_MASK);
|
||||
theRNG().state = 12378213;
|
||||
grabCut(image_3, mask_3, roi_3, bgdModel_3, fgdModel_3, 1, GC_INIT_WITH_MASK);
|
||||
|
||||
EXPECT_EQ(0, countNonZero(mask_1 != mask_2));
|
||||
EXPECT_EQ(0, countNonZero(mask_1 != mask_3));
|
||||
EXPECT_EQ(0, countNonZero(mask_2 != mask_3));
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
1998
3rdparty/opencv-4.5.4/modules/imgproc/test/test_histograms.cpp
vendored
Normal file
1998
3rdparty/opencv-4.5.4/modules/imgproc/test/test_histograms.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
321
3rdparty/opencv-4.5.4/modules/imgproc/test/test_houghcircles.cpp
vendored
Normal file
321
3rdparty/opencv-4.5.4/modules/imgproc/test/test_houghcircles.cpp
vendored
Normal file
@@ -0,0 +1,321 @@
|
||||
/*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.
|
||||
// Copyright (C) 2014, Itseez, 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 {
|
||||
|
||||
#ifndef DEBUG_IMAGES
|
||||
#define DEBUG_IMAGES 0
|
||||
#endif
|
||||
|
||||
//#define GENERATE_DATA // generate data in debug mode via CPU code path (without IPP / OpenCL and other accelerators)
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
static string getTestCaseName(const string& picture_name, double minDist, double edgeThreshold, double accumThreshold, int minRadius, int maxRadius)
|
||||
{
|
||||
string results_name = cv::format("circles_%s_%.0f_%.0f_%.0f_%d_%d",
|
||||
picture_name.c_str(), minDist, edgeThreshold, accumThreshold, minRadius, maxRadius);
|
||||
string temp(results_name);
|
||||
size_t pos = temp.find_first_of("\\/.");
|
||||
while (pos != string::npos) {
|
||||
temp.replace(pos, 1, "_");
|
||||
pos = temp.find_first_of("\\/.");
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
#if DEBUG_IMAGES
|
||||
static void highlightCircles(const string& imagePath, const vector<Vec3f>& circles, const string& outputImagePath)
|
||||
{
|
||||
Mat imgDebug = imread(imagePath, IMREAD_COLOR);
|
||||
const Scalar yellow(0, 255, 255);
|
||||
|
||||
for (vector<Vec3f>::const_iterator iter = circles.begin(); iter != circles.end(); ++iter)
|
||||
{
|
||||
const Vec3f& circle = *iter;
|
||||
float x = circle[0];
|
||||
float y = circle[1];
|
||||
float r = max(circle[2], 2.0f);
|
||||
cv::circle(imgDebug, Point(int(x), int(y)), int(r), yellow);
|
||||
}
|
||||
imwrite(outputImagePath, imgDebug);
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef tuple<string, double, double, double, int, int> Image_MinDist_EdgeThreshold_AccumThreshold_MinRadius_MaxRadius_t;
|
||||
class HoughCirclesTestFixture : public testing::TestWithParam<Image_MinDist_EdgeThreshold_AccumThreshold_MinRadius_MaxRadius_t>
|
||||
{
|
||||
string picture_name;
|
||||
double minDist;
|
||||
double edgeThreshold;
|
||||
double accumThreshold;
|
||||
int minRadius;
|
||||
int maxRadius;
|
||||
|
||||
public:
|
||||
HoughCirclesTestFixture()
|
||||
{
|
||||
picture_name = get<0>(GetParam());
|
||||
minDist = get<1>(GetParam());
|
||||
edgeThreshold = get<2>(GetParam());
|
||||
accumThreshold = get<3>(GetParam());
|
||||
minRadius = get<4>(GetParam());
|
||||
maxRadius = get<5>(GetParam());
|
||||
}
|
||||
|
||||
HoughCirclesTestFixture(const string& picture, double minD, double edge, double accum, int minR, int maxR) :
|
||||
picture_name(picture), minDist(minD), edgeThreshold(edge), accumThreshold(accum), minRadius(minR), maxRadius(maxR)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename CircleType>
|
||||
void run_test(const char* xml_name)
|
||||
{
|
||||
string test_case_name = getTestCaseName(picture_name, minDist, edgeThreshold, accumThreshold, minRadius, maxRadius);
|
||||
string filename = cvtest::TS::ptr()->get_data_path() + picture_name;
|
||||
Mat src = imread(filename, IMREAD_GRAYSCALE);
|
||||
EXPECT_FALSE(src.empty()) << "Invalid test image: " << filename;
|
||||
|
||||
GaussianBlur(src, src, Size(9, 9), 2, 2);
|
||||
|
||||
vector<CircleType> circles;
|
||||
const double dp = 1.0;
|
||||
HoughCircles(src, circles, CV_HOUGH_GRADIENT, dp, minDist, edgeThreshold, accumThreshold, minRadius, maxRadius);
|
||||
|
||||
string imgProc = string(cvtest::TS::ptr()->get_data_path()) + "imgproc/";
|
||||
#if DEBUG_IMAGES
|
||||
highlightCircles(filename, circles, imgProc + test_case_name + ".png");
|
||||
#endif
|
||||
|
||||
string xml = imgProc + xml_name;
|
||||
#ifdef GENERATE_DATA
|
||||
{
|
||||
FileStorage fs(xml, FileStorage::READ);
|
||||
ASSERT_TRUE(!fs.isOpened() || fs[test_case_name].empty());
|
||||
}
|
||||
{
|
||||
FileStorage fs(xml, FileStorage::APPEND);
|
||||
EXPECT_TRUE(fs.isOpened()) << "Cannot open sanity data file: " << xml;
|
||||
fs << test_case_name << circles;
|
||||
}
|
||||
#else
|
||||
FileStorage fs(xml, FileStorage::READ);
|
||||
FileNode node = fs[test_case_name];
|
||||
ASSERT_FALSE(node.empty()) << "Missing test data: " << test_case_name << std::endl << "XML: " << xml;
|
||||
vector<CircleType> exp_circles;
|
||||
read(fs[test_case_name], exp_circles, vector<CircleType>());
|
||||
fs.release();
|
||||
EXPECT_EQ(exp_circles.size(), circles.size());
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(HoughCirclesTestFixture, regression)
|
||||
{
|
||||
run_test<Vec3f>("HoughCircles.xml");
|
||||
}
|
||||
|
||||
TEST_P(HoughCirclesTestFixture, regression4f)
|
||||
{
|
||||
run_test<Vec4f>("HoughCircles4f.xml");
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ImgProc, HoughCirclesTestFixture, testing::Combine(
|
||||
// picture_name:
|
||||
testing::Values("imgproc/stuff.jpg"),
|
||||
// minDist:
|
||||
testing::Values(20),
|
||||
// edgeThreshold:
|
||||
testing::Values(20),
|
||||
// accumThreshold:
|
||||
testing::Values(30),
|
||||
// minRadius:
|
||||
testing::Values(20),
|
||||
// maxRadius:
|
||||
testing::Values(200)
|
||||
));
|
||||
|
||||
|
||||
class HoughCirclesTest : public testing::TestWithParam<HoughModes>
|
||||
{
|
||||
protected:
|
||||
HoughModes method;
|
||||
public:
|
||||
HoughCirclesTest() { method = GetParam(); }
|
||||
};
|
||||
|
||||
TEST_P(HoughCirclesTest, DefaultMaxRadius)
|
||||
{
|
||||
string picture_name = "imgproc/stuff.jpg";
|
||||
string filename = cvtest::TS::ptr()->get_data_path() + picture_name;
|
||||
Mat src = imread(filename, IMREAD_GRAYSCALE);
|
||||
EXPECT_FALSE(src.empty()) << "Invalid test image: " << filename;
|
||||
GaussianBlur(src, src, Size(9, 9), 2, 2);
|
||||
|
||||
double dp = 1.0;
|
||||
double minDist = 20.0;
|
||||
double edgeThreshold = 20.0;
|
||||
double param2 = method == HOUGH_GRADIENT_ALT ? 0.9 : 30.;
|
||||
int minRadius = method == HOUGH_GRADIENT_ALT ? 10 : 20;
|
||||
int maxRadius = 0;
|
||||
|
||||
vector<Vec3f> circles;
|
||||
vector<Vec4f> circles4f;
|
||||
HoughCircles(src, circles, method, dp, minDist, edgeThreshold, param2, minRadius, maxRadius);
|
||||
HoughCircles(src, circles4f, method, dp, minDist, edgeThreshold, param2, minRadius, maxRadius);
|
||||
|
||||
#if DEBUG_IMAGES
|
||||
string imgProc = string(cvtest::TS::ptr()->get_data_path()) + "imgproc/";
|
||||
highlightCircles(filename, circles, imgProc + "HoughCirclesTest_DefaultMaxRadius.png");
|
||||
#endif
|
||||
|
||||
int maxDimension = std::max(src.rows, src.cols);
|
||||
|
||||
if(method == HOUGH_GRADIENT_ALT)
|
||||
{
|
||||
EXPECT_EQ(circles.size(), size_t(3)) << "Should find 3 circles";
|
||||
}
|
||||
else
|
||||
{
|
||||
EXPECT_GT(circles.size(), size_t(0)) << "Should find at least some circles";
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < circles.size(); ++i)
|
||||
{
|
||||
EXPECT_GE(circles[i][2], minRadius) << "Radius should be >= minRadius";
|
||||
EXPECT_LE(circles[i][2], maxDimension) << "Radius should be <= max image dimension";
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(HoughCirclesTest, CentersOnly)
|
||||
{
|
||||
string picture_name = "imgproc/stuff.jpg";
|
||||
string filename = cvtest::TS::ptr()->get_data_path() + picture_name;
|
||||
Mat src = imread(filename, IMREAD_GRAYSCALE);
|
||||
EXPECT_FALSE(src.empty()) << "Invalid test image: " << filename;
|
||||
|
||||
GaussianBlur(src, src, Size(9, 9), 2, 2);
|
||||
double dp = 1.0;
|
||||
double minDist = 20.0;
|
||||
double edgeThreshold = 20.0;
|
||||
double param2 = method == HOUGH_GRADIENT_ALT ? 0.9 : 30.;
|
||||
int minRadius = method == HOUGH_GRADIENT_ALT ? 10 : 20;
|
||||
int maxRadius = -1;
|
||||
|
||||
vector<Vec3f> circles;
|
||||
vector<Vec4f> circles4f;
|
||||
|
||||
HoughCircles(src, circles, method, dp, minDist, edgeThreshold, param2, minRadius, maxRadius);
|
||||
HoughCircles(src, circles4f, method, dp, minDist, edgeThreshold, param2, minRadius, maxRadius);
|
||||
|
||||
#if DEBUG_IMAGES
|
||||
string imgProc = string(cvtest::TS::ptr()->get_data_path()) + "imgproc/";
|
||||
highlightCircles(filename, circles, imgProc + "HoughCirclesTest_DefaultMaxRadius.png");
|
||||
#endif
|
||||
|
||||
if(method == HOUGH_GRADIENT_ALT)
|
||||
{
|
||||
EXPECT_EQ(circles.size(), size_t(3)) << "Should find 3 circles";
|
||||
}
|
||||
else
|
||||
{
|
||||
EXPECT_GT(circles.size(), size_t(0)) << "Should find at least some circles";
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < circles.size(); ++i)
|
||||
{
|
||||
if( method == HOUGH_GRADIENT )
|
||||
{
|
||||
EXPECT_EQ(circles[i][2], 0.0f) << "Did not ask for radius";
|
||||
}
|
||||
EXPECT_EQ(circles[i][0], circles4f[i][0]);
|
||||
EXPECT_EQ(circles[i][1], circles4f[i][1]);
|
||||
EXPECT_EQ(circles[i][2], circles4f[i][2]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(HoughCirclesTest, ManySmallCircles)
|
||||
{
|
||||
string picture_name = "imgproc/beads.jpg";
|
||||
|
||||
string filename = cvtest::TS::ptr()->get_data_path() + picture_name;
|
||||
Mat src = imread(filename, IMREAD_GRAYSCALE);
|
||||
EXPECT_FALSE(src.empty()) << "Invalid test image: " << filename;
|
||||
|
||||
const double dp = method == HOUGH_GRADIENT_ALT ? 1.5 : 1.0;
|
||||
double minDist = 10;
|
||||
double edgeThreshold = 90;
|
||||
double accumThreshold = 11;
|
||||
double minCos2 = 0.85;
|
||||
double param2 = method == HOUGH_GRADIENT_ALT ? minCos2 : accumThreshold;
|
||||
int minRadius = 7;
|
||||
int maxRadius = 18;
|
||||
int ncircles_min = method == HOUGH_GRADIENT_ALT ? 2000 : 3000;
|
||||
|
||||
Mat src_smooth;
|
||||
if( method == HOUGH_GRADIENT_ALT )
|
||||
GaussianBlur(src, src_smooth, Size(7, 7), 1.5, 1.5);
|
||||
else
|
||||
src.copyTo(src_smooth);
|
||||
vector<Vec3f> circles;
|
||||
vector<Vec4f> circles4f;
|
||||
HoughCircles(src_smooth, circles, method, dp, minDist, edgeThreshold, param2, minRadius, maxRadius);
|
||||
HoughCircles(src_smooth, circles4f, method, dp, minDist, edgeThreshold, param2, minRadius, maxRadius);
|
||||
|
||||
#if DEBUG_IMAGES
|
||||
string imgProc = string(cvtest::TS::ptr()->get_data_path()) + "imgproc/";
|
||||
string test_case_name = getTestCaseName(picture_name, minDist, edgeThreshold, accumThreshold, minRadius, maxRadius);
|
||||
highlightCircles(filename, circles, imgProc + test_case_name + ".png");
|
||||
#endif
|
||||
|
||||
EXPECT_GT(circles.size(), size_t(ncircles_min)) << "Should find a lot of circles";
|
||||
EXPECT_EQ(circles.size(), circles4f.size());
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(HoughGradient, HoughCirclesTest, testing::Values(HOUGH_GRADIENT));
|
||||
INSTANTIATE_TEST_CASE_P(HoughGradientAlt, HoughCirclesTest, testing::Values(HOUGH_GRADIENT_ALT));
|
||||
|
||||
}} // namespace
|
||||
322
3rdparty/opencv-4.5.4/modules/imgproc/test/test_houghlines.cpp
vendored
Normal file
322
3rdparty/opencv-4.5.4/modules/imgproc/test/test_houghlines.cpp
vendored
Normal file
@@ -0,0 +1,322 @@
|
||||
/*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.
|
||||
// Copyright (C) 2014, Itseez, 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"
|
||||
|
||||
//#define GENERATE_DATA // generate data in debug mode via CPU code path (without IPP / OpenCL and other accelerators)
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
template<typename T>
|
||||
struct SimilarWith
|
||||
{
|
||||
T value;
|
||||
float theta_eps;
|
||||
float rho_eps;
|
||||
SimilarWith<T>(T val, float e, float r_e): value(val), theta_eps(e), rho_eps(r_e) { };
|
||||
bool operator()(const T& other);
|
||||
};
|
||||
|
||||
template<>
|
||||
bool SimilarWith<Vec2f>::operator()(const Vec2f& other)
|
||||
{
|
||||
return std::abs(other[0] - value[0]) < rho_eps && std::abs(other[1] - value[1]) < theta_eps;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool SimilarWith<Vec3f>::operator()(const Vec3f& other)
|
||||
{
|
||||
return std::abs(other[0] - value[0]) < rho_eps && std::abs(other[1] - value[1]) < theta_eps;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool SimilarWith<Vec4i>::operator()(const Vec4i& other)
|
||||
{
|
||||
return cv::norm(value, other) < theta_eps;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int countMatIntersection(const Mat& expect, const Mat& actual, float eps, float rho_eps)
|
||||
{
|
||||
int count = 0;
|
||||
if (!expect.empty() && !actual.empty())
|
||||
{
|
||||
for (MatConstIterator_<T> it=expect.begin<T>(); it!=expect.end<T>(); it++)
|
||||
{
|
||||
MatConstIterator_<T> f = std::find_if(actual.begin<T>(), actual.end<T>(), SimilarWith<T>(*it, eps, rho_eps));
|
||||
if (f != actual.end<T>())
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
String getTestCaseName(String filename)
|
||||
{
|
||||
string temp(filename);
|
||||
size_t pos = temp.find_first_of("\\/.");
|
||||
while ( pos != string::npos ) {
|
||||
temp.replace( pos, 1, "_" );
|
||||
pos = temp.find_first_of("\\/.");
|
||||
}
|
||||
return String(temp);
|
||||
}
|
||||
|
||||
class BaseHoughLineTest
|
||||
{
|
||||
public:
|
||||
enum {STANDART = 0, PROBABILISTIC};
|
||||
protected:
|
||||
template<typename LinesType, typename LineType>
|
||||
void run_test(int type, const char* xml_name);
|
||||
|
||||
string picture_name;
|
||||
double rhoStep;
|
||||
double thetaStep;
|
||||
int threshold;
|
||||
int minLineLength;
|
||||
int maxGap;
|
||||
};
|
||||
|
||||
typedef tuple<string, double, double, int> Image_RhoStep_ThetaStep_Threshold_t;
|
||||
class StandartHoughLinesTest : public BaseHoughLineTest, public testing::TestWithParam<Image_RhoStep_ThetaStep_Threshold_t>
|
||||
{
|
||||
public:
|
||||
StandartHoughLinesTest()
|
||||
{
|
||||
picture_name = get<0>(GetParam());
|
||||
rhoStep = get<1>(GetParam());
|
||||
thetaStep = get<2>(GetParam());
|
||||
threshold = get<3>(GetParam());
|
||||
minLineLength = 0;
|
||||
maxGap = 0;
|
||||
}
|
||||
};
|
||||
|
||||
typedef tuple<string, double, double, int, int, int> Image_RhoStep_ThetaStep_Threshold_MinLine_MaxGap_t;
|
||||
class ProbabilisticHoughLinesTest : public BaseHoughLineTest, public testing::TestWithParam<Image_RhoStep_ThetaStep_Threshold_MinLine_MaxGap_t>
|
||||
{
|
||||
public:
|
||||
ProbabilisticHoughLinesTest()
|
||||
{
|
||||
picture_name = get<0>(GetParam());
|
||||
rhoStep = get<1>(GetParam());
|
||||
thetaStep = get<2>(GetParam());
|
||||
threshold = get<3>(GetParam());
|
||||
minLineLength = get<4>(GetParam());
|
||||
maxGap = get<5>(GetParam());
|
||||
}
|
||||
};
|
||||
|
||||
typedef tuple<double, double, double, double> HoughLinesPointSetInput_t;
|
||||
class HoughLinesPointSetTest : public testing::TestWithParam<HoughLinesPointSetInput_t>
|
||||
{
|
||||
protected:
|
||||
void run_test();
|
||||
double Rho;
|
||||
double Theta;
|
||||
double rhoMin, rhoMax, rhoStep;
|
||||
double thetaMin, thetaMax, thetaStep;
|
||||
public:
|
||||
HoughLinesPointSetTest()
|
||||
{
|
||||
rhoMin = get<0>(GetParam());
|
||||
rhoMax = get<1>(GetParam());
|
||||
rhoStep = (rhoMax - rhoMin) / 360.0f;
|
||||
thetaMin = get<2>(GetParam());
|
||||
thetaMax = get<3>(GetParam());
|
||||
thetaStep = CV_PI / 180.0f;
|
||||
Rho = 320.00000;
|
||||
Theta = 1.04719;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename LinesType, typename LineType>
|
||||
void BaseHoughLineTest::run_test(int type, const char* xml_name)
|
||||
{
|
||||
string filename = cvtest::TS::ptr()->get_data_path() + picture_name;
|
||||
Mat src = imread(filename, IMREAD_GRAYSCALE);
|
||||
ASSERT_FALSE(src.empty()) << "Invalid test image: " << filename;
|
||||
|
||||
string xml = string(cvtest::TS::ptr()->get_data_path()) + "imgproc/" + xml_name;
|
||||
|
||||
Mat dst;
|
||||
Canny(src, dst, 100, 150, 3);
|
||||
ASSERT_FALSE(dst.empty()) << "Failed Canny edge detector";
|
||||
|
||||
LinesType lines;
|
||||
if (type == STANDART)
|
||||
HoughLines(dst, lines, rhoStep, thetaStep, threshold, 0, 0);
|
||||
else if (type == PROBABILISTIC)
|
||||
HoughLinesP(dst, lines, rhoStep, thetaStep, threshold, minLineLength, maxGap);
|
||||
|
||||
String test_case_name = format("lines_%s_%.0f_%.2f_%d_%d_%d", picture_name.c_str(), rhoStep, thetaStep,
|
||||
threshold, minLineLength, maxGap);
|
||||
test_case_name = getTestCaseName(test_case_name);
|
||||
|
||||
#ifdef GENERATE_DATA
|
||||
{
|
||||
FileStorage fs(xml, FileStorage::READ);
|
||||
ASSERT_TRUE(!fs.isOpened() || fs[test_case_name].empty());
|
||||
}
|
||||
{
|
||||
FileStorage fs(xml, FileStorage::APPEND);
|
||||
EXPECT_TRUE(fs.isOpened()) << "Cannot open sanity data file: " << xml;
|
||||
fs << test_case_name << Mat(lines);
|
||||
}
|
||||
#else
|
||||
FileStorage fs(xml, FileStorage::READ);
|
||||
FileNode node = fs[test_case_name];
|
||||
ASSERT_FALSE(node.empty()) << "Missing test data: " << test_case_name << std::endl << "XML: " << xml;
|
||||
|
||||
Mat exp_lines_;
|
||||
read(fs[test_case_name], exp_lines_, Mat());
|
||||
fs.release();
|
||||
LinesType exp_lines;
|
||||
exp_lines_.copyTo(exp_lines);
|
||||
|
||||
int count = -1;
|
||||
if (type == STANDART)
|
||||
count = countMatIntersection<LineType>(Mat(exp_lines), Mat(lines), (float) thetaStep + FLT_EPSILON, (float) rhoStep + FLT_EPSILON);
|
||||
else if (type == PROBABILISTIC)
|
||||
count = countMatIntersection<LineType>(Mat(exp_lines), Mat(lines), 1e-4f, 0.f);
|
||||
|
||||
#if defined HAVE_IPP && IPP_VERSION_X100 >= 810 && !IPP_DISABLE_HOUGH
|
||||
EXPECT_LE(std::abs((double)count - Mat(exp_lines).total()), Mat(exp_lines).total() * 0.25)
|
||||
<< "count=" << count << " expected=" << Mat(exp_lines).total();
|
||||
#else
|
||||
EXPECT_EQ(count, (int)Mat(exp_lines).total());
|
||||
#endif
|
||||
#endif // GENERATE_DATA
|
||||
}
|
||||
|
||||
void HoughLinesPointSetTest::run_test(void)
|
||||
{
|
||||
Mat lines_f, lines_i;
|
||||
vector<Point2f> pointf;
|
||||
vector<Point2i> pointi;
|
||||
vector<Vec3d> line_polar_f, line_polar_i;
|
||||
const float Points[20][2] = {
|
||||
{ 0.0f, 369.0f }, { 10.0f, 364.0f }, { 20.0f, 358.0f }, { 30.0f, 352.0f },
|
||||
{ 40.0f, 346.0f }, { 50.0f, 341.0f }, { 60.0f, 335.0f }, { 70.0f, 329.0f },
|
||||
{ 80.0f, 323.0f }, { 90.0f, 318.0f }, { 100.0f, 312.0f }, { 110.0f, 306.0f },
|
||||
{ 120.0f, 300.0f }, { 130.0f, 295.0f }, { 140.0f, 289.0f }, { 150.0f, 284.0f },
|
||||
{ 160.0f, 277.0f }, { 170.0f, 271.0f }, { 180.0f, 266.0f }, { 190.0f, 260.0f }
|
||||
};
|
||||
|
||||
// Float
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
pointf.push_back(Point2f(Points[i][0],Points[i][1]));
|
||||
}
|
||||
|
||||
HoughLinesPointSet(pointf, lines_f, 20, 1,
|
||||
rhoMin, rhoMax, rhoStep,
|
||||
thetaMin, thetaMax, thetaStep);
|
||||
|
||||
lines_f.copyTo( line_polar_f );
|
||||
|
||||
// Integer
|
||||
for( int i = 0; i < 20; i++ )
|
||||
{
|
||||
pointi.push_back( Point2i( (int)Points[i][0], (int)Points[i][1] ) );
|
||||
}
|
||||
|
||||
HoughLinesPointSet( pointi, lines_i, 20, 1,
|
||||
rhoMin, rhoMax, rhoStep,
|
||||
thetaMin, thetaMax, thetaStep );
|
||||
|
||||
lines_i.copyTo( line_polar_i );
|
||||
|
||||
EXPECT_EQ((int)(line_polar_f.at(0).val[1] * 100000.0f), (int)(Rho * 100000.0f));
|
||||
EXPECT_EQ((int)(line_polar_f.at(0).val[2] * 100000.0f), (int)(Theta * 100000.0f));
|
||||
EXPECT_EQ((int)(line_polar_i.at(0).val[1] * 100000.0f), (int)(Rho * 100000.0f));
|
||||
EXPECT_EQ((int)(line_polar_i.at(0).val[2] * 100000.0f), (int)(Theta * 100000.0f));
|
||||
}
|
||||
|
||||
TEST_P(StandartHoughLinesTest, regression)
|
||||
{
|
||||
run_test<Mat, Vec2f>(STANDART, "HoughLines.xml");
|
||||
}
|
||||
|
||||
TEST_P(ProbabilisticHoughLinesTest, regression)
|
||||
{
|
||||
run_test<Mat, Vec4i>(PROBABILISTIC, "HoughLinesP.xml");
|
||||
}
|
||||
|
||||
TEST_P(StandartHoughLinesTest, regression_Vec2f)
|
||||
{
|
||||
run_test<std::vector<Vec2f>, Vec2f>(STANDART, "HoughLines2f.xml");
|
||||
}
|
||||
|
||||
TEST_P(StandartHoughLinesTest, regression_Vec3f)
|
||||
{
|
||||
run_test<std::vector<Vec3f>, Vec3f>(STANDART, "HoughLines3f.xml");
|
||||
}
|
||||
|
||||
TEST_P(HoughLinesPointSetTest, regression)
|
||||
{
|
||||
run_test();
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P( ImgProc, StandartHoughLinesTest, testing::Combine(testing::Values( "shared/pic5.png", "../stitching/a1.png" ),
|
||||
testing::Values( 1, 10 ),
|
||||
testing::Values( 0.05, 0.1 ),
|
||||
testing::Values( 80, 150 )
|
||||
));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P( ImgProc, ProbabilisticHoughLinesTest, testing::Combine(testing::Values( "shared/pic5.png", "shared/pic1.png" ),
|
||||
testing::Values( 5, 10 ),
|
||||
testing::Values( 0.05, 0.1 ),
|
||||
testing::Values( 75, 150 ),
|
||||
testing::Values( 0, 10 ),
|
||||
testing::Values( 0, 4 )
|
||||
));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P( Imgproc, HoughLinesPointSetTest, testing::Combine(testing::Values( 0.0f, 120.0f ),
|
||||
testing::Values( 360.0f, 480.0f ),
|
||||
testing::Values( 0.0f, (CV_PI / 18.0f) ),
|
||||
testing::Values( (CV_PI / 2.0f), (CV_PI * 5.0f / 12.0f) )
|
||||
));
|
||||
|
||||
}} // namespace
|
||||
84
3rdparty/opencv-4.5.4/modules/imgproc/test/test_imgproc_umat.cpp
vendored
Normal file
84
3rdparty/opencv-4.5.4/modules/imgproc/test/test_imgproc_umat.cpp
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
/*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_ImgprocUMatTest : public cvtest::BaseTest
|
||||
{
|
||||
public:
|
||||
CV_ImgprocUMatTest() {}
|
||||
~CV_ImgprocUMatTest() {}
|
||||
protected:
|
||||
void run(int)
|
||||
{
|
||||
string imgpath = string(ts->get_data_path()) + "shared/lena.png";
|
||||
Mat img = imread(imgpath, 1), gray, smallimg, result;
|
||||
UMat uimg = img.getUMat(ACCESS_READ), ugray, usmallimg, uresult;
|
||||
|
||||
cvtColor(img, gray, COLOR_BGR2GRAY);
|
||||
resize(gray, smallimg, Size(), 0.75, 0.75, INTER_LINEAR_EXACT);
|
||||
equalizeHist(smallimg, result);
|
||||
|
||||
cvtColor(uimg, ugray, COLOR_BGR2GRAY);
|
||||
resize(ugray, usmallimg, Size(), 0.75, 0.75, INTER_LINEAR_EXACT);
|
||||
equalizeHist(usmallimg, uresult);
|
||||
|
||||
#if 0
|
||||
imshow("orig", uimg);
|
||||
imshow("small", usmallimg);
|
||||
imshow("equalized gray", uresult);
|
||||
waitKey();
|
||||
destroyWindow("orig");
|
||||
destroyWindow("small");
|
||||
destroyWindow("equalized gray");
|
||||
#endif
|
||||
ts->set_failed_test_info(cvtest::TS::OK);
|
||||
|
||||
(void)uresult.getMat(ACCESS_READ);
|
||||
}
|
||||
};
|
||||
|
||||
TEST(Imgproc_UMat, regression) { CV_ImgprocUMatTest test; test.safe_run(); }
|
||||
|
||||
}} // namespace
|
||||
1663
3rdparty/opencv-4.5.4/modules/imgproc/test/test_imgwarp.cpp
vendored
Normal file
1663
3rdparty/opencv-4.5.4/modules/imgproc/test/test_imgwarp.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1331
3rdparty/opencv-4.5.4/modules/imgproc/test/test_imgwarp_strict.cpp
vendored
Normal file
1331
3rdparty/opencv-4.5.4/modules/imgproc/test/test_imgwarp_strict.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
467
3rdparty/opencv-4.5.4/modules/imgproc/test/test_intelligent_scissors.cpp
vendored
Normal file
467
3rdparty/opencv-4.5.4/modules/imgproc/test/test_intelligent_scissors.cpp
vendored
Normal file
@@ -0,0 +1,467 @@
|
||||
// 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"
|
||||
//#include "opencv2/imgproc/segmentation.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
|
||||
Mat getTestImageGray()
|
||||
{
|
||||
static Mat m;
|
||||
if (m.empty())
|
||||
{
|
||||
m = imread(findDataFile("shared/lena.png"), IMREAD_GRAYSCALE);
|
||||
}
|
||||
return m.clone();
|
||||
}
|
||||
|
||||
Mat getTestImageColor()
|
||||
{
|
||||
static Mat m;
|
||||
if (m.empty())
|
||||
{
|
||||
m = imread(findDataFile("shared/lena.png"), IMREAD_COLOR);
|
||||
}
|
||||
return m.clone();
|
||||
}
|
||||
|
||||
Mat getTestImage1()
|
||||
{
|
||||
static Mat m;
|
||||
if (m.empty())
|
||||
{
|
||||
m.create(Size(200, 100), CV_8UC1);
|
||||
m.setTo(Scalar::all(128));
|
||||
Rect roi(50, 30, 100, 40);
|
||||
m(roi).setTo(Scalar::all(0));
|
||||
#if 0
|
||||
imshow("image", m);
|
||||
waitKey();
|
||||
#endif
|
||||
}
|
||||
return m.clone();
|
||||
}
|
||||
|
||||
Mat getTestImage2()
|
||||
{
|
||||
static Mat m;
|
||||
if (m.empty())
|
||||
{
|
||||
m.create(Size(200, 100), CV_8UC1);
|
||||
m.setTo(Scalar::all(128));
|
||||
Rect roi(40, 30, 100, 40);
|
||||
m(roi).setTo(Scalar::all(255));
|
||||
#if 0
|
||||
imshow("image", m);
|
||||
waitKey();
|
||||
#endif
|
||||
}
|
||||
return m.clone();
|
||||
}
|
||||
|
||||
Mat getTestImage3()
|
||||
{
|
||||
static Mat m;
|
||||
if (m.empty())
|
||||
{
|
||||
m.create(Size(200, 100), CV_8UC1);
|
||||
m.setTo(Scalar::all(128));
|
||||
Scalar color(0,0,0,0);
|
||||
line(m, Point(30, 50), Point(50, 50), color, 1);
|
||||
line(m, Point(50, 50), Point(80, 30), color, 1);
|
||||
line(m, Point(150, 50), Point(80, 30), color, 1);
|
||||
line(m, Point(150, 50), Point(180, 50), color, 1);
|
||||
|
||||
line(m, Point(80, 10), Point(80, 90), Scalar::all(200), 1);
|
||||
line(m, Point(100, 10), Point(100, 90), Scalar::all(200), 1);
|
||||
line(m, Point(120, 10), Point(120, 90), Scalar::all(200), 1);
|
||||
#if 0
|
||||
imshow("image", m);
|
||||
waitKey();
|
||||
#endif
|
||||
}
|
||||
return m.clone();
|
||||
}
|
||||
|
||||
Mat getTestImage4()
|
||||
{
|
||||
static Mat m;
|
||||
if (m.empty())
|
||||
{
|
||||
m.create(Size(200, 100), CV_8UC1);
|
||||
for (int y = 0; y < m.rows; y++)
|
||||
{
|
||||
for (int x = 0; x < m.cols; x++)
|
||||
{
|
||||
float dx = (float)(x - 100);
|
||||
float dy = (float)(y - 100);
|
||||
float d = sqrtf(dx * dx + dy * dy);
|
||||
m.at<uchar>(y, x) = saturate_cast<uchar>(100 + 100 * sin(d / 10 * CV_PI));
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
imshow("image", m);
|
||||
waitKey();
|
||||
#endif
|
||||
}
|
||||
return m.clone();
|
||||
}
|
||||
|
||||
Mat getTestImage5()
|
||||
{
|
||||
static Mat m;
|
||||
if (m.empty())
|
||||
{
|
||||
m.create(Size(200, 100), CV_8UC1);
|
||||
for (int y = 0; y < m.rows; y++)
|
||||
{
|
||||
for (int x = 0; x < m.cols; x++)
|
||||
{
|
||||
float dx = (float)(x - 100);
|
||||
float dy = (float)(y - 100);
|
||||
float d = sqrtf(dx * dx + dy * dy);
|
||||
m.at<uchar>(y, x) = saturate_cast<uchar>(x / 2 + 100 * sin(d / 10 * CV_PI));
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
imshow("image", m);
|
||||
waitKey();
|
||||
#endif
|
||||
}
|
||||
return m.clone();
|
||||
}
|
||||
|
||||
void show(const Mat& img, const std::vector<Point> pts)
|
||||
{
|
||||
if (cvtest::debugLevel >= 10)
|
||||
{
|
||||
Mat dst = img.clone();
|
||||
std::vector< std::vector<Point> > contours;
|
||||
contours.push_back(pts);
|
||||
polylines(dst, contours, false, Scalar::all(255));
|
||||
imshow("dst", dst);
|
||||
waitKey();
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Imgproc_IntelligentScissorsMB, rect)
|
||||
{
|
||||
segmentation::IntelligentScissorsMB tool;
|
||||
|
||||
tool.applyImage(getTestImage1());
|
||||
|
||||
Point source_point(50, 30);
|
||||
tool.buildMap(source_point);
|
||||
|
||||
Point target_point(100, 30);
|
||||
std::vector<Point> pts;
|
||||
tool.getContour(target_point, pts);
|
||||
|
||||
tool.applyImage(getTestImage2());
|
||||
|
||||
tool.buildMap(source_point);
|
||||
|
||||
std::vector<Point> pts2;
|
||||
tool.getContour(target_point, pts2, true/*backward*/);
|
||||
|
||||
EXPECT_EQ(pts.size(), pts2.size());
|
||||
}
|
||||
|
||||
TEST(Imgproc_IntelligentScissorsMB, lines)
|
||||
{
|
||||
segmentation::IntelligentScissorsMB tool;
|
||||
Mat image = getTestImage3();
|
||||
tool.applyImage(image);
|
||||
|
||||
Point source_point(30, 50);
|
||||
tool.buildMap(source_point);
|
||||
|
||||
Point target_point(150, 50);
|
||||
std::vector<Point> pts;
|
||||
tool.getContour(target_point, pts);
|
||||
|
||||
EXPECT_EQ((size_t)121, pts.size());
|
||||
show(image, pts);
|
||||
}
|
||||
|
||||
TEST(Imgproc_IntelligentScissorsMB, circles)
|
||||
{
|
||||
segmentation::IntelligentScissorsMB tool;
|
||||
tool.setGradientMagnitudeMaxLimit(10);
|
||||
|
||||
Mat image = getTestImage4();
|
||||
tool.applyImage(image);
|
||||
|
||||
Point source_point(50, 50);
|
||||
tool.buildMap(source_point);
|
||||
|
||||
Point target_point(150, 50);
|
||||
std::vector<Point> pts;
|
||||
tool.getContour(target_point, pts);
|
||||
|
||||
EXPECT_EQ((size_t)101, pts.size());
|
||||
show(image, pts);
|
||||
}
|
||||
|
||||
TEST(Imgproc_IntelligentScissorsMB, circles_gradient)
|
||||
{
|
||||
segmentation::IntelligentScissorsMB tool;
|
||||
Mat image = getTestImage5();
|
||||
tool.applyImage(image);
|
||||
|
||||
Point source_point(50, 50);
|
||||
tool.buildMap(source_point);
|
||||
|
||||
Point target_point(150, 50);
|
||||
std::vector<Point> pts;
|
||||
tool.getContour(target_point, pts);
|
||||
|
||||
EXPECT_EQ((size_t)101, pts.size());
|
||||
show(image, pts);
|
||||
}
|
||||
|
||||
#define PTS_SIZE_EPS 2
|
||||
|
||||
TEST(Imgproc_IntelligentScissorsMB, grayscale)
|
||||
{
|
||||
segmentation::IntelligentScissorsMB tool;
|
||||
|
||||
Mat image = getTestImageGray();
|
||||
tool.applyImage(image);
|
||||
|
||||
Point source_point(275, 63);
|
||||
tool.buildMap(source_point);
|
||||
|
||||
Point target_point(413, 155);
|
||||
std::vector<Point> pts;
|
||||
tool.getContour(target_point, pts);
|
||||
|
||||
size_t gold = 206;
|
||||
EXPECT_GE(pts.size(), gold - PTS_SIZE_EPS);
|
||||
EXPECT_LE(pts.size(), gold + PTS_SIZE_EPS);
|
||||
show(image, pts);
|
||||
}
|
||||
|
||||
TEST(Imgproc_IntelligentScissorsMB, check_features_grayscale_1_0_0_zerro_crossing_with_limit)
|
||||
{
|
||||
segmentation::IntelligentScissorsMB tool;
|
||||
tool.setEdgeFeatureZeroCrossingParameters(64);
|
||||
tool.setWeights(1.0f, 0.0f, 0.0f);
|
||||
|
||||
Mat image = getTestImageGray();
|
||||
tool.applyImage(image);
|
||||
|
||||
Point source_point(275, 63);
|
||||
tool.buildMap(source_point);
|
||||
|
||||
Point target_point(413, 155);
|
||||
std::vector<Point> pts;
|
||||
tool.getContour(target_point, pts);
|
||||
|
||||
size_t gold = 207;
|
||||
EXPECT_GE(pts.size(), gold - PTS_SIZE_EPS);
|
||||
EXPECT_LE(pts.size(), gold + PTS_SIZE_EPS);
|
||||
show(image, pts);
|
||||
}
|
||||
|
||||
TEST(Imgproc_IntelligentScissorsMB, check_features_grayscale_1_0_0_canny)
|
||||
{
|
||||
segmentation::IntelligentScissorsMB tool;
|
||||
tool.setEdgeFeatureCannyParameters(50, 100);
|
||||
tool.setWeights(1.0f, 0.0f, 0.0f);
|
||||
|
||||
Mat image = getTestImageGray();
|
||||
tool.applyImage(image);
|
||||
|
||||
Point source_point(275, 63);
|
||||
tool.buildMap(source_point);
|
||||
|
||||
Point target_point(413, 155);
|
||||
std::vector<Point> pts;
|
||||
tool.getContour(target_point, pts);
|
||||
|
||||
size_t gold = 201;
|
||||
EXPECT_GE(pts.size(), gold - PTS_SIZE_EPS);
|
||||
EXPECT_LE(pts.size(), gold + PTS_SIZE_EPS);
|
||||
show(image, pts);
|
||||
}
|
||||
|
||||
TEST(Imgproc_IntelligentScissorsMB, check_features_grayscale_0_1_0)
|
||||
{
|
||||
segmentation::IntelligentScissorsMB tool;
|
||||
tool.setWeights(0.0f, 1.0f, 0.0f);
|
||||
|
||||
Mat image = getTestImageGray();
|
||||
tool.applyImage(image);
|
||||
|
||||
Point source_point(275, 63);
|
||||
tool.buildMap(source_point);
|
||||
|
||||
Point target_point(413, 155);
|
||||
std::vector<Point> pts;
|
||||
tool.getContour(target_point, pts);
|
||||
|
||||
size_t gold = 166;
|
||||
EXPECT_GE(pts.size(), gold - PTS_SIZE_EPS);
|
||||
EXPECT_LE(pts.size(), gold + PTS_SIZE_EPS);
|
||||
show(image, pts);
|
||||
}
|
||||
|
||||
TEST(Imgproc_IntelligentScissorsMB, check_features_grayscale_0_0_1)
|
||||
{
|
||||
segmentation::IntelligentScissorsMB tool;
|
||||
tool.setWeights(0.0f, 0.0f, 1.0f);
|
||||
|
||||
Mat image = getTestImageGray();
|
||||
tool.applyImage(image);
|
||||
|
||||
Point source_point(275, 63);
|
||||
tool.buildMap(source_point);
|
||||
|
||||
Point target_point(413, 155);
|
||||
std::vector<Point> pts;
|
||||
tool.getContour(target_point, pts);
|
||||
|
||||
size_t gold = 197;
|
||||
EXPECT_GE(pts.size(), gold - PTS_SIZE_EPS);
|
||||
EXPECT_LE(pts.size(), gold + PTS_SIZE_EPS);
|
||||
show(image, pts);
|
||||
}
|
||||
|
||||
TEST(Imgproc_IntelligentScissorsMB, color)
|
||||
{
|
||||
segmentation::IntelligentScissorsMB tool;
|
||||
|
||||
Mat image = getTestImageColor();
|
||||
tool.applyImage(image);
|
||||
|
||||
Point source_point(275, 63);
|
||||
tool.buildMap(source_point);
|
||||
|
||||
Point target_point(413, 155);
|
||||
std::vector<Point> pts;
|
||||
tool.getContour(target_point, pts);
|
||||
|
||||
size_t gold = 205;
|
||||
EXPECT_GE(pts.size(), gold - PTS_SIZE_EPS);
|
||||
EXPECT_LE(pts.size(), gold + PTS_SIZE_EPS);
|
||||
show(image, pts);
|
||||
}
|
||||
|
||||
TEST(Imgproc_IntelligentScissorsMB, color_canny)
|
||||
{
|
||||
segmentation::IntelligentScissorsMB tool;
|
||||
tool.setEdgeFeatureCannyParameters(32, 100);
|
||||
|
||||
Mat image = getTestImageColor();
|
||||
tool.applyImage(image);
|
||||
|
||||
Point source_point(275, 63);
|
||||
tool.buildMap(source_point);
|
||||
|
||||
Point target_point(413, 155);
|
||||
std::vector<Point> pts;
|
||||
tool.getContour(target_point, pts);
|
||||
|
||||
size_t gold = 200;
|
||||
EXPECT_GE(pts.size(), gold - PTS_SIZE_EPS);
|
||||
EXPECT_LE(pts.size(), gold + PTS_SIZE_EPS);
|
||||
show(image, pts);
|
||||
}
|
||||
|
||||
|
||||
TEST(Imgproc_IntelligentScissorsMB, color_custom_features_invalid)
|
||||
{
|
||||
segmentation::IntelligentScissorsMB tool;
|
||||
ASSERT_ANY_THROW(tool.applyImageFeatures(noArray(), noArray(), noArray()));
|
||||
}
|
||||
|
||||
TEST(Imgproc_IntelligentScissorsMB, color_custom_features_edge)
|
||||
{
|
||||
segmentation::IntelligentScissorsMB tool;
|
||||
|
||||
Mat image = getTestImageColor();
|
||||
|
||||
Mat canny_edges;
|
||||
Canny(image, canny_edges, 32, 100, 5);
|
||||
Mat binary_edge_feature;
|
||||
cv::threshold(canny_edges, binary_edge_feature, 254, 1, THRESH_BINARY_INV);
|
||||
tool.applyImageFeatures(binary_edge_feature, noArray(), noArray(), image);
|
||||
|
||||
Point source_point(275, 63);
|
||||
tool.buildMap(source_point);
|
||||
|
||||
Point target_point(413, 155);
|
||||
std::vector<Point> pts;
|
||||
tool.getContour(target_point, pts);
|
||||
|
||||
size_t gold = 201;
|
||||
EXPECT_GE(pts.size(), gold - PTS_SIZE_EPS);
|
||||
EXPECT_LE(pts.size(), gold + PTS_SIZE_EPS);
|
||||
show(image, pts);
|
||||
}
|
||||
|
||||
TEST(Imgproc_IntelligentScissorsMB, color_custom_features_all)
|
||||
{
|
||||
segmentation::IntelligentScissorsMB tool;
|
||||
|
||||
tool.setWeights(0.9f, 0.0f, 0.1f);
|
||||
|
||||
Mat image = getTestImageColor();
|
||||
|
||||
Mat canny_edges;
|
||||
Canny(image, canny_edges, 50, 100, 5);
|
||||
Mat binary_edge_feature; // 0, 1 values
|
||||
cv::threshold(canny_edges, binary_edge_feature, 254, 1, THRESH_BINARY_INV);
|
||||
|
||||
Mat_<Point2f> gradient_direction(image.size(), Point2f(0, 0)); // normalized
|
||||
Mat_<float> gradient_magnitude(image.size(), 0); // cost function
|
||||
tool.applyImageFeatures(binary_edge_feature, gradient_direction, gradient_magnitude);
|
||||
|
||||
Point source_point(275, 63);
|
||||
tool.buildMap(source_point);
|
||||
|
||||
Point target_point(413, 155);
|
||||
std::vector<Point> pts;
|
||||
tool.getContour(target_point, pts);
|
||||
|
||||
size_t gold = 201;
|
||||
EXPECT_GE(pts.size(), gold - PTS_SIZE_EPS);
|
||||
EXPECT_LE(pts.size(), gold + PTS_SIZE_EPS);
|
||||
show(image, pts);
|
||||
}
|
||||
|
||||
TEST(Imgproc_IntelligentScissorsMB, color_custom_features_edge_magnitude)
|
||||
{
|
||||
segmentation::IntelligentScissorsMB tool;
|
||||
|
||||
tool.setWeights(0.9f, 0.0f, 0.1f);
|
||||
|
||||
Mat image = getTestImageColor();
|
||||
|
||||
Mat canny_edges;
|
||||
Canny(image, canny_edges, 50, 100, 5);
|
||||
Mat binary_edge_feature; // 0, 1 values
|
||||
cv::threshold(canny_edges, binary_edge_feature, 254, 1, THRESH_BINARY_INV);
|
||||
|
||||
Mat_<float> gradient_magnitude(image.size(), 0); // cost function
|
||||
tool.applyImageFeatures(binary_edge_feature, noArray(), gradient_magnitude);
|
||||
|
||||
Point source_point(275, 63);
|
||||
tool.buildMap(source_point);
|
||||
|
||||
Point target_point(413, 155);
|
||||
std::vector<Point> pts;
|
||||
tool.getContour(target_point, pts);
|
||||
|
||||
size_t gold = 201;
|
||||
EXPECT_GE(pts.size(), gold - PTS_SIZE_EPS);
|
||||
EXPECT_LE(pts.size(), gold + PTS_SIZE_EPS);
|
||||
show(image, pts);
|
||||
}
|
||||
|
||||
|
||||
}} // namespace
|
||||
260
3rdparty/opencv-4.5.4/modules/imgproc/test/test_intersectconvexconvex.cpp
vendored
Normal file
260
3rdparty/opencv-4.5.4/modules/imgproc/test/test_intersectconvexconvex.cpp
vendored
Normal file
@@ -0,0 +1,260 @@
|
||||
// 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"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
|
||||
TEST(Imgproc_IntersectConvexConvex, no_intersection)
|
||||
{
|
||||
std::vector<cv::Point> convex1;
|
||||
convex1.push_back(cv::Point(290, 126));
|
||||
convex1.push_back(cv::Point(284, 132));
|
||||
convex1.push_back(cv::Point(281, 133));
|
||||
convex1.push_back(cv::Point(256, 124));
|
||||
convex1.push_back(cv::Point(249, 116));
|
||||
convex1.push_back(cv::Point(234, 91));
|
||||
convex1.push_back(cv::Point(232, 86));
|
||||
convex1.push_back(cv::Point(232, 79));
|
||||
convex1.push_back(cv::Point(251, 69));
|
||||
convex1.push_back(cv::Point(257, 68));
|
||||
convex1.push_back(cv::Point(297, 85));
|
||||
convex1.push_back(cv::Point(299, 87));
|
||||
|
||||
std::vector<cv::Point> convex2;
|
||||
convex2.push_back(cv::Point(192, 236));
|
||||
convex2.push_back(cv::Point(190, 245));
|
||||
convex2.push_back(cv::Point(177, 260));
|
||||
convex2.push_back(cv::Point(154, 271));
|
||||
convex2.push_back(cv::Point(142, 270));
|
||||
convex2.push_back(cv::Point(135, 263));
|
||||
convex2.push_back(cv::Point(131, 254));
|
||||
convex2.push_back(cv::Point(132, 240));
|
||||
convex2.push_back(cv::Point(172, 213));
|
||||
convex2.push_back(cv::Point(176, 216));
|
||||
|
||||
std::vector<cv::Point> intersection;
|
||||
float area = cv::intersectConvexConvex(convex1, convex2, intersection);
|
||||
|
||||
EXPECT_TRUE(intersection.empty());
|
||||
EXPECT_NEAR(area, 0, std::numeric_limits<float>::epsilon());
|
||||
}
|
||||
|
||||
|
||||
TEST(Imgproc_IntersectConvexConvex, no_intersection_with_1_vertex_on_edge_1)
|
||||
{
|
||||
std::vector<cv::Point> convex1;
|
||||
convex1.push_back(cv::Point(0,0));
|
||||
convex1.push_back(cv::Point(740, 0));
|
||||
convex1.push_back(cv::Point(740, 540));
|
||||
convex1.push_back(cv::Point(0, 540));
|
||||
|
||||
std::vector<cv::Point> convex2;
|
||||
convex2.push_back(cv::Point(0, 210));
|
||||
convex2.push_back(cv::Point(-30, 210));
|
||||
convex2.push_back(cv::Point(-37, 170));
|
||||
convex2.push_back(cv::Point(-7, 172));
|
||||
|
||||
std::vector<cv::Point> intersection;
|
||||
float area = cv::intersectConvexConvex(convex1, convex2, intersection);
|
||||
|
||||
EXPECT_TRUE(intersection.empty());
|
||||
EXPECT_NEAR(area, 0, std::numeric_limits<float>::epsilon());
|
||||
}
|
||||
|
||||
|
||||
TEST(Imgproc_IntersectConvexConvex, no_intersection_with_1_vertex_on_edge_2)
|
||||
{
|
||||
std::vector<cv::Point> convex1;
|
||||
convex1.push_back(cv::Point(0,0));
|
||||
convex1.push_back(cv::Point(740, 0));
|
||||
convex1.push_back(cv::Point(740, 540));
|
||||
convex1.push_back(cv::Point(0, 540));
|
||||
|
||||
std::vector<cv::Point> convex2;
|
||||
convex2.push_back(cv::Point(740, 210));
|
||||
convex2.push_back(cv::Point(750, 100));
|
||||
convex2.push_back(cv::Point(790, 250));
|
||||
convex2.push_back(cv::Point(800, 500));
|
||||
|
||||
std::vector<cv::Point> intersection;
|
||||
float area = cv::intersectConvexConvex(convex1, convex2, intersection);
|
||||
|
||||
EXPECT_TRUE(intersection.empty());
|
||||
EXPECT_NEAR(area, 0, std::numeric_limits<float>::epsilon());
|
||||
}
|
||||
|
||||
|
||||
TEST(Imgproc_IntersectConvexConvex, intersection_with_1_vertex_on_edge)
|
||||
{
|
||||
std::vector<cv::Point> convex1;
|
||||
convex1.push_back(cv::Point(0,0));
|
||||
convex1.push_back(cv::Point(740, 0));
|
||||
convex1.push_back(cv::Point(740, 540));
|
||||
convex1.push_back(cv::Point(0, 540));
|
||||
|
||||
std::vector<cv::Point> convex2;
|
||||
convex2.push_back(cv::Point(30, 210));
|
||||
convex2.push_back(cv::Point(0,210));
|
||||
convex2.push_back(cv::Point(7, 172));
|
||||
convex2.push_back(cv::Point(37, 170));
|
||||
|
||||
std::vector<cv::Point> intersection;
|
||||
float area = cv::intersectConvexConvex(convex1, convex2, intersection);
|
||||
|
||||
std::vector<cv::Point> expected_intersection;
|
||||
expected_intersection.push_back(cv::Point(0, 210));
|
||||
expected_intersection.push_back(cv::Point(7, 172));
|
||||
expected_intersection.push_back(cv::Point(37, 170));
|
||||
expected_intersection.push_back(cv::Point(30, 210));
|
||||
|
||||
EXPECT_EQ(intersection, expected_intersection);
|
||||
EXPECT_NEAR(area, 1163, std::numeric_limits<float>::epsilon());
|
||||
}
|
||||
|
||||
|
||||
TEST(Imgproc_IntersectConvexConvex, intersection_with_2_vertices_on_edge)
|
||||
{
|
||||
std::vector<cv::Point> convex1;
|
||||
convex1.push_back(cv::Point(0,0));
|
||||
convex1.push_back(cv::Point(740, 0));
|
||||
convex1.push_back(cv::Point(740, 540));
|
||||
convex1.push_back(cv::Point(0, 540));
|
||||
|
||||
std::vector<cv::Point> convex2;
|
||||
convex2.push_back(cv::Point(30, 210));
|
||||
convex2.push_back(cv::Point(37, 170));
|
||||
convex2.push_back(cv::Point(0,210));
|
||||
convex2.push_back(cv::Point(0, 300));
|
||||
|
||||
std::vector<cv::Point> intersection;
|
||||
float area = cv::intersectConvexConvex(convex1, convex2, intersection);
|
||||
|
||||
std::vector<cv::Point> expected_intersection;
|
||||
expected_intersection.push_back(cv::Point(0, 300));
|
||||
expected_intersection.push_back(cv::Point(0, 210));
|
||||
expected_intersection.push_back(cv::Point(37, 170));
|
||||
expected_intersection.push_back(cv::Point(30, 210));
|
||||
|
||||
EXPECT_EQ(intersection, expected_intersection);
|
||||
EXPECT_NEAR(area, 1950, std::numeric_limits<float>::epsilon());
|
||||
}
|
||||
|
||||
|
||||
TEST(Imgproc_IntersectConvexConvex, intersection_1)
|
||||
{
|
||||
std::vector<cv::Point> convex1;
|
||||
convex1.push_back(cv::Point(0,0));
|
||||
convex1.push_back(cv::Point(740, 0));
|
||||
convex1.push_back(cv::Point(740, 540));
|
||||
convex1.push_back(cv::Point(0, 540));
|
||||
|
||||
std::vector<cv::Point> convex2;
|
||||
convex2.push_back(cv::Point(20,210));
|
||||
convex2.push_back(cv::Point(30, 210));
|
||||
convex2.push_back(cv::Point(37, 170));
|
||||
convex2.push_back(cv::Point(7, 172));
|
||||
|
||||
std::vector<cv::Point> intersection;
|
||||
float area = cv::intersectConvexConvex(convex1, convex2, intersection);
|
||||
|
||||
std::vector<cv::Point> expected_intersection;
|
||||
expected_intersection.push_back(cv::Point(7, 172));
|
||||
expected_intersection.push_back(cv::Point(37, 170));
|
||||
expected_intersection.push_back(cv::Point(30, 210));
|
||||
expected_intersection.push_back(cv::Point(20, 210));
|
||||
|
||||
EXPECT_EQ(intersection, expected_intersection);
|
||||
EXPECT_NEAR(area, 783, std::numeric_limits<float>::epsilon());
|
||||
}
|
||||
|
||||
|
||||
TEST(Imgproc_IntersectConvexConvex, intersection_2)
|
||||
{
|
||||
std::vector<cv::Point> convex1;
|
||||
convex1.push_back(cv::Point(0,0));
|
||||
convex1.push_back(cv::Point(740, 0));
|
||||
convex1.push_back(cv::Point(740, 540));
|
||||
convex1.push_back(cv::Point(0, 540));
|
||||
|
||||
std::vector<cv::Point> convex2;
|
||||
convex2.push_back(cv::Point(-2,210));
|
||||
convex2.push_back(cv::Point(-5, 300));
|
||||
convex2.push_back(cv::Point(37, 150));
|
||||
convex2.push_back(cv::Point(7, 172));
|
||||
|
||||
std::vector<cv::Point> intersection;
|
||||
float area = cv::intersectConvexConvex(convex1, convex2, intersection);
|
||||
|
||||
std::vector<cv::Point> expected_intersection;
|
||||
expected_intersection.push_back(cv::Point(0, 202));
|
||||
expected_intersection.push_back(cv::Point(7, 172));
|
||||
expected_intersection.push_back(cv::Point(37, 150));
|
||||
expected_intersection.push_back(cv::Point(0, 282));
|
||||
|
||||
EXPECT_EQ(intersection, expected_intersection);
|
||||
EXPECT_NEAR(area, 1857.19836425781, std::numeric_limits<float>::epsilon());
|
||||
}
|
||||
|
||||
|
||||
TEST(Imgproc_IntersectConvexConvex, intersection_3)
|
||||
{
|
||||
std::vector<cv::Point> convex1;
|
||||
convex1.push_back(cv::Point(15, 0));
|
||||
convex1.push_back(cv::Point(740, 0));
|
||||
convex1.push_back(cv::Point(740, 540));
|
||||
convex1.push_back(cv::Point(15, 540));
|
||||
|
||||
std::vector<cv::Point> convex2;
|
||||
convex2.push_back(cv::Point(0,210));
|
||||
convex2.push_back(cv::Point(30, 210));
|
||||
convex2.push_back(cv::Point(37, 170));
|
||||
convex2.push_back(cv::Point(7, 172));
|
||||
|
||||
std::vector<cv::Point> intersection;
|
||||
float area = cv::intersectConvexConvex(convex1, convex2, intersection);
|
||||
|
||||
std::vector<cv::Point> expected_intersection;
|
||||
expected_intersection.push_back(cv::Point(15, 171));
|
||||
expected_intersection.push_back(cv::Point(37, 170));
|
||||
expected_intersection.push_back(cv::Point(30, 210));
|
||||
expected_intersection.push_back(cv::Point(15, 210));
|
||||
|
||||
EXPECT_EQ(intersection, expected_intersection);
|
||||
|
||||
EXPECT_NEAR(area, 723.866760253906, std::numeric_limits<float>::epsilon());
|
||||
}
|
||||
|
||||
|
||||
TEST(Imgproc_IntersectConvexConvex, intersection_4)
|
||||
{
|
||||
std::vector<cv::Point> convex1;
|
||||
convex1.push_back(cv::Point(15, 0));
|
||||
convex1.push_back(cv::Point(740, 0));
|
||||
convex1.push_back(cv::Point(740, 540));
|
||||
convex1.push_back(cv::Point(15, 540));
|
||||
|
||||
std::vector<cv::Point> convex2;
|
||||
convex2.push_back(cv::Point(15, 0));
|
||||
convex2.push_back(cv::Point(740, 0));
|
||||
convex2.push_back(cv::Point(740, 540));
|
||||
convex2.push_back(cv::Point(15, 540));
|
||||
|
||||
std::vector<cv::Point> intersection;
|
||||
float area = cv::intersectConvexConvex(convex1, convex2, intersection);
|
||||
|
||||
std::vector<cv::Point> expected_intersection;
|
||||
expected_intersection.push_back(cv::Point(15, 0));
|
||||
expected_intersection.push_back(cv::Point(740, 0));
|
||||
expected_intersection.push_back(cv::Point(740, 540));
|
||||
expected_intersection.push_back(cv::Point(15, 540));
|
||||
|
||||
EXPECT_EQ(intersection, expected_intersection);
|
||||
EXPECT_NEAR(area, 391500, std::numeric_limits<float>::epsilon());
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
} // opencv_test
|
||||
411
3rdparty/opencv-4.5.4/modules/imgproc/test/test_intersection.cpp
vendored
Normal file
411
3rdparty/opencv-4.5.4/modules/imgproc/test/test_intersection.cpp
vendored
Normal file
@@ -0,0 +1,411 @@
|
||||
/*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) 2008-2011, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// @Authors
|
||||
// Nghia Ho, nghiaho12@yahoo.com
|
||||
//
|
||||
// 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 OpenCV Foundation 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 {
|
||||
|
||||
#define ACCURACY 0.00001
|
||||
|
||||
// See pics/intersection.png for the scenarios we are testing
|
||||
|
||||
// Test the following scenarios:
|
||||
// 1 - no intersection
|
||||
// 2 - partial intersection, rectangle translated
|
||||
// 3 - partial intersection, rectangle rotated 45 degree on the corner, forms a triangle intersection
|
||||
// 4 - full intersection, rectangles of same size directly on top of each other
|
||||
// 5 - partial intersection, rectangle on top rotated 45 degrees
|
||||
// 6 - partial intersection, rectangle on top of different size
|
||||
// 7 - full intersection, rectangle fully enclosed in the other
|
||||
// 8 - partial intersection, rectangle corner just touching. point contact
|
||||
// 9 - partial intersection. rectangle side by side, line contact
|
||||
|
||||
static void compare(const std::vector<Point2f>& test, const std::vector<Point2f>& target)
|
||||
{
|
||||
ASSERT_EQ(test.size(), target.size());
|
||||
ASSERT_TRUE(test.size() < 4 || isContourConvex(test));
|
||||
ASSERT_TRUE(target.size() < 4 || isContourConvex(target));
|
||||
for( size_t i = 0; i < test.size(); i++ )
|
||||
{
|
||||
double r = sqrt(normL2Sqr<double>(test[i] - target[i]));
|
||||
ASSERT_LT(r, ACCURACY);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Imgproc_RotatedRectangleIntersection, accuracy_1)
|
||||
{
|
||||
// no intersection
|
||||
RotatedRect rect1(Point2f(0, 0), Size2f(2, 2), 12.0f);
|
||||
RotatedRect rect2(Point2f(10, 10), Size2f(2, 2), 34.0f);
|
||||
|
||||
vector<Point2f> vertices;
|
||||
int ret = rotatedRectangleIntersection(rect1, rect2, vertices);
|
||||
|
||||
CV_Assert(ret == INTERSECT_NONE);
|
||||
CV_Assert(vertices.empty());
|
||||
}
|
||||
|
||||
TEST(Imgproc_RotatedRectangleIntersection, accuracy_2)
|
||||
{
|
||||
// partial intersection, rectangles translated
|
||||
RotatedRect rect1(Point2f(0, 0), Size2f(2, 2), 0.0f);
|
||||
RotatedRect rect2(Point2f(1, 1), Size2f(2, 2), 0.0f);
|
||||
|
||||
vector<Point2f> vertices;
|
||||
int ret = rotatedRectangleIntersection(rect1, rect2, vertices);
|
||||
|
||||
CV_Assert(ret == INTERSECT_PARTIAL);
|
||||
|
||||
vector<Point2f> targetVertices(4);
|
||||
targetVertices[0] = Point2f(1.0f, 0.0f);
|
||||
targetVertices[1] = Point2f(1.0f, 1.0f);
|
||||
targetVertices[2] = Point2f(0.0f, 1.0f);
|
||||
targetVertices[3] = Point2f(0.0f, 0.0f);
|
||||
compare(vertices, targetVertices);
|
||||
}
|
||||
|
||||
TEST(Imgproc_RotatedRectangleIntersection, accuracy_3)
|
||||
{
|
||||
// partial intersection, rectangles rotated 45 degree on the corner, forms a triangle intersection
|
||||
RotatedRect rect1(Point2f(0, 0), Size2f(2, 2), 0.0f);
|
||||
RotatedRect rect2(Point2f(1, 1), Size2f(sqrt(2.0f), 20), 45.0f);
|
||||
|
||||
vector<Point2f> vertices;
|
||||
int ret = rotatedRectangleIntersection(rect1, rect2, vertices);
|
||||
|
||||
CV_Assert(ret == INTERSECT_PARTIAL);
|
||||
|
||||
vector<Point2f> targetVertices(3);
|
||||
targetVertices[0] = Point2f(1.0f, 0.0f);
|
||||
targetVertices[1] = Point2f(1.0f, 1.0f);
|
||||
targetVertices[2] = Point2f(0.0f, 1.0f);
|
||||
compare(vertices, targetVertices);
|
||||
}
|
||||
|
||||
TEST(Imgproc_RotatedRectangleIntersection, accuracy_4)
|
||||
{
|
||||
// full intersection, rectangles of same size directly on top of each other
|
||||
RotatedRect rect1(Point2f(0, 0), Size2f(2, 2), 0.0f);
|
||||
RotatedRect rect2(Point2f(0, 0), Size2f(2, 2), 0.0f);
|
||||
|
||||
vector<Point2f> vertices;
|
||||
int ret = rotatedRectangleIntersection(rect1, rect2, vertices);
|
||||
|
||||
CV_Assert(ret == INTERSECT_FULL);
|
||||
|
||||
vector<Point2f> targetVertices(4);
|
||||
targetVertices[0] = Point2f(-1.0f, 1.0f);
|
||||
targetVertices[1] = Point2f(-1.0f, -1.0f);
|
||||
targetVertices[2] = Point2f(1.0f, -1.0f);
|
||||
targetVertices[3] = Point2f(1.0f, 1.0f);
|
||||
compare(vertices, targetVertices);
|
||||
}
|
||||
|
||||
TEST(Imgproc_RotatedRectangleIntersection, accuracy_5)
|
||||
{
|
||||
// partial intersection, rectangle on top rotated 45 degrees
|
||||
RotatedRect rect1(Point2f(0, 0), Size2f(2, 2), 0.0f);
|
||||
RotatedRect rect2(Point2f(0, 0), Size2f(2, 2), 45.0f);
|
||||
|
||||
vector<Point2f> vertices;
|
||||
int ret = rotatedRectangleIntersection(rect1, rect2, vertices);
|
||||
|
||||
CV_Assert(ret == INTERSECT_PARTIAL);
|
||||
|
||||
vector<Point2f> targetVertices(8);
|
||||
targetVertices[0] = Point2f(-1.0f, -0.414214f);
|
||||
targetVertices[1] = Point2f(-0.414214f, -1.0f);
|
||||
targetVertices[2] = Point2f(0.414214f, -1.0f);
|
||||
targetVertices[3] = Point2f(1.0f, -0.414214f);
|
||||
targetVertices[4] = Point2f(1.0f, 0.414214f);
|
||||
targetVertices[5] = Point2f(0.414214f, 1.0f);
|
||||
targetVertices[6] = Point2f(-0.414214f, 1.0f);
|
||||
targetVertices[7] = Point2f(-1.0f, 0.414214f);
|
||||
compare(vertices, targetVertices);
|
||||
}
|
||||
|
||||
TEST(Imgproc_RotatedRectangleIntersection, accuracy_6)
|
||||
{
|
||||
// 6 - partial intersection, rectangle on top of different size
|
||||
RotatedRect rect1(Point2f(0, 0), Size2f(2, 2), 0.0f);
|
||||
RotatedRect rect2(Point2f(0, 0), Size2f(2, 10), 0.0f);
|
||||
|
||||
vector<Point2f> vertices;
|
||||
int ret = rotatedRectangleIntersection(rect1, rect2, vertices);
|
||||
|
||||
CV_Assert(ret == INTERSECT_PARTIAL);
|
||||
|
||||
vector<Point2f> targetVertices(4);
|
||||
targetVertices[0] = Point2f(-1.0f, -1.0f);
|
||||
targetVertices[1] = Point2f(1.0f, -1.0f);
|
||||
targetVertices[2] = Point2f(1.0f, 1.0f);
|
||||
targetVertices[3] = Point2f(-1.0f, 1.0f);
|
||||
compare(vertices, targetVertices);
|
||||
}
|
||||
|
||||
TEST(Imgproc_RotatedRectangleIntersection, accuracy_7)
|
||||
{
|
||||
// full intersection, rectangle fully enclosed in the other
|
||||
RotatedRect rect1(Point2f(0, 0), Size2f(12.34f, 56.78f), 0.0f);
|
||||
RotatedRect rect2(Point2f(0, 0), Size2f(2, 2), 0.0f);
|
||||
|
||||
vector<Point2f> vertices;
|
||||
int ret = rotatedRectangleIntersection(rect1, rect2, vertices);
|
||||
|
||||
CV_Assert(ret == INTERSECT_FULL);
|
||||
|
||||
vector<Point2f> targetVertices(4);
|
||||
targetVertices[0] = Point2f(-1.0f, 1.0f);
|
||||
targetVertices[1] = Point2f(-1.0f, -1.0f);
|
||||
targetVertices[2] = Point2f(1.0f, -1.0f);
|
||||
targetVertices[3] = Point2f(1.0f, 1.0f);
|
||||
compare(vertices, targetVertices);
|
||||
}
|
||||
|
||||
TEST(Imgproc_RotatedRectangleIntersection, accuracy_8)
|
||||
{
|
||||
// intersection by a single vertex
|
||||
RotatedRect rect1(Point2f(0, 0), Size2f(2, 2), 0.0f);
|
||||
RotatedRect rect2(Point2f(2, 2), Size2f(2, 2), 0.0f);
|
||||
|
||||
vector<Point2f> vertices;
|
||||
int ret = rotatedRectangleIntersection(rect1, rect2, vertices);
|
||||
|
||||
CV_Assert(ret == INTERSECT_PARTIAL);
|
||||
compare(vertices, vector<Point2f>(1, Point2f(1.0f, 1.0f)));
|
||||
}
|
||||
|
||||
TEST(Imgproc_RotatedRectangleIntersection, accuracy_9)
|
||||
{
|
||||
// full intersection, rectangle fully enclosed in the other
|
||||
RotatedRect rect1(Point2f(0, 0), Size2f(2, 2), 0.0f);
|
||||
RotatedRect rect2(Point2f(2, 0), Size2f(2, 123.45f), 0.0f);
|
||||
|
||||
vector<Point2f> vertices;
|
||||
int ret = rotatedRectangleIntersection(rect1, rect2, vertices);
|
||||
|
||||
CV_Assert(ret == INTERSECT_PARTIAL);
|
||||
|
||||
vector<Point2f> targetVertices(2);
|
||||
targetVertices[0] = Point2f(1.0f, -1.0f);
|
||||
targetVertices[1] = Point2f(1.0f, 1.0f);
|
||||
compare(vertices, targetVertices);
|
||||
}
|
||||
|
||||
TEST(Imgproc_RotatedRectangleIntersection, accuracy_10)
|
||||
{
|
||||
// three points of rect2 are inside rect1.
|
||||
RotatedRect rect1(Point2f(0, 0), Size2f(2, 2), 0.0f);
|
||||
RotatedRect rect2(Point2f(0, 0.5), Size2f(1, 1), 45.0f);
|
||||
|
||||
vector<Point2f> vertices;
|
||||
int ret = rotatedRectangleIntersection(rect1, rect2, vertices);
|
||||
|
||||
CV_Assert(ret == INTERSECT_PARTIAL);
|
||||
|
||||
vector<Point2f> targetVertices(5);
|
||||
targetVertices[0] = Point2f(0.207107f, 1.0f);
|
||||
targetVertices[1] = Point2f(-0.207107f, 1.0f);
|
||||
targetVertices[2] = Point2f(-0.707107f, 0.5f);
|
||||
targetVertices[3] = Point2f(0.0f, -0.207107f);
|
||||
targetVertices[4] = Point2f(0.707107f, 0.5f);
|
||||
compare(vertices, targetVertices);
|
||||
}
|
||||
|
||||
TEST(Imgproc_RotatedRectangleIntersection, accuracy_11)
|
||||
{
|
||||
RotatedRect rect1(Point2f(0, 0), Size2f(4, 2), 0.0f);
|
||||
RotatedRect rect2(Point2f(0, 0), Size2f(2, 2), -45.0f);
|
||||
|
||||
vector<Point2f> vertices;
|
||||
int ret = rotatedRectangleIntersection(rect1, rect2, vertices);
|
||||
|
||||
CV_Assert(ret == INTERSECT_PARTIAL);
|
||||
|
||||
vector<Point2f> targetVertices(6);
|
||||
targetVertices[0] = Point2f(-0.414214f, -1.0f);
|
||||
targetVertices[1] = Point2f(0.414213f, -1.0f);
|
||||
targetVertices[2] = Point2f(1.41421f, 0.0f);
|
||||
targetVertices[3] = Point2f(0.414214f, 1.0f);
|
||||
targetVertices[4] = Point2f(-0.414213f, 1.0f);
|
||||
targetVertices[5] = Point2f(-1.41421f, 0.0f);
|
||||
compare(vertices, targetVertices);
|
||||
}
|
||||
|
||||
TEST(Imgproc_RotatedRectangleIntersection, accuracy_12)
|
||||
{
|
||||
RotatedRect rect1(Point2f(0, 0), Size2f(2, 2), 0.0f);
|
||||
RotatedRect rect2(Point2f(0, 1), Size2f(1, 1), 0.0f);
|
||||
|
||||
vector<Point2f> vertices;
|
||||
int ret = rotatedRectangleIntersection(rect1, rect2, vertices);
|
||||
|
||||
CV_Assert(ret == INTERSECT_PARTIAL);
|
||||
|
||||
vector<Point2f> targetVertices(4);
|
||||
targetVertices[0] = Point2f(-0.5f, 1.0f);
|
||||
targetVertices[1] = Point2f(-0.5f, 0.5f);
|
||||
targetVertices[2] = Point2f(0.5f, 0.5f);
|
||||
targetVertices[3] = Point2f(0.5f, 1.0f);
|
||||
compare(vertices, targetVertices);
|
||||
}
|
||||
|
||||
TEST(Imgproc_RotatedRectangleIntersection, accuracy_13)
|
||||
{
|
||||
RotatedRect rect1(Point2f(0, 0), Size2f(1, 3), 0.0f);
|
||||
RotatedRect rect2(Point2f(0, 1), Size2f(3, 1), 0.0f);
|
||||
|
||||
vector<Point2f> vertices;
|
||||
int ret = rotatedRectangleIntersection(rect1, rect2, vertices);
|
||||
|
||||
CV_Assert(ret == INTERSECT_PARTIAL);
|
||||
|
||||
vector<Point2f> targetVertices(4);
|
||||
targetVertices[0] = Point2f(-0.5f, 0.5f);
|
||||
targetVertices[1] = Point2f(0.5f, 0.5f);
|
||||
targetVertices[2] = Point2f(0.5f, 1.5f);
|
||||
targetVertices[3] = Point2f(-0.5f, 1.5f);
|
||||
compare(vertices, targetVertices);
|
||||
}
|
||||
|
||||
TEST(Imgproc_RotatedRectangleIntersection, accuracy_14)
|
||||
{
|
||||
const int kNumTests = 100;
|
||||
const float kWidth = 5;
|
||||
const float kHeight = 5;
|
||||
RotatedRect rects[2];
|
||||
std::vector<Point2f> inter;
|
||||
cv::RNG& rng = cv::theRNG();
|
||||
for (int i = 0; i < kNumTests; ++i)
|
||||
{
|
||||
for (int j = 0; j < 2; ++j)
|
||||
{
|
||||
rects[j].center = Point2f(rng.uniform(0.0f, kWidth), rng.uniform(0.0f, kHeight));
|
||||
rects[j].size = Size2f(rng.uniform(1.0f, kWidth), rng.uniform(1.0f, kHeight));
|
||||
rects[j].angle = rng.uniform(0.0f, 360.0f);
|
||||
}
|
||||
int res = rotatedRectangleIntersection(rects[0], rects[1], inter);
|
||||
EXPECT_TRUE(res == INTERSECT_NONE || res == INTERSECT_PARTIAL || res == INTERSECT_FULL) << res;
|
||||
ASSERT_TRUE(inter.size() < 4 || isContourConvex(inter)) << inter;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Imgproc_RotatedRectangleIntersection, regression_12221_1)
|
||||
{
|
||||
RotatedRect r1(
|
||||
Point2f(259.65081787109375, 51.58895492553711),
|
||||
Size2f(5487.8779296875, 233.8921661376953),
|
||||
-29.488616943359375);
|
||||
RotatedRect r2(
|
||||
Point2f(293.70465087890625, 112.10154724121094),
|
||||
Size2f(5487.8896484375, 234.87368774414062),
|
||||
-31.27001953125);
|
||||
|
||||
std::vector<Point2f> intersections;
|
||||
int interType = cv::rotatedRectangleIntersection(r1, r2, intersections);
|
||||
EXPECT_EQ(INTERSECT_PARTIAL, interType);
|
||||
EXPECT_LE(intersections.size(), (size_t)8);
|
||||
}
|
||||
|
||||
TEST(Imgproc_RotatedRectangleIntersection, regression_12221_2)
|
||||
{
|
||||
RotatedRect r1(
|
||||
Point2f(239.78500366210938, 515.72021484375),
|
||||
Size2f(70.23420715332031, 39.74684524536133),
|
||||
-42.86162567138672);
|
||||
RotatedRect r2(
|
||||
Point2f(242.4205322265625, 510.1195373535156),
|
||||
Size2f(66.85948944091797, 61.46455383300781),
|
||||
-9.840961456298828);
|
||||
|
||||
std::vector<Point2f> intersections;
|
||||
int interType = cv::rotatedRectangleIntersection(r1, r2, intersections);
|
||||
EXPECT_EQ(INTERSECT_PARTIAL, interType);
|
||||
EXPECT_LE(intersections.size(), (size_t)8);
|
||||
}
|
||||
|
||||
TEST(Imgproc_RotatedRectangleIntersection, regression_18520)
|
||||
{
|
||||
RotatedRect rr_empty(
|
||||
Point2f(2, 2),
|
||||
Size2f(0, 0), // empty
|
||||
0);
|
||||
RotatedRect rr(
|
||||
Point2f(50, 50),
|
||||
Size2f(4, 4),
|
||||
0);
|
||||
|
||||
{
|
||||
std::vector<Point2f> intersections;
|
||||
int interType = cv::rotatedRectangleIntersection(rr_empty, rr, intersections);
|
||||
EXPECT_EQ(INTERSECT_NONE, interType) << "rr_empty, rr";
|
||||
EXPECT_EQ((size_t)0, intersections.size()) << "rr_empty, rr";
|
||||
}
|
||||
{
|
||||
std::vector<Point2f> intersections;
|
||||
int interType = cv::rotatedRectangleIntersection(rr, rr_empty, intersections);
|
||||
EXPECT_EQ(INTERSECT_NONE, interType) << "rr, rr_empty";
|
||||
EXPECT_EQ((size_t)0, intersections.size()) << "rr, rr_empty";
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Imgproc_RotatedRectangleIntersection, regression_19824)
|
||||
{
|
||||
RotatedRect r1(
|
||||
Point2f(246805.033f, 4002326.94f),
|
||||
Size2f(26.40587f, 6.20026f),
|
||||
-62.10156f);
|
||||
RotatedRect r2(
|
||||
Point2f(246805.122f, 4002326.59f),
|
||||
Size2f(27.4821f, 8.5361f),
|
||||
-56.33761f);
|
||||
|
||||
std::vector<Point2f> intersections;
|
||||
int interType = cv::rotatedRectangleIntersection(r1, r2, intersections);
|
||||
EXPECT_EQ(INTERSECT_PARTIAL, interType);
|
||||
EXPECT_LE(intersections.size(), (size_t)7);
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
405
3rdparty/opencv-4.5.4/modules/imgproc/test/test_lsd.cpp
vendored
Normal file
405
3rdparty/opencv-4.5.4/modules/imgproc/test/test_lsd.cpp
vendored
Normal file
@@ -0,0 +1,405 @@
|
||||
// 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"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
const Size img_size(640, 480);
|
||||
const int LSD_TEST_SEED = 0x134679;
|
||||
const int EPOCHS = 20;
|
||||
|
||||
class LSDBase : public testing::Test
|
||||
{
|
||||
public:
|
||||
LSDBase() { }
|
||||
|
||||
protected:
|
||||
Mat test_image;
|
||||
vector<Vec4f> lines;
|
||||
RNG rng;
|
||||
int passedtests;
|
||||
|
||||
void GenerateWhiteNoise(Mat& image);
|
||||
void GenerateConstColor(Mat& image);
|
||||
void GenerateLines(Mat& image, const unsigned int numLines);
|
||||
void GenerateRotatedRect(Mat& image);
|
||||
virtual void SetUp();
|
||||
};
|
||||
|
||||
class Imgproc_LSD_ADV: public LSDBase
|
||||
{
|
||||
public:
|
||||
Imgproc_LSD_ADV() { }
|
||||
protected:
|
||||
|
||||
};
|
||||
|
||||
class Imgproc_LSD_STD: public LSDBase
|
||||
{
|
||||
public:
|
||||
Imgproc_LSD_STD() { }
|
||||
protected:
|
||||
|
||||
};
|
||||
|
||||
class Imgproc_LSD_NONE: public LSDBase
|
||||
{
|
||||
public:
|
||||
Imgproc_LSD_NONE() { }
|
||||
protected:
|
||||
|
||||
};
|
||||
|
||||
class Imgproc_LSD_Common : public LSDBase
|
||||
{
|
||||
public:
|
||||
Imgproc_LSD_Common() { }
|
||||
protected:
|
||||
|
||||
};
|
||||
|
||||
void LSDBase::GenerateWhiteNoise(Mat& image)
|
||||
{
|
||||
image = Mat(img_size, CV_8UC1);
|
||||
rng.fill(image, RNG::UNIFORM, 0, 256);
|
||||
}
|
||||
|
||||
void LSDBase::GenerateConstColor(Mat& image)
|
||||
{
|
||||
image = Mat(img_size, CV_8UC1, Scalar::all(rng.uniform(0, 256)));
|
||||
}
|
||||
|
||||
void LSDBase::GenerateLines(Mat& image, const unsigned int numLines)
|
||||
{
|
||||
image = Mat(img_size, CV_8UC1, Scalar::all(rng.uniform(0, 128)));
|
||||
|
||||
for(unsigned int i = 0; i < numLines; ++i)
|
||||
{
|
||||
int y = rng.uniform(10, img_size.width - 10);
|
||||
Point p1(y, 10);
|
||||
Point p2(y, img_size.height - 10);
|
||||
line(image, p1, p2, Scalar(255), 3);
|
||||
}
|
||||
}
|
||||
|
||||
void LSDBase::GenerateRotatedRect(Mat& image)
|
||||
{
|
||||
image = Mat::zeros(img_size, CV_8UC1);
|
||||
|
||||
Point center(rng.uniform(img_size.width/4, img_size.width*3/4),
|
||||
rng.uniform(img_size.height/4, img_size.height*3/4));
|
||||
Size rect_size(rng.uniform(img_size.width/8, img_size.width/6),
|
||||
rng.uniform(img_size.height/8, img_size.height/6));
|
||||
float angle = rng.uniform(0.f, 360.f);
|
||||
|
||||
Point2f vertices[4];
|
||||
|
||||
RotatedRect rRect = RotatedRect(center, rect_size, angle);
|
||||
|
||||
rRect.points(vertices);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
line(image, vertices[i], vertices[(i + 1) % 4], Scalar(255), 3);
|
||||
}
|
||||
}
|
||||
|
||||
void LSDBase::SetUp()
|
||||
{
|
||||
lines.clear();
|
||||
test_image = Mat();
|
||||
rng = RNG(LSD_TEST_SEED);
|
||||
passedtests = 0;
|
||||
}
|
||||
|
||||
|
||||
TEST_F(Imgproc_LSD_ADV, whiteNoise)
|
||||
{
|
||||
for (int i = 0; i < EPOCHS; ++i)
|
||||
{
|
||||
GenerateWhiteNoise(test_image);
|
||||
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_ADV);
|
||||
detector->detect(test_image, lines);
|
||||
|
||||
if(40u >= lines.size()) ++passedtests;
|
||||
}
|
||||
ASSERT_EQ(EPOCHS, passedtests);
|
||||
}
|
||||
|
||||
TEST_F(Imgproc_LSD_ADV, constColor)
|
||||
{
|
||||
for (int i = 0; i < EPOCHS; ++i)
|
||||
{
|
||||
GenerateConstColor(test_image);
|
||||
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_ADV);
|
||||
detector->detect(test_image, lines);
|
||||
|
||||
if(0u == lines.size()) ++passedtests;
|
||||
}
|
||||
ASSERT_EQ(EPOCHS, passedtests);
|
||||
}
|
||||
|
||||
TEST_F(Imgproc_LSD_ADV, lines)
|
||||
{
|
||||
for (int i = 0; i < EPOCHS; ++i)
|
||||
{
|
||||
const unsigned int numOfLines = 1;
|
||||
GenerateLines(test_image, numOfLines);
|
||||
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_ADV);
|
||||
detector->detect(test_image, lines);
|
||||
|
||||
if(numOfLines * 2 == lines.size()) ++passedtests; // * 2 because of Gibbs effect
|
||||
}
|
||||
ASSERT_EQ(EPOCHS, passedtests);
|
||||
}
|
||||
|
||||
TEST_F(Imgproc_LSD_ADV, rotatedRect)
|
||||
{
|
||||
for (int i = 0; i < EPOCHS; ++i)
|
||||
{
|
||||
GenerateRotatedRect(test_image);
|
||||
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_ADV);
|
||||
detector->detect(test_image, lines);
|
||||
|
||||
if(2u <= lines.size()) ++passedtests;
|
||||
}
|
||||
ASSERT_EQ(EPOCHS, passedtests);
|
||||
}
|
||||
|
||||
TEST_F(Imgproc_LSD_STD, whiteNoise)
|
||||
{
|
||||
for (int i = 0; i < EPOCHS; ++i)
|
||||
{
|
||||
GenerateWhiteNoise(test_image);
|
||||
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_STD);
|
||||
detector->detect(test_image, lines);
|
||||
|
||||
if(50u >= lines.size()) ++passedtests;
|
||||
}
|
||||
ASSERT_EQ(EPOCHS, passedtests);
|
||||
}
|
||||
|
||||
TEST_F(Imgproc_LSD_STD, constColor)
|
||||
{
|
||||
for (int i = 0; i < EPOCHS; ++i)
|
||||
{
|
||||
GenerateConstColor(test_image);
|
||||
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_STD);
|
||||
detector->detect(test_image, lines);
|
||||
|
||||
if(0u == lines.size()) ++passedtests;
|
||||
}
|
||||
ASSERT_EQ(EPOCHS, passedtests);
|
||||
}
|
||||
|
||||
TEST_F(Imgproc_LSD_STD, lines)
|
||||
{
|
||||
for (int i = 0; i < EPOCHS; ++i)
|
||||
{
|
||||
const unsigned int numOfLines = 1;
|
||||
GenerateLines(test_image, numOfLines);
|
||||
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_STD);
|
||||
detector->detect(test_image, lines);
|
||||
|
||||
if(numOfLines * 2 == lines.size()) ++passedtests; // * 2 because of Gibbs effect
|
||||
}
|
||||
ASSERT_EQ(EPOCHS, passedtests);
|
||||
}
|
||||
|
||||
TEST_F(Imgproc_LSD_STD, rotatedRect)
|
||||
{
|
||||
for (int i = 0; i < EPOCHS; ++i)
|
||||
{
|
||||
GenerateRotatedRect(test_image);
|
||||
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_STD);
|
||||
detector->detect(test_image, lines);
|
||||
|
||||
if(4u <= lines.size()) ++passedtests;
|
||||
}
|
||||
ASSERT_EQ(EPOCHS, passedtests);
|
||||
}
|
||||
|
||||
TEST_F(Imgproc_LSD_NONE, whiteNoise)
|
||||
{
|
||||
for (int i = 0; i < EPOCHS; ++i)
|
||||
{
|
||||
GenerateWhiteNoise(test_image);
|
||||
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_NONE);
|
||||
detector->detect(test_image, lines);
|
||||
|
||||
if(50u >= lines.size()) ++passedtests;
|
||||
}
|
||||
ASSERT_EQ(EPOCHS, passedtests);
|
||||
}
|
||||
|
||||
TEST_F(Imgproc_LSD_NONE, constColor)
|
||||
{
|
||||
for (int i = 0; i < EPOCHS; ++i)
|
||||
{
|
||||
GenerateConstColor(test_image);
|
||||
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_NONE);
|
||||
detector->detect(test_image, lines);
|
||||
|
||||
if(0u == lines.size()) ++passedtests;
|
||||
}
|
||||
ASSERT_EQ(EPOCHS, passedtests);
|
||||
}
|
||||
|
||||
TEST_F(Imgproc_LSD_NONE, lines)
|
||||
{
|
||||
for (int i = 0; i < EPOCHS; ++i)
|
||||
{
|
||||
const unsigned int numOfLines = 1;
|
||||
GenerateLines(test_image, numOfLines);
|
||||
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_NONE);
|
||||
detector->detect(test_image, lines);
|
||||
|
||||
if(numOfLines * 2 == lines.size()) ++passedtests; // * 2 because of Gibbs effect
|
||||
}
|
||||
ASSERT_EQ(EPOCHS, passedtests);
|
||||
}
|
||||
|
||||
TEST_F(Imgproc_LSD_NONE, rotatedRect)
|
||||
{
|
||||
for (int i = 0; i < EPOCHS; ++i)
|
||||
{
|
||||
GenerateRotatedRect(test_image);
|
||||
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_NONE);
|
||||
detector->detect(test_image, lines);
|
||||
|
||||
if(8u <= lines.size()) ++passedtests;
|
||||
}
|
||||
ASSERT_EQ(EPOCHS, passedtests);
|
||||
}
|
||||
|
||||
TEST_F(Imgproc_LSD_Common, supportsVec4iResult)
|
||||
{
|
||||
for (int i = 0; i < EPOCHS; ++i)
|
||||
{
|
||||
GenerateWhiteNoise(test_image);
|
||||
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_STD);
|
||||
detector->detect(test_image, lines);
|
||||
|
||||
std::vector<Vec4i> linesVec4i;
|
||||
detector->detect(test_image, linesVec4i);
|
||||
|
||||
if (lines.size() == linesVec4i.size())
|
||||
{
|
||||
bool pass = true;
|
||||
for (size_t lineIndex = 0; pass && lineIndex < lines.size(); lineIndex++)
|
||||
{
|
||||
for (int ch = 0; ch < 4; ch++)
|
||||
{
|
||||
if (cv::saturate_cast<int>(lines[lineIndex][ch]) != linesVec4i[lineIndex][ch])
|
||||
{
|
||||
pass = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pass)
|
||||
++passedtests;
|
||||
}
|
||||
}
|
||||
ASSERT_EQ(EPOCHS, passedtests);
|
||||
}
|
||||
|
||||
TEST_F(Imgproc_LSD_Common, drawSegmentsVec4f)
|
||||
{
|
||||
GenerateConstColor(test_image);
|
||||
|
||||
std::vector<Vec4f> linesVec4f;
|
||||
RNG cr(0); // constant seed for deterministic test
|
||||
for (int j = 0; j < 10; j++) {
|
||||
linesVec4f.push_back(
|
||||
Vec4f(float(cr) * test_image.cols, float(cr) * test_image.rows, float(cr) * test_image.cols, float(cr) * test_image.rows));
|
||||
}
|
||||
|
||||
Mat actual = Mat::zeros(test_image.size(), CV_8UC3);
|
||||
Mat expected = Mat::zeros(test_image.size(), CV_8UC3);
|
||||
|
||||
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_STD);
|
||||
detector->drawSegments(actual, linesVec4f);
|
||||
|
||||
// something should be drawn
|
||||
ASSERT_EQ(sum(actual == expected) != Scalar::all(0), true);
|
||||
|
||||
for (size_t lineIndex = 0; lineIndex < linesVec4f.size(); lineIndex++)
|
||||
{
|
||||
const Vec4f &v = linesVec4f[lineIndex];
|
||||
const Point2f b(v[0], v[1]);
|
||||
const Point2f e(v[2], v[3]);
|
||||
line(expected, b, e, Scalar(0, 0, 255), 1);
|
||||
}
|
||||
|
||||
ASSERT_EQ(sum(actual != expected) == Scalar::all(0), true);
|
||||
}
|
||||
|
||||
TEST_F(Imgproc_LSD_Common, drawSegmentsVec4i)
|
||||
{
|
||||
GenerateConstColor(test_image);
|
||||
|
||||
std::vector<Vec4i> linesVec4i;
|
||||
RNG cr(0); // constant seed for deterministic test
|
||||
for (int j = 0; j < 10; j++) {
|
||||
linesVec4i.push_back(
|
||||
Vec4i(cr(test_image.cols), cr(test_image.rows), cr(test_image.cols), cr(test_image.rows)));
|
||||
}
|
||||
|
||||
Mat actual = Mat::zeros(test_image.size(), CV_8UC3);
|
||||
Mat expected = Mat::zeros(test_image.size(), CV_8UC3);
|
||||
|
||||
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_STD);
|
||||
detector->drawSegments(actual, linesVec4i);
|
||||
|
||||
// something should be drawn
|
||||
ASSERT_EQ(sum(actual == expected) != Scalar::all(0), true);
|
||||
|
||||
for (size_t lineIndex = 0; lineIndex < linesVec4i.size(); lineIndex++)
|
||||
{
|
||||
const Vec4f &v = linesVec4i[lineIndex];
|
||||
const Point2f b(v[0], v[1]);
|
||||
const Point2f e(v[2], v[3]);
|
||||
line(expected, b, e, Scalar(0, 0, 255), 1);
|
||||
}
|
||||
|
||||
ASSERT_EQ(sum(actual != expected) == Scalar::all(0), true);
|
||||
}
|
||||
|
||||
TEST_F(Imgproc_LSD_Common, compareSegmentsVec4f)
|
||||
{
|
||||
GenerateConstColor(test_image);
|
||||
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_STD);
|
||||
|
||||
std::vector<Vec4f> lines1, lines2;
|
||||
lines1.push_back(Vec4f(0, 0, 100, 200));
|
||||
lines2.push_back(Vec4f(0, 0, 100, 200));
|
||||
int result1 = detector->compareSegments(test_image.size(), lines1, lines2);
|
||||
|
||||
ASSERT_EQ(result1, 0);
|
||||
|
||||
lines2.push_back(Vec4f(100, 100, 110, 100));
|
||||
int result2 = detector->compareSegments(test_image.size(), lines1, lines2);
|
||||
|
||||
ASSERT_EQ(result2, 11);
|
||||
}
|
||||
|
||||
TEST_F(Imgproc_LSD_Common, compareSegmentsVec4i)
|
||||
{
|
||||
GenerateConstColor(test_image);
|
||||
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_STD);
|
||||
|
||||
std::vector<Vec4i> lines1, lines2;
|
||||
lines1.push_back(Vec4i(0, 0, 100, 200));
|
||||
lines2.push_back(Vec4i(0, 0, 100, 200));
|
||||
int result1 = detector->compareSegments(test_image.size(), lines1, lines2);
|
||||
|
||||
ASSERT_EQ(result1, 0);
|
||||
|
||||
lines2.push_back(Vec4i(100, 100, 110, 100));
|
||||
int result2 = detector->compareSegments(test_image.size(), lines1, lines2);
|
||||
|
||||
ASSERT_EQ(result2, 11);
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
10
3rdparty/opencv-4.5.4/modules/imgproc/test/test_main.cpp
vendored
Normal file
10
3rdparty/opencv-4.5.4/modules/imgproc/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")
|
||||
443
3rdparty/opencv-4.5.4/modules/imgproc/test/test_moments.cpp
vendored
Normal file
443
3rdparty/opencv-4.5.4/modules/imgproc/test/test_moments.cpp
vendored
Normal file
@@ -0,0 +1,443 @@
|
||||
/*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.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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/ts/ocl_test.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
#define OCL_TUNING_MODE 0
|
||||
#if OCL_TUNING_MODE
|
||||
#define OCL_TUNING_MODE_ONLY(code) code
|
||||
#else
|
||||
#define OCL_TUNING_MODE_ONLY(code)
|
||||
#endif
|
||||
|
||||
// image moments
|
||||
class CV_MomentsTest : public cvtest::ArrayTest
|
||||
{
|
||||
public:
|
||||
CV_MomentsTest(bool try_umat);
|
||||
|
||||
protected:
|
||||
|
||||
enum { MOMENT_COUNT = 25 };
|
||||
int prepare_test_case( int test_case_idx );
|
||||
void prepare_to_validation( int /*test_case_idx*/ );
|
||||
void get_test_array_types_and_sizes( int test_case_idx, vector<vector<Size> >& sizes, vector<vector<int> >& types );
|
||||
void get_minmax_bounds( int i, int j, int type, Scalar& low, Scalar& high );
|
||||
double get_success_error_level( int test_case_idx, int i, int j );
|
||||
void run_func();
|
||||
bool is_binary;
|
||||
bool try_umat_;
|
||||
};
|
||||
|
||||
|
||||
CV_MomentsTest::CV_MomentsTest(bool try_umat) :
|
||||
try_umat_(try_umat)
|
||||
{
|
||||
test_array[INPUT].push_back(NULL);
|
||||
test_array[OUTPUT].push_back(NULL);
|
||||
test_array[REF_OUTPUT].push_back(NULL);
|
||||
is_binary = false;
|
||||
OCL_TUNING_MODE_ONLY(test_case_count = 10);
|
||||
//element_wise_relative_error = false;
|
||||
}
|
||||
|
||||
|
||||
void CV_MomentsTest::get_minmax_bounds( int i, int j, int type, Scalar& low, Scalar& high )
|
||||
{
|
||||
cvtest::ArrayTest::get_minmax_bounds( i, j, type, low, high );
|
||||
int depth = CV_MAT_DEPTH(type);
|
||||
|
||||
if( depth == CV_16U )
|
||||
{
|
||||
low = Scalar::all(0);
|
||||
high = Scalar::all(1000);
|
||||
}
|
||||
else if( depth == CV_16S )
|
||||
{
|
||||
low = Scalar::all(-1000);
|
||||
high = Scalar::all(1000);
|
||||
}
|
||||
else if( depth == CV_32F )
|
||||
{
|
||||
low = Scalar::all(-1);
|
||||
high = Scalar::all(1);
|
||||
}
|
||||
}
|
||||
|
||||
void CV_MomentsTest::get_test_array_types_and_sizes( int test_case_idx,
|
||||
vector<vector<Size> >& sizes, vector<vector<int> >& types )
|
||||
{
|
||||
RNG& rng = ts->get_rng();
|
||||
cvtest::ArrayTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
|
||||
int depth = cvtest::randInt(rng) % 4;
|
||||
depth = depth == 0 ? CV_8U : depth == 1 ? CV_16U : depth == 2 ? CV_16S : CV_32F;
|
||||
|
||||
is_binary = cvtest::randInt(rng) % 2 != 0;
|
||||
|
||||
OCL_TUNING_MODE_ONLY(
|
||||
depth = CV_8U;
|
||||
is_binary = false;
|
||||
sizes[INPUT][0] = Size(1024,768)
|
||||
);
|
||||
|
||||
types[INPUT][0] = CV_MAKETYPE(depth, 1);
|
||||
types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_64FC1;
|
||||
sizes[OUTPUT][0] = sizes[REF_OUTPUT][0] = cvSize(MOMENT_COUNT,1);
|
||||
if(CV_MAT_DEPTH(types[INPUT][0])>=CV_32S)
|
||||
sizes[INPUT][0].width = MAX(sizes[INPUT][0].width, 3);
|
||||
|
||||
cvmat_allowed = true;
|
||||
}
|
||||
|
||||
|
||||
double CV_MomentsTest::get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ )
|
||||
{
|
||||
int depth = test_mat[INPUT][0].depth();
|
||||
return depth != CV_32F ? FLT_EPSILON*10 : FLT_EPSILON*100;
|
||||
}
|
||||
|
||||
int CV_MomentsTest::prepare_test_case( int test_case_idx )
|
||||
{
|
||||
int code = cvtest::ArrayTest::prepare_test_case( test_case_idx );
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
void CV_MomentsTest::run_func()
|
||||
{
|
||||
CvMoments* m = (CvMoments*)test_mat[OUTPUT][0].ptr<double>();
|
||||
double* others = (double*)(m + 1);
|
||||
if (try_umat_)
|
||||
{
|
||||
UMat u;
|
||||
test_mat[INPUT][0].clone().copyTo(u);
|
||||
OCL_TUNING_MODE_ONLY(
|
||||
static double ttime = 0;
|
||||
static int ncalls = 0;
|
||||
moments(u, is_binary != 0);
|
||||
double t = (double)getTickCount());
|
||||
Moments new_m = moments(u, is_binary != 0);
|
||||
OCL_TUNING_MODE_ONLY(
|
||||
ttime += (double)getTickCount() - t;
|
||||
ncalls++;
|
||||
printf("%g\n", ttime/ncalls/u.total()));
|
||||
*m = cvMoments(new_m);
|
||||
}
|
||||
else
|
||||
cvMoments( test_array[INPUT][0], m, is_binary );
|
||||
|
||||
others[0] = cvGetNormalizedCentralMoment( m, 2, 0 );
|
||||
others[1] = cvGetNormalizedCentralMoment( m, 1, 1 );
|
||||
others[2] = cvGetNormalizedCentralMoment( m, 0, 2 );
|
||||
others[3] = cvGetNormalizedCentralMoment( m, 3, 0 );
|
||||
others[4] = cvGetNormalizedCentralMoment( m, 2, 1 );
|
||||
others[5] = cvGetNormalizedCentralMoment( m, 1, 2 );
|
||||
others[6] = cvGetNormalizedCentralMoment( m, 0, 3 );
|
||||
}
|
||||
|
||||
|
||||
void CV_MomentsTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
{
|
||||
Mat& src = test_mat[INPUT][0];
|
||||
CvMoments m = cvMoments();
|
||||
double* mdata = test_mat[REF_OUTPUT][0].ptr<double>();
|
||||
int depth = src.depth();
|
||||
int cn = src.channels();
|
||||
int i, y, x, cols = src.cols;
|
||||
double xc = 0., yc = 0.;
|
||||
|
||||
int coi = 0;
|
||||
for( y = 0; y < src.rows; y++ )
|
||||
{
|
||||
double s0 = 0, s1 = 0, s2 = 0, s3 = 0;
|
||||
uchar* ptr = src.ptr(y);
|
||||
for( x = 0; x < cols; x++ )
|
||||
{
|
||||
double val;
|
||||
if( depth == CV_8U )
|
||||
val = ptr[x*cn + coi];
|
||||
else if( depth == CV_16U )
|
||||
val = ((ushort*)ptr)[x*cn + coi];
|
||||
else if( depth == CV_16S )
|
||||
val = ((short*)ptr)[x*cn + coi];
|
||||
else
|
||||
val = ((float*)ptr)[x*cn + coi];
|
||||
|
||||
if( is_binary )
|
||||
val = val != 0;
|
||||
|
||||
s0 += val;
|
||||
s1 += val*x;
|
||||
s2 += val*x*x;
|
||||
s3 += ((val*x)*x)*x;
|
||||
}
|
||||
|
||||
m.m00 += s0;
|
||||
m.m01 += s0*y;
|
||||
m.m02 += (s0*y)*y;
|
||||
m.m03 += ((s0*y)*y)*y;
|
||||
|
||||
m.m10 += s1;
|
||||
m.m11 += s1*y;
|
||||
m.m12 += (s1*y)*y;
|
||||
|
||||
m.m20 += s2;
|
||||
m.m21 += s2*y;
|
||||
|
||||
m.m30 += s3;
|
||||
}
|
||||
|
||||
if( m.m00 != 0 )
|
||||
{
|
||||
xc = m.m10/m.m00, yc = m.m01/m.m00;
|
||||
m.inv_sqrt_m00 = 1./sqrt(fabs(m.m00));
|
||||
}
|
||||
|
||||
for( y = 0; y < src.rows; y++ )
|
||||
{
|
||||
double s0 = 0, s1 = 0, s2 = 0, s3 = 0, y1 = y - yc;
|
||||
uchar* ptr = src.ptr(y);
|
||||
for( x = 0; x < cols; x++ )
|
||||
{
|
||||
double val, x1 = x - xc;
|
||||
if( depth == CV_8U )
|
||||
val = ptr[x*cn + coi];
|
||||
else if( depth == CV_16U )
|
||||
val = ((ushort*)ptr)[x*cn + coi];
|
||||
else if( depth == CV_16S )
|
||||
val = ((short*)ptr)[x*cn + coi];
|
||||
else
|
||||
val = ((float*)ptr)[x*cn + coi];
|
||||
|
||||
if( is_binary )
|
||||
val = val != 0;
|
||||
|
||||
s0 += val;
|
||||
s1 += val*x1;
|
||||
s2 += val*x1*x1;
|
||||
s3 += ((val*x1)*x1)*x1;
|
||||
}
|
||||
|
||||
m.mu02 += s0*y1*y1;
|
||||
m.mu03 += ((s0*y1)*y1)*y1;
|
||||
|
||||
m.mu11 += s1*y1;
|
||||
m.mu12 += (s1*y1)*y1;
|
||||
|
||||
m.mu20 += s2;
|
||||
m.mu21 += s2*y1;
|
||||
|
||||
m.mu30 += s3;
|
||||
}
|
||||
|
||||
memcpy( mdata, &m, sizeof(m));
|
||||
mdata += sizeof(m)/sizeof(m.m00);
|
||||
|
||||
/* calc normalized moments */
|
||||
{
|
||||
double inv_m00 = m.inv_sqrt_m00*m.inv_sqrt_m00;
|
||||
double s2 = inv_m00*inv_m00; /* 1./(m00 ^ (2/2 + 1)) */
|
||||
double s3 = s2*m.inv_sqrt_m00; /* 1./(m00 ^ (3/2 + 1)) */
|
||||
|
||||
mdata[0] = m.mu20 * s2;
|
||||
mdata[1] = m.mu11 * s2;
|
||||
mdata[2] = m.mu02 * s2;
|
||||
|
||||
mdata[3] = m.mu30 * s3;
|
||||
mdata[4] = m.mu21 * s3;
|
||||
mdata[5] = m.mu12 * s3;
|
||||
mdata[6] = m.mu03 * s3;
|
||||
}
|
||||
|
||||
double* a = test_mat[REF_OUTPUT][0].ptr<double>();
|
||||
double* b = test_mat[OUTPUT][0].ptr<double>();
|
||||
for( i = 0; i < MOMENT_COUNT; i++ )
|
||||
{
|
||||
if( fabs(a[i]) < 1e-3 )
|
||||
a[i] = 0;
|
||||
if( fabs(b[i]) < 1e-3 )
|
||||
b[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Hu invariants
|
||||
class CV_HuMomentsTest : public cvtest::ArrayTest
|
||||
{
|
||||
public:
|
||||
CV_HuMomentsTest();
|
||||
|
||||
protected:
|
||||
|
||||
enum { MOMENT_COUNT = 18, HU_MOMENT_COUNT = 7 };
|
||||
|
||||
int prepare_test_case( int test_case_idx );
|
||||
void prepare_to_validation( int /*test_case_idx*/ );
|
||||
void get_test_array_types_and_sizes( int test_case_idx, vector<vector<Size> >& sizes, vector<vector<int> >& types );
|
||||
void get_minmax_bounds( int i, int j, int type, Scalar& low, Scalar& high );
|
||||
double get_success_error_level( int test_case_idx, int i, int j );
|
||||
void run_func();
|
||||
};
|
||||
|
||||
|
||||
CV_HuMomentsTest::CV_HuMomentsTest()
|
||||
{
|
||||
test_array[INPUT].push_back(NULL);
|
||||
test_array[OUTPUT].push_back(NULL);
|
||||
test_array[REF_OUTPUT].push_back(NULL);
|
||||
}
|
||||
|
||||
|
||||
void CV_HuMomentsTest::get_minmax_bounds( int i, int j, int type, Scalar& low, Scalar& high )
|
||||
{
|
||||
cvtest::ArrayTest::get_minmax_bounds( i, j, type, low, high );
|
||||
low = Scalar::all(-10000);
|
||||
high = Scalar::all(10000);
|
||||
}
|
||||
|
||||
|
||||
void CV_HuMomentsTest::get_test_array_types_and_sizes( int test_case_idx,
|
||||
vector<vector<Size> >& sizes, vector<vector<int> >& types )
|
||||
{
|
||||
cvtest::ArrayTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
|
||||
types[INPUT][0] = types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_64FC1;
|
||||
sizes[INPUT][0] = cvSize(MOMENT_COUNT,1);
|
||||
sizes[OUTPUT][0] = sizes[REF_OUTPUT][0] = cvSize(HU_MOMENT_COUNT,1);
|
||||
}
|
||||
|
||||
|
||||
double CV_HuMomentsTest::get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ )
|
||||
{
|
||||
return FLT_EPSILON;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int CV_HuMomentsTest::prepare_test_case( int test_case_idx )
|
||||
{
|
||||
int code = cvtest::ArrayTest::prepare_test_case( test_case_idx );
|
||||
if( code > 0 )
|
||||
{
|
||||
// ...
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
void CV_HuMomentsTest::run_func()
|
||||
{
|
||||
cvGetHuMoments( test_mat[INPUT][0].ptr<CvMoments>(),
|
||||
test_mat[OUTPUT][0].ptr<CvHuMoments>() );
|
||||
}
|
||||
|
||||
|
||||
void CV_HuMomentsTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
{
|
||||
CvMoments* m = test_mat[INPUT][0].ptr<CvMoments>();
|
||||
CvHuMoments* hu = test_mat[REF_OUTPUT][0].ptr<CvHuMoments>();
|
||||
|
||||
double inv_m00 = m->inv_sqrt_m00*m->inv_sqrt_m00;
|
||||
double s2 = inv_m00*inv_m00; /* 1./(m00 ^ (2/2 + 1)) */
|
||||
double s3 = s2*m->inv_sqrt_m00; /* 1./(m00 ^ (3/2 + 1)) */
|
||||
|
||||
double nu20 = m->mu20 * s2;
|
||||
double nu11 = m->mu11 * s2;
|
||||
double nu02 = m->mu02 * s2;
|
||||
|
||||
double nu30 = m->mu30 * s3;
|
||||
double nu21 = m->mu21 * s3;
|
||||
double nu12 = m->mu12 * s3;
|
||||
double nu03 = m->mu03 * s3;
|
||||
|
||||
#undef sqr
|
||||
#define sqr(a) ((a)*(a))
|
||||
|
||||
hu->hu1 = nu20 + nu02;
|
||||
hu->hu2 = sqr(nu20 - nu02) + 4*sqr(nu11);
|
||||
hu->hu3 = sqr(nu30 - 3*nu12) + sqr(3*nu21 - nu03);
|
||||
hu->hu4 = sqr(nu30 + nu12) + sqr(nu21 + nu03);
|
||||
hu->hu5 = (nu30 - 3*nu12)*(nu30 + nu12)*(sqr(nu30 + nu12) - 3*sqr(nu21 + nu03)) +
|
||||
(3*nu21 - nu03)*(nu21 + nu03)*(3*sqr(nu30 + nu12) - sqr(nu21 + nu03));
|
||||
hu->hu6 = (nu20 - nu02)*(sqr(nu30 + nu12) - sqr(nu21 + nu03)) +
|
||||
4*nu11*(nu30 + nu12)*(nu21 + nu03);
|
||||
hu->hu7 = (3*nu21 - nu03)*(nu30 + nu12)*(sqr(nu30 + nu12) - 3*sqr(nu21 + nu03)) +
|
||||
(3*nu12 - nu30)*(nu21 + nu03)*(3*sqr(nu30 + nu12) - sqr(nu21 + nu03));
|
||||
}
|
||||
|
||||
|
||||
TEST(Imgproc_Moments, accuracy) { CV_MomentsTest test(false); test.safe_run(); }
|
||||
OCL_TEST(Imgproc_Moments, accuracy) { CV_MomentsTest test(true); test.safe_run(); }
|
||||
TEST(Imgproc_HuMoments, accuracy) { CV_HuMomentsTest test; test.safe_run(); }
|
||||
|
||||
class CV_SmallContourMomentTest : public cvtest::BaseTest
|
||||
{
|
||||
public:
|
||||
CV_SmallContourMomentTest() {}
|
||||
~CV_SmallContourMomentTest() {}
|
||||
protected:
|
||||
void run(int)
|
||||
{
|
||||
try
|
||||
{
|
||||
vector<Point> points;
|
||||
points.push_back(Point(50, 56));
|
||||
points.push_back(Point(53, 53));
|
||||
points.push_back(Point(46, 54));
|
||||
points.push_back(Point(49, 51));
|
||||
|
||||
Moments m = moments(points, false);
|
||||
double area = contourArea(points);
|
||||
|
||||
CV_Assert( m.m00 == 0 && m.m01 == 0 && m.m10 == 0 && area == 0 );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TEST(Imgproc_ContourMoment, small) { CV_SmallContourMomentTest test; test.safe_run(); }
|
||||
|
||||
}} // namespace
|
||||
397
3rdparty/opencv-4.5.4/modules/imgproc/test/test_pc.cpp
vendored
Normal file
397
3rdparty/opencv-4.5.4/modules/imgproc/test/test_pc.cpp
vendored
Normal file
@@ -0,0 +1,397 @@
|
||||
/*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 {
|
||||
|
||||
/// phase correlation
|
||||
class CV_PhaseCorrelatorTest : public cvtest::ArrayTest
|
||||
{
|
||||
public:
|
||||
CV_PhaseCorrelatorTest();
|
||||
protected:
|
||||
void run( int );
|
||||
};
|
||||
|
||||
CV_PhaseCorrelatorTest::CV_PhaseCorrelatorTest() {}
|
||||
|
||||
void CV_PhaseCorrelatorTest::run( int )
|
||||
{
|
||||
ts->set_failed_test_info(cvtest::TS::OK);
|
||||
|
||||
Mat r1 = Mat::ones(Size(129, 128), CV_64F);
|
||||
Mat r2 = Mat::ones(Size(129, 128), CV_64F);
|
||||
|
||||
double expectedShiftX = -10.0;
|
||||
double expectedShiftY = -20.0;
|
||||
|
||||
// draw 10x10 rectangles @ (100, 100) and (90, 80) should see ~(-10, -20) shift here...
|
||||
cv::rectangle(r1, Point(100, 100), Point(110, 110), Scalar(0, 0, 0), CV_FILLED);
|
||||
cv::rectangle(r2, Point(90, 80), Point(100, 90), Scalar(0, 0, 0), CV_FILLED);
|
||||
|
||||
Mat hann;
|
||||
createHanningWindow(hann, r1.size(), CV_64F);
|
||||
Point2d phaseShift = phaseCorrelate(r1, r2, hann);
|
||||
|
||||
// test accuracy should be less than 1 pixel...
|
||||
if(std::abs(expectedShiftX - phaseShift.x) >= 1 || std::abs(expectedShiftY - phaseShift.y) >= 1)
|
||||
{
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Imgproc_PhaseCorrelatorTest, accuracy) { CV_PhaseCorrelatorTest test; test.safe_run(); }
|
||||
|
||||
TEST(Imgproc_PhaseCorrelatorTest, accuracy_real_img)
|
||||
{
|
||||
Mat img = imread(cvtest::TS::ptr()->get_data_path() + "shared/airplane.png", IMREAD_GRAYSCALE);
|
||||
img.convertTo(img, CV_64FC1);
|
||||
|
||||
const int xLen = 129;
|
||||
const int yLen = 129;
|
||||
const int xShift = 40;
|
||||
const int yShift = 14;
|
||||
|
||||
Mat roi1 = img(Rect(xShift, yShift, xLen, yLen));
|
||||
Mat roi2 = img(Rect(0, 0, xLen, yLen));
|
||||
|
||||
Mat hann;
|
||||
createHanningWindow(hann, roi1.size(), CV_64F);
|
||||
Point2d phaseShift = phaseCorrelate(roi1, roi2, hann);
|
||||
|
||||
ASSERT_NEAR(phaseShift.x, (double)xShift, 1.);
|
||||
ASSERT_NEAR(phaseShift.y, (double)yShift, 1.);
|
||||
}
|
||||
|
||||
TEST(Imgproc_PhaseCorrelatorTest, accuracy_1d_odd_fft) {
|
||||
Mat r1 = Mat::ones(Size(129, 1), CV_64F)*255; // 129 will be completed to 135 before FFT
|
||||
Mat r2 = Mat::ones(Size(129, 1), CV_64F)*255;
|
||||
|
||||
const int xShift = 10;
|
||||
|
||||
for(int i = 6; i < 20; i++)
|
||||
{
|
||||
r1.at<double>(i) = 1;
|
||||
r2.at<double>(i + xShift) = 1;
|
||||
}
|
||||
|
||||
Point2d phaseShift = phaseCorrelate(r1, r2);
|
||||
|
||||
ASSERT_NEAR(phaseShift.x, (double)xShift, 1.);
|
||||
}
|
||||
|
||||
////////////////////// DivSpectrums ////////////////////////
|
||||
class CV_DivSpectrumsTest : public cvtest::ArrayTest
|
||||
{
|
||||
public:
|
||||
CV_DivSpectrumsTest();
|
||||
protected:
|
||||
void run_func();
|
||||
void get_test_array_types_and_sizes( int, vector<vector<Size> >& sizes, vector<vector<int> >& types );
|
||||
void prepare_to_validation( int test_case_idx );
|
||||
int flags;
|
||||
};
|
||||
|
||||
|
||||
CV_DivSpectrumsTest::CV_DivSpectrumsTest() : flags(0)
|
||||
{
|
||||
// Allocate test matrices.
|
||||
test_array[INPUT].push_back(NULL); // first input DFT as a CCS-packed array or complex matrix.
|
||||
test_array[INPUT].push_back(NULL); // second input DFT as a CCS-packed array or complex matrix.
|
||||
test_array[OUTPUT].push_back(NULL); // output DFT as a complex matrix.
|
||||
test_array[REF_OUTPUT].push_back(NULL); // reference output DFT as a complex matrix.
|
||||
test_array[TEMP].push_back(NULL); // first input DFT converted to a complex matrix.
|
||||
test_array[TEMP].push_back(NULL); // second input DFT converted to a complex matrix.
|
||||
test_array[TEMP].push_back(NULL); // output DFT as a CCV-packed array.
|
||||
}
|
||||
|
||||
void CV_DivSpectrumsTest::get_test_array_types_and_sizes( int test_case_idx, vector<vector<Size> >& sizes, vector<vector<int> >& types )
|
||||
{
|
||||
cvtest::ArrayTest::get_test_array_types_and_sizes(test_case_idx, sizes, types);
|
||||
RNG& rng = ts->get_rng();
|
||||
|
||||
// Get the flag of the input.
|
||||
const int rand_int_flags = cvtest::randInt(rng);
|
||||
flags = rand_int_flags & (CV_DXT_MUL_CONJ | CV_DXT_ROWS);
|
||||
|
||||
// Get input type.
|
||||
const int rand_int_type = cvtest::randInt(rng);
|
||||
int type;
|
||||
|
||||
if (rand_int_type % 4)
|
||||
{
|
||||
type = CV_32FC1;
|
||||
}
|
||||
else if (rand_int_type % 4 == 1)
|
||||
{
|
||||
type = CV_32FC2;
|
||||
}
|
||||
else if (rand_int_type % 4 == 2)
|
||||
{
|
||||
type = CV_64FC1;
|
||||
}
|
||||
else
|
||||
{
|
||||
type = CV_64FC2;
|
||||
}
|
||||
|
||||
for( size_t i = 0; i < types.size(); i++ )
|
||||
{
|
||||
for( size_t j = 0; j < types[i].size(); j++ )
|
||||
{
|
||||
types[i][j] = type;
|
||||
}
|
||||
}
|
||||
|
||||
// Inputs are CCS-packed arrays. Prepare outputs and temporary inputs as complex matrices.
|
||||
if( type == CV_32FC1 || type == CV_64FC1 )
|
||||
{
|
||||
types[OUTPUT][0] += 8;
|
||||
types[REF_OUTPUT][0] += 8;
|
||||
types[TEMP][0] += 8;
|
||||
types[TEMP][1] += 8;
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper function to convert a ccs array of depth_t into a complex matrix.
|
||||
template<typename depth_t>
|
||||
static void convert_from_ccs_helper( const Mat& src0, const Mat& src1, Mat& dst )
|
||||
{
|
||||
const int cn = src0.channels();
|
||||
int srcstep = cn;
|
||||
int dststep = 1;
|
||||
|
||||
if( !dst.isContinuous() )
|
||||
dststep = (int)(dst.step/dst.elemSize());
|
||||
|
||||
if( !src0.isContinuous() )
|
||||
srcstep = (int)(src0.step/src0.elemSize1());
|
||||
|
||||
Complex<depth_t> *dst_data = dst.ptr<Complex<depth_t> >();
|
||||
const depth_t* src0_data = src0.ptr<depth_t>();
|
||||
const depth_t* src1_data = src1.ptr<depth_t>();
|
||||
dst_data->re = src0_data[0];
|
||||
dst_data->im = 0;
|
||||
const int n = dst.cols + dst.rows - 1;
|
||||
const int n2 = (n+1) >> 1;
|
||||
|
||||
if( (n & 1) == 0 )
|
||||
{
|
||||
dst_data[n2*dststep].re = src0_data[(cn == 1 ? n-1 : n2)*srcstep];
|
||||
dst_data[n2*dststep].im = 0;
|
||||
}
|
||||
|
||||
int delta0 = srcstep;
|
||||
int delta1 = delta0 + (cn == 1 ? srcstep : 1);
|
||||
|
||||
if( cn == 1 )
|
||||
srcstep *= 2;
|
||||
|
||||
for( int i = 1; i < n2; i++, delta0 += srcstep, delta1 += srcstep )
|
||||
{
|
||||
depth_t t0 = src0_data[delta0];
|
||||
depth_t t1 = src0_data[delta1];
|
||||
|
||||
dst_data[i*dststep].re = t0;
|
||||
dst_data[i*dststep].im = t1;
|
||||
|
||||
t0 = src1_data[delta0];
|
||||
t1 = -src1_data[delta1];
|
||||
|
||||
dst_data[(n-i)*dststep].re = t0;
|
||||
dst_data[(n-i)*dststep].im = t1;
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper function to convert a ccs array into a complex matrix.
|
||||
static void convert_from_ccs( const Mat& src0, const Mat& src1, Mat& dst, const int flags )
|
||||
{
|
||||
if( dst.rows > 1 && (dst.cols > 1 || (flags & DFT_ROWS)) )
|
||||
{
|
||||
const int count = dst.rows;
|
||||
const int len = dst.cols;
|
||||
const bool is2d = (flags & DFT_ROWS) == 0;
|
||||
for( int i = 0; i < count; i++ )
|
||||
{
|
||||
const int j = !is2d || i == 0 ? i : count - i;
|
||||
const Mat& src0row = src0.row(i);
|
||||
const Mat& src1row = src1.row(j);
|
||||
Mat dstrow = dst.row(i);
|
||||
convert_from_ccs( src0row, src1row, dstrow, 0 );
|
||||
}
|
||||
|
||||
if( is2d )
|
||||
{
|
||||
const Mat& src0row = src0.col(0);
|
||||
Mat dstrow = dst.col(0);
|
||||
convert_from_ccs( src0row, src0row, dstrow, 0 );
|
||||
|
||||
if( (len & 1) == 0 )
|
||||
{
|
||||
const Mat& src0row_even = src0.col(src0.cols - 1);
|
||||
Mat dstrow_even = dst.col(len/2);
|
||||
convert_from_ccs( src0row_even, src0row_even, dstrow_even, 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( dst.depth() == CV_32F )
|
||||
{
|
||||
convert_from_ccs_helper<float>( src0, src1, dst );
|
||||
}
|
||||
else
|
||||
{
|
||||
convert_from_ccs_helper<double>( src0, src1, dst );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper function to compute complex number (nu_re + nu_im * i) / (de_re + de_im * i).
|
||||
static std::pair<double, double> divide_complex_numbers( const double nu_re, const double nu_im,
|
||||
const double de_re, const double de_im,
|
||||
const bool conj_de )
|
||||
{
|
||||
if ( conj_de )
|
||||
{
|
||||
return divide_complex_numbers( nu_re, nu_im, de_re, -de_im, false /* conj_de */ );
|
||||
}
|
||||
|
||||
const double result_de = de_re * de_re + de_im * de_im + DBL_EPSILON;
|
||||
const double result_re = nu_re * de_re + nu_im * de_im;
|
||||
const double result_im = nu_re * (-de_im) + nu_im * de_re;
|
||||
return std::pair<double, double>(result_re / result_de, result_im / result_de);
|
||||
};
|
||||
|
||||
/// Helper function to divide a DFT in src1 by a DFT in src2 with depths depth_t. The DFTs are
|
||||
/// complex matrices.
|
||||
template <typename depth_t>
|
||||
static void div_complex_helper( const Mat& src1, const Mat& src2, Mat& dst, int flags )
|
||||
{
|
||||
CV_Assert( src1.size == src2.size && src1.type() == src2.type() );
|
||||
dst.create( src1.rows, src1.cols, src1.type() );
|
||||
const int cn = src1.channels();
|
||||
int cols = src1.cols * cn;
|
||||
|
||||
for( int i = 0; i < dst.rows; i++ )
|
||||
{
|
||||
const depth_t *src1_data = src1.ptr<depth_t>(i);
|
||||
const depth_t *src2_data = src2.ptr<depth_t>(i);
|
||||
depth_t *dst_data = dst.ptr<depth_t>(i);
|
||||
for( int j = 0; j < cols; j += 2 )
|
||||
{
|
||||
std::pair<double, double> result =
|
||||
divide_complex_numbers( src1_data[j], src1_data[j + 1],
|
||||
src2_data[j], src2_data[j + 1],
|
||||
(flags & CV_DXT_MUL_CONJ) != 0 );
|
||||
dst_data[j] = (depth_t)result.first;
|
||||
dst_data[j + 1] = (depth_t)result.second;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper function to divide a DFT in src1 by a DFT in src2. The DFTs are complex matrices.
|
||||
static void div_complex( const Mat& src1, const Mat& src2, Mat& dst, const int flags )
|
||||
{
|
||||
const int type = src1.type();
|
||||
CV_Assert( type == CV_32FC2 || type == CV_64FC2 );
|
||||
|
||||
if ( src1.depth() == CV_32F )
|
||||
{
|
||||
return div_complex_helper<float>( src1, src2, dst, flags );
|
||||
}
|
||||
else
|
||||
{
|
||||
return div_complex_helper<double>( src1, src2, dst, flags );
|
||||
}
|
||||
}
|
||||
|
||||
void CV_DivSpectrumsTest::prepare_to_validation( int /* test_case_idx */ )
|
||||
{
|
||||
Mat &src1 = test_mat[INPUT][0];
|
||||
Mat &src2 = test_mat[INPUT][1];
|
||||
Mat &ref_dst = test_mat[REF_OUTPUT][0];
|
||||
const int cn = src1.channels();
|
||||
// Inputs are CCS-packed arrays. Convert them to complex matrices and get the expected output
|
||||
// as a complex matrix.
|
||||
if( cn == 1 )
|
||||
{
|
||||
Mat &converted_src1 = test_mat[TEMP][0];
|
||||
Mat &converted_src2 = test_mat[TEMP][1];
|
||||
convert_from_ccs( src1, src1, converted_src1, flags );
|
||||
convert_from_ccs( src2, src2, converted_src2, flags );
|
||||
div_complex( converted_src1, converted_src2, ref_dst, flags );
|
||||
}
|
||||
// Inputs are complex matrices. Get the expected output as a complex matrix.
|
||||
else
|
||||
{
|
||||
div_complex( src1, src2, ref_dst, flags );
|
||||
}
|
||||
}
|
||||
|
||||
void CV_DivSpectrumsTest::run_func()
|
||||
{
|
||||
const Mat &src1 = test_mat[INPUT][0];
|
||||
const Mat &src2 = test_mat[INPUT][1];
|
||||
const int cn = src1.channels();
|
||||
|
||||
// Inputs are CCS-packed arrays. Get the output as a CCS-packed array and convert it to a
|
||||
// complex matrix.
|
||||
if ( cn == 1 )
|
||||
{
|
||||
Mat &dst = test_mat[TEMP][2];
|
||||
cv::divSpectrums( src1, src2, dst, flags, (flags & CV_DXT_MUL_CONJ) != 0 );
|
||||
Mat &converted_dst = test_mat[OUTPUT][0];
|
||||
convert_from_ccs( dst, dst, converted_dst, flags );
|
||||
}
|
||||
// Inputs are complex matrices. Get the output as a complex matrix.
|
||||
else
|
||||
{
|
||||
Mat &dst = test_mat[OUTPUT][0];
|
||||
cv::divSpectrums( src1, src2, dst, flags, (flags & CV_DXT_MUL_CONJ) != 0 );
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Imgproc_DivSpectrums, accuracy) { CV_DivSpectrumsTest test; test.safe_run(); }
|
||||
|
||||
}} // namespace
|
||||
15
3rdparty/opencv-4.5.4/modules/imgproc/test/test_precomp.hpp
vendored
Normal file
15
3rdparty/opencv-4.5.4/modules/imgproc/test/test_precomp.hpp
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
// 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/imgproc.hpp"
|
||||
#include "opencv2/imgproc/imgproc_c.h"
|
||||
|
||||
#include "opencv2/core/private.hpp"
|
||||
|
||||
#include "opencv2/core/softfloat.hpp" // softfloat, uint32_t
|
||||
|
||||
#endif
|
||||
240
3rdparty/opencv-4.5.4/modules/imgproc/test/test_resize_bitexact.cpp
vendored
Normal file
240
3rdparty/opencv-4.5.4/modules/imgproc/test/test_resize_bitexact.cpp
vendored
Normal file
@@ -0,0 +1,240 @@
|
||||
// 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"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
static const int fixedShiftU8 = 8;
|
||||
|
||||
template <typename T, int fixedShift>
|
||||
void eval4(int64_t xcoeff0, int64_t xcoeff1, int64_t ycoeff0, int64_t ycoeff1, int cn,
|
||||
uint8_t* src_pt00, uint8_t* src_pt01, uint8_t* src_pt10, uint8_t* src_pt11, uint8_t* dst_pt)
|
||||
{
|
||||
static const int64_t fixedRound = ((1LL << (fixedShift * 2)) >> 1);
|
||||
int64_t val = (((T*)src_pt00)[cn] * xcoeff0 + ((T*)src_pt01)[cn] * xcoeff1) * ycoeff0 +
|
||||
(((T*)src_pt10)[cn] * xcoeff0 + ((T*)src_pt11)[cn] * xcoeff1) * ycoeff1 ;
|
||||
((T*)dst_pt)[cn] = saturate_cast<T>((val + fixedRound) >> (fixedShift * 2));
|
||||
}
|
||||
|
||||
TEST(Resize_Bitexact, Linear8U)
|
||||
{
|
||||
static const int64_t fixedOne = (1L << fixedShiftU8);
|
||||
|
||||
struct testmode
|
||||
{
|
||||
int type;
|
||||
Size sz;
|
||||
} modes[] = {
|
||||
{ CV_8UC1, Size( 512, 768) }, // 1/2 1
|
||||
{ CV_8UC3, Size( 512, 768) },
|
||||
{ CV_8UC1, Size(1024, 384) }, // 1 1/2
|
||||
{ CV_8UC4, Size(1024, 384) },
|
||||
{ CV_8UC1, Size( 512, 384) }, // 1/2 1/2
|
||||
{ CV_8UC2, Size( 512, 384) },
|
||||
{ CV_8UC3, Size( 512, 384) },
|
||||
{ CV_8UC4, Size( 512, 384) },
|
||||
{ CV_8UC1, Size( 256, 192) }, // 1/4 1/4
|
||||
{ CV_8UC2, Size( 256, 192) },
|
||||
{ CV_8UC3, Size( 256, 192) },
|
||||
{ CV_8UC4, Size( 256, 192) },
|
||||
{ CV_8UC1, Size( 4, 3) }, // 1/256 1/256
|
||||
{ CV_8UC2, Size( 4, 3) },
|
||||
{ CV_8UC3, Size( 4, 3) },
|
||||
{ CV_8UC4, Size( 4, 3) },
|
||||
{ CV_8UC1, Size( 342, 384) }, // 1/3 1/2
|
||||
{ CV_8UC1, Size( 342, 256) }, // 1/3 1/3
|
||||
{ CV_8UC2, Size( 342, 256) },
|
||||
{ CV_8UC3, Size( 342, 256) },
|
||||
{ CV_8UC4, Size( 342, 256) },
|
||||
{ CV_8UC1, Size( 512, 256) }, // 1/2 1/3
|
||||
{ CV_8UC1, Size( 146, 110) }, // 1/7 1/7
|
||||
{ CV_8UC3, Size( 146, 110) },
|
||||
{ CV_8UC4, Size( 146, 110) },
|
||||
{ CV_8UC1, Size( 931, 698) }, // 10/11 10/11
|
||||
{ CV_8UC2, Size( 931, 698) },
|
||||
{ CV_8UC3, Size( 931, 698) },
|
||||
{ CV_8UC4, Size( 931, 698) },
|
||||
{ CV_8UC1, Size( 853, 640) }, // 10/12 10/12
|
||||
{ CV_8UC3, Size( 853, 640) },
|
||||
{ CV_8UC4, Size( 853, 640) },
|
||||
{ CV_8UC1, Size(1004, 753) }, // 251/256 251/256
|
||||
{ CV_8UC2, Size(1004, 753) },
|
||||
{ CV_8UC3, Size(1004, 753) },
|
||||
{ CV_8UC4, Size(1004, 753) },
|
||||
{ CV_8UC1, Size(2048,1536) }, // 2 2
|
||||
{ CV_8UC2, Size(2048,1536) },
|
||||
{ CV_8UC4, Size(2048,1536) },
|
||||
{ CV_8UC1, Size(3072,2304) }, // 3 3
|
||||
{ CV_8UC3, Size(3072,2304) },
|
||||
{ CV_8UC1, Size(7168,5376) } // 7 7
|
||||
};
|
||||
|
||||
for (int modeind = 0, _modecnt = sizeof(modes) / sizeof(modes[0]); modeind < _modecnt; ++modeind)
|
||||
{
|
||||
int type = modes[modeind].type, depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type);
|
||||
int dcols = modes[modeind].sz.width, drows = modes[modeind].sz.height;
|
||||
int cols = 1024, rows = 768;
|
||||
|
||||
double inv_scale_x = (double)dcols / cols;
|
||||
double inv_scale_y = (double)drows / rows;
|
||||
softdouble scale_x = softdouble::one() / softdouble(inv_scale_x);
|
||||
softdouble scale_y = softdouble::one() / softdouble(inv_scale_y);
|
||||
|
||||
Mat src(rows, cols, type), refdst(drows, dcols, type), dst;
|
||||
RNG rnd(0x123456789abcdefULL);
|
||||
for (int j = 0; j < rows; j++)
|
||||
{
|
||||
uint8_t* line = src.ptr(j);
|
||||
for (int i = 0; i < cols; i++)
|
||||
for (int c = 0; c < cn; c++)
|
||||
{
|
||||
double val = j < rows / 2 ? ( i < cols / 2 ? ((sin((i + 1)*CV_PI / 256.)*sin((j + 1)*CV_PI / 256.)*sin((cn + 4)*CV_PI / 8.) + 1.)*128.) :
|
||||
(((i / 128 + j / 128) % 2) * 250 + (j / 128) % 2) ) :
|
||||
( i < cols / 2 ? ((i / 128) * (85 - j / 256 * 40) * ((j / 128) % 2) + (7 - i / 128) * (85 - j / 256 * 40) * ((j / 128 + 1) % 2)) :
|
||||
((uchar)rnd) ) ;
|
||||
if (depth == CV_8U)
|
||||
line[i*cn + c] = (uint8_t)val;
|
||||
else if (depth == CV_16U)
|
||||
((uint16_t*)line)[i*cn + c] = (uint16_t)val;
|
||||
else if (depth == CV_16S)
|
||||
((int16_t*)line)[i*cn + c] = (int16_t)val;
|
||||
else if (depth == CV_32S)
|
||||
((int32_t*)line)[i*cn + c] = (int32_t)val;
|
||||
else
|
||||
CV_Assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < drows; j++)
|
||||
{
|
||||
softdouble src_row_flt = scale_y*(softdouble(j) + softdouble(0.5)) - softdouble(0.5);
|
||||
int src_row = cvFloor(src_row_flt);
|
||||
int64_t ycoeff1 = cvRound64((src_row_flt - softdouble(src_row))*softdouble(fixedOne));
|
||||
int64_t ycoeff0 = fixedOne - ycoeff1;
|
||||
|
||||
for (int i = 0; i < dcols; i++)
|
||||
{
|
||||
softdouble src_col_flt = scale_x*(softdouble(i) + softdouble(0.5)) - softdouble(0.5);
|
||||
int src_col = cvFloor(src_col_flt);
|
||||
int64_t xcoeff1 = cvRound64((src_col_flt - softdouble(src_col))*softdouble(fixedOne));
|
||||
int64_t xcoeff0 = fixedOne - xcoeff1;
|
||||
|
||||
uint8_t* dst_pt = refdst.ptr(j, i);
|
||||
uint8_t* src_pt00 = src.ptr( src_row < 0 ? 0 : src_row >= rows ? rows - 1 : src_row ,
|
||||
src_col < 0 ? 0 : src_col >= cols ? cols - 1 : src_col );
|
||||
uint8_t* src_pt01 = src.ptr( src_row < 0 ? 0 : src_row >= rows ? rows - 1 : src_row ,
|
||||
(src_col + 1) < 0 ? 0 : (src_col + 1) >= cols ? cols - 1 : (src_col + 1));
|
||||
uint8_t* src_pt10 = src.ptr((src_row + 1) < 0 ? 0 : (src_row + 1) >= rows ? rows - 1 : (src_row + 1),
|
||||
src_col < 0 ? 0 : src_col >= cols ? cols - 1 : src_col );
|
||||
uint8_t* src_pt11 = src.ptr((src_row + 1) < 0 ? 0 : (src_row + 1) >= rows ? rows - 1 : (src_row + 1),
|
||||
(src_col + 1) < 0 ? 0 : (src_col + 1) >= cols ? cols - 1 : (src_col + 1));
|
||||
for (int c = 0; c < cn; c++)
|
||||
{
|
||||
if (depth == CV_8U)
|
||||
eval4< uint8_t, fixedShiftU8>(xcoeff0, xcoeff1, ycoeff0, ycoeff1, c, src_pt00, src_pt01, src_pt10, src_pt11, dst_pt);
|
||||
else if (depth == CV_16U)
|
||||
eval4<uint16_t, fixedShiftU8>(xcoeff0, xcoeff1, ycoeff0, ycoeff1, c, src_pt00, src_pt01, src_pt10, src_pt11, dst_pt);
|
||||
else if (depth == CV_16S)
|
||||
eval4< int16_t, fixedShiftU8>(xcoeff0, xcoeff1, ycoeff0, ycoeff1, c, src_pt00, src_pt01, src_pt10, src_pt11, dst_pt);
|
||||
else if (depth == CV_32S)
|
||||
eval4< int32_t, fixedShiftU8>(xcoeff0, xcoeff1, ycoeff0, ycoeff1, c, src_pt00, src_pt01, src_pt10, src_pt11, dst_pt);
|
||||
else
|
||||
CV_Assert(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cv::resize(src, dst, Size(dcols, drows), 0, 0, cv::INTER_LINEAR_EXACT);
|
||||
EXPECT_GE(0, cvtest::norm(refdst, dst, cv::NORM_L1))
|
||||
<< "Resize " << cn << "-chan mat from " << cols << "x" << rows << " to " << dcols << "x" << drows << " failed with max diff " << cvtest::norm(refdst, dst, cv::NORM_INF);
|
||||
}
|
||||
}
|
||||
|
||||
PARAM_TEST_CASE(Resize_Bitexact, int)
|
||||
{
|
||||
public:
|
||||
int depth;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
depth = GET_PARAM(0);
|
||||
}
|
||||
|
||||
double CountDiff(const Mat& src)
|
||||
{
|
||||
Mat dstExact; cv::resize(src, dstExact, Size(), 2, 1, INTER_NEAREST_EXACT);
|
||||
Mat dstNonExact; cv::resize(src, dstNonExact, Size(), 2, 1, INTER_NEAREST);
|
||||
|
||||
return cv::norm(dstExact, dstNonExact, NORM_INF);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(Resize_Bitexact, Nearest8U_vsNonExact)
|
||||
{
|
||||
Mat mat_color, mat_gray;
|
||||
Mat src_color = imread(cvtest::findDataFile("shared/lena.png"));
|
||||
Mat src_gray; cv::cvtColor(src_color, src_gray, COLOR_BGR2GRAY);
|
||||
src_color.convertTo(mat_color, depth);
|
||||
src_gray.convertTo(mat_gray, depth);
|
||||
|
||||
EXPECT_EQ(CountDiff(mat_color), 0) << "color, type: " << depth;
|
||||
EXPECT_EQ(CountDiff(mat_gray), 0) << "gray, type: " << depth;
|
||||
}
|
||||
|
||||
// Now INTER_NEAREST's convention and INTER_NEAREST_EXACT's one are different.
|
||||
INSTANTIATE_TEST_CASE_P(DISABLED_Imgproc, Resize_Bitexact,
|
||||
testing::Values(CV_8U, CV_16U, CV_32F, CV_64F)
|
||||
);
|
||||
|
||||
TEST(Resize_Bitexact, Nearest8U)
|
||||
{
|
||||
Mat src[6], dst[6];
|
||||
|
||||
// 2x decimation
|
||||
src[0] = (Mat_<uint8_t>(1, 6) << 0, 1, 2, 3, 4, 5);
|
||||
dst[0] = (Mat_<uint8_t>(1, 3) << 0, 2, 4);
|
||||
|
||||
// decimation odd to 1
|
||||
src[1] = (Mat_<uint8_t>(1, 5) << 0, 1, 2, 3, 4);
|
||||
dst[1] = (Mat_<uint8_t>(1, 1) << 2);
|
||||
|
||||
// decimation n*2-1 to n
|
||||
src[2] = (Mat_<uint8_t>(1, 5) << 0, 1, 2, 3, 4);
|
||||
dst[2] = (Mat_<uint8_t>(1, 3) << 0, 2, 4);
|
||||
|
||||
// decimation n*2+1 to n
|
||||
src[3] = (Mat_<uint8_t>(1, 5) << 0, 1, 2, 3, 4);
|
||||
dst[3] = (Mat_<uint8_t>(1, 2) << 1, 3);
|
||||
|
||||
// zoom
|
||||
src[4] = (Mat_<uint8_t>(3, 5) <<
|
||||
0, 1, 2, 3, 4,
|
||||
5, 6, 7, 8, 9,
|
||||
10, 11, 12, 13, 14);
|
||||
dst[4] = (Mat_<uint8_t>(5, 7) <<
|
||||
0, 1, 1, 2, 3, 3, 4,
|
||||
0, 1, 1, 2, 3, 3, 4,
|
||||
5, 6, 6, 7, 8, 8, 9,
|
||||
10, 11, 11, 12, 13, 13, 14,
|
||||
10, 11, 11, 12, 13, 13, 14);
|
||||
|
||||
src[5] = (Mat_<uint8_t>(2, 3) <<
|
||||
0, 1, 2,
|
||||
3, 4, 5);
|
||||
dst[5] = (Mat_<uint8_t>(4, 6) <<
|
||||
0, 0, 1, 1, 2, 2,
|
||||
0, 0, 1, 1, 2, 2,
|
||||
3, 3, 4, 4, 5, 5,
|
||||
3, 3, 4, 4, 5, 5);
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
Mat calc;
|
||||
resize(src[i], calc, dst[i].size(), 0, 0, INTER_NEAREST_EXACT);
|
||||
EXPECT_EQ(cvtest::norm(calc, dst[i], cv::NORM_L1), 0);
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
263
3rdparty/opencv-4.5.4/modules/imgproc/test/test_smooth_bitexact.cpp
vendored
Normal file
263
3rdparty/opencv-4.5.4/modules/imgproc/test/test_smooth_bitexact.cpp
vendored
Normal file
@@ -0,0 +1,263 @@
|
||||
// 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"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
static const int fixedShiftU8 = 8;
|
||||
static const int64_t fixedOneU8 = (1L << fixedShiftU8);
|
||||
static const int fixedShiftU16 = 16;
|
||||
static const int64_t fixedOneU16 = (1L << fixedShiftU16);
|
||||
|
||||
int64_t vU8[][9] = {
|
||||
{ fixedOneU8 }, // size 1, sigma 0
|
||||
{ fixedOneU8 >> 2, fixedOneU8 >> 1, fixedOneU8 >> 2 }, // size 3, sigma 0
|
||||
{ fixedOneU8 >> 4, fixedOneU8 >> 2, 6 * (fixedOneU8 >> 4), fixedOneU8 >> 2, fixedOneU8 >> 4 }, // size 5, sigma 0
|
||||
{ fixedOneU8 >> 5, 7 * (fixedOneU8 >> 6), 7 * (fixedOneU8 >> 5), 9 * (fixedOneU8 >> 5), 7 * (fixedOneU8 >> 5), 7 * (fixedOneU8 >> 6), fixedOneU8 >> 5 }, // size 7, sigma 0
|
||||
{ 4, 13, 30, 51, 60, 51, 30, 13, 4 }, // size 9, sigma 0
|
||||
#if 1
|
||||
#define CV_TEST_INACCURATE_GAUSSIAN_BLUR
|
||||
{ 81, 94, 81 }, // size 3, sigma 1.75
|
||||
{ 65, 126, 65 }, // size 3, sigma 0.875
|
||||
{ 0, 7, 242, 7, 0 }, // size 5, sigma 0.375
|
||||
{ 4, 56, 136, 56, 4 } // size 5, sigma 0.75
|
||||
#endif
|
||||
};
|
||||
|
||||
int64_t vU16[][9] = {
|
||||
{ fixedOneU16 }, // size 1, sigma 0
|
||||
{ fixedOneU16 >> 2, fixedOneU16 >> 1, fixedOneU16 >> 2 }, // size 3, sigma 0
|
||||
{ fixedOneU16 >> 4, fixedOneU16 >> 2, 6 * (fixedOneU16 >> 4), fixedOneU16 >> 2, fixedOneU16 >> 4 }, // size 5, sigma 0
|
||||
{ fixedOneU16 >> 5, 7 * (fixedOneU16 >> 6), 7 * (fixedOneU16 >> 5), 9 * (fixedOneU16 >> 5), 7 * (fixedOneU16 >> 5), 7 * (fixedOneU16 >> 6), fixedOneU16 >> 5 }, // size 7, sigma 0
|
||||
{ 4<<8, 13<<8, 30<<8, 51<<8, 60<<8, 51<<8, 30<<8, 13<<8, 4<<8 } // size 9, sigma 0
|
||||
};
|
||||
|
||||
template <typename T, int fixedShift>
|
||||
T eval(Mat src, vector<int64_t> kernelx, vector<int64_t> kernely)
|
||||
{
|
||||
static const int64_t fixedRound = ((1LL << (fixedShift * 2)) >> 1);
|
||||
int64_t val = 0;
|
||||
for (size_t j = 0; j < kernely.size(); j++)
|
||||
{
|
||||
int64_t lineval = 0;
|
||||
for (size_t i = 0; i < kernelx.size(); i++)
|
||||
lineval += src.at<T>((int)j, (int)i) * kernelx[i];
|
||||
val += lineval * kernely[j];
|
||||
}
|
||||
return saturate_cast<T>((val + fixedRound) >> (fixedShift * 2));
|
||||
}
|
||||
|
||||
struct testmode
|
||||
{
|
||||
int type;
|
||||
Size sz;
|
||||
Size kernel;
|
||||
double sigma_x;
|
||||
double sigma_y;
|
||||
vector<int64_t> kernel_x;
|
||||
vector<int64_t> kernel_y;
|
||||
};
|
||||
|
||||
int bordermodes[] = {
|
||||
BORDER_CONSTANT | BORDER_ISOLATED,
|
||||
BORDER_REPLICATE | BORDER_ISOLATED,
|
||||
BORDER_REFLECT | BORDER_ISOLATED,
|
||||
BORDER_WRAP | BORDER_ISOLATED,
|
||||
BORDER_REFLECT_101 | BORDER_ISOLATED
|
||||
// BORDER_CONSTANT,
|
||||
// BORDER_REPLICATE,
|
||||
// BORDER_REFLECT,
|
||||
// BORDER_WRAP,
|
||||
// BORDER_REFLECT_101
|
||||
};
|
||||
|
||||
template <int fixedShift>
|
||||
void checkMode(const testmode& mode)
|
||||
{
|
||||
int type = mode.type, depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type);
|
||||
int dcols = mode.sz.width, drows = mode.sz.height;
|
||||
Size kernel = mode.kernel;
|
||||
|
||||
int rows = drows + 20, cols = dcols + 20;
|
||||
Mat src(rows, cols, type), refdst(drows, dcols, type), dst;
|
||||
for (int j = 0; j < rows; j++)
|
||||
{
|
||||
uint8_t* line = src.ptr(j);
|
||||
for (int i = 0; i < cols; i++)
|
||||
for (int c = 0; c < cn; c++)
|
||||
{
|
||||
RNG rnd(0x123456789abcdefULL);
|
||||
double val = j < rows / 2 ? (i < cols / 2 ? ((sin((i + 1)*CV_PI / 256.)*sin((j + 1)*CV_PI / 256.)*sin((cn + 4)*CV_PI / 8.) + 1.)*128.) :
|
||||
(((i / 128 + j / 128) % 2) * 250 + (j / 128) % 2)) :
|
||||
(i < cols / 2 ? ((i / 128) * (85 - j / 256 * 40) * ((j / 128) % 2) + (7 - i / 128) * (85 - j / 256 * 40) * ((j / 128 + 1) % 2)) :
|
||||
((uchar)rnd));
|
||||
if (depth == CV_8U)
|
||||
line[i*cn + c] = (uint8_t)val;
|
||||
else if (depth == CV_16U)
|
||||
((uint16_t*)line)[i*cn + c] = (uint16_t)val;
|
||||
else if (depth == CV_16S)
|
||||
((int16_t*)line)[i*cn + c] = (int16_t)val;
|
||||
else if (depth == CV_32S)
|
||||
((int32_t*)line)[i*cn + c] = (int32_t)val;
|
||||
else
|
||||
CV_Assert(0);
|
||||
}
|
||||
}
|
||||
Mat src_roi = src(Rect(10, 10, dcols, drows));
|
||||
|
||||
|
||||
for (int borderind = 0, _bordercnt = sizeof(bordermodes) / sizeof(bordermodes[0]); borderind < _bordercnt; ++borderind)
|
||||
{
|
||||
Mat src_border;
|
||||
cv::copyMakeBorder(src_roi, src_border, kernel.height / 2, kernel.height / 2, kernel.width / 2, kernel.width / 2, bordermodes[borderind]);
|
||||
for (int c = 0; c < src_border.channels(); c++)
|
||||
{
|
||||
int fromTo[2] = { c, 0 };
|
||||
int toFrom[2] = { 0, c };
|
||||
Mat src_chan(src_border.size(), CV_MAKETYPE(src_border.depth(),1));
|
||||
Mat dst_chan(refdst.size(), CV_MAKETYPE(refdst.depth(), 1));
|
||||
mixChannels(src_border, src_chan, fromTo, 1);
|
||||
for (int j = 0; j < drows; j++)
|
||||
for (int i = 0; i < dcols; i++)
|
||||
{
|
||||
if (depth == CV_8U)
|
||||
dst_chan.at<uint8_t>(j, i) = eval<uint8_t, fixedShift>(src_chan(Rect(i,j,kernel.width,kernel.height)), mode.kernel_x, mode.kernel_y);
|
||||
else if (depth == CV_16U)
|
||||
dst_chan.at<uint16_t>(j, i) = eval<uint16_t, fixedShift>(src_chan(Rect(i, j, kernel.width, kernel.height)), mode.kernel_x, mode.kernel_y);
|
||||
else if (depth == CV_16S)
|
||||
dst_chan.at<int16_t>(j, i) = eval<int16_t, fixedShift>(src_chan(Rect(i, j, kernel.width, kernel.height)), mode.kernel_x, mode.kernel_y);
|
||||
else if (depth == CV_32S)
|
||||
dst_chan.at<int32_t>(j, i) = eval<int32_t, fixedShift>(src_chan(Rect(i, j, kernel.width, kernel.height)), mode.kernel_x, mode.kernel_y);
|
||||
else
|
||||
CV_Assert(0);
|
||||
}
|
||||
mixChannels(dst_chan, refdst, toFrom, 1);
|
||||
}
|
||||
|
||||
cv::GaussianBlur(src_roi, dst, kernel, mode.sigma_x, mode.sigma_y, bordermodes[borderind]);
|
||||
|
||||
EXPECT_GE(0, cvtest::norm(refdst, dst, cv::NORM_L1))
|
||||
<< "GaussianBlur " << cn << "-chan mat " << drows << "x" << dcols << " by kernel " << kernel << " sigma(" << mode.sigma_x << ";" << mode.sigma_y << ") failed with max diff " << cvtest::norm(refdst, dst, cv::NORM_INF);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(GaussianBlur_Bitexact, Linear8U)
|
||||
{
|
||||
testmode modes[] = {
|
||||
{ CV_8UC1, Size( 1, 1), Size(3, 3), 0, 0, vector<int64_t>(vU8[1], vU8[1]+3), vector<int64_t>(vU8[1], vU8[1]+3) },
|
||||
{ CV_8UC1, Size( 2, 2), Size(3, 3), 0, 0, vector<int64_t>(vU8[1], vU8[1]+3), vector<int64_t>(vU8[1], vU8[1]+3) },
|
||||
{ CV_8UC1, Size( 3, 1), Size(3, 3), 0, 0, vector<int64_t>(vU8[1], vU8[1]+3), vector<int64_t>(vU8[1], vU8[1]+3) },
|
||||
{ CV_8UC1, Size( 1, 3), Size(3, 3), 0, 0, vector<int64_t>(vU8[1], vU8[1]+3), vector<int64_t>(vU8[1], vU8[1]+3) },
|
||||
{ CV_8UC1, Size( 3, 3), Size(3, 3), 0, 0, vector<int64_t>(vU8[1], vU8[1]+3), vector<int64_t>(vU8[1], vU8[1]+3) },
|
||||
{ CV_8UC1, Size( 3, 3), Size(5, 5), 0, 0, vector<int64_t>(vU8[2], vU8[2]+5), vector<int64_t>(vU8[2], vU8[2]+5) },
|
||||
{ CV_8UC1, Size( 3, 3), Size(7, 7), 0, 0, vector<int64_t>(vU8[3], vU8[3]+7), vector<int64_t>(vU8[3], vU8[3]+7) },
|
||||
{ CV_8UC1, Size( 5, 5), Size(3, 3), 0, 0, vector<int64_t>(vU8[1], vU8[1]+3), vector<int64_t>(vU8[1], vU8[1]+3) },
|
||||
{ CV_8UC1, Size( 5, 5), Size(5, 5), 0, 0, vector<int64_t>(vU8[2], vU8[2]+5), vector<int64_t>(vU8[2], vU8[2]+5) },
|
||||
{ CV_8UC1, Size( 3, 5), Size(5, 5), 0, 0, vector<int64_t>(vU8[2], vU8[2]+5), vector<int64_t>(vU8[2], vU8[2]+5) },
|
||||
{ CV_8UC1, Size( 5, 5), Size(5, 5), 0, 0, vector<int64_t>(vU8[2], vU8[2]+5), vector<int64_t>(vU8[2], vU8[2]+5) },
|
||||
{ CV_8UC1, Size( 5, 5), Size(7, 7), 0, 0, vector<int64_t>(vU8[3], vU8[3]+7), vector<int64_t>(vU8[3], vU8[3]+7) },
|
||||
{ CV_8UC1, Size( 7, 7), Size(7, 7), 0, 0, vector<int64_t>(vU8[3], vU8[3]+7), vector<int64_t>(vU8[3], vU8[3]+7) },
|
||||
{ CV_8UC1, Size( 256, 128), Size(3, 3), 0, 0, vector<int64_t>(vU8[1], vU8[1]+3), vector<int64_t>(vU8[1], vU8[1]+3) },
|
||||
{ CV_8UC2, Size( 256, 128), Size(3, 3), 0, 0, vector<int64_t>(vU8[1], vU8[1]+3), vector<int64_t>(vU8[1], vU8[1]+3) },
|
||||
{ CV_8UC3, Size( 256, 128), Size(3, 3), 0, 0, vector<int64_t>(vU8[1], vU8[1]+3), vector<int64_t>(vU8[1], vU8[1]+3) },
|
||||
{ CV_8UC4, Size( 256, 128), Size(3, 3), 0, 0, vector<int64_t>(vU8[1], vU8[1]+3), vector<int64_t>(vU8[1], vU8[1]+3) },
|
||||
{ CV_8UC1, Size( 256, 128), Size(5, 5), 0, 0, vector<int64_t>(vU8[2], vU8[2]+5), vector<int64_t>(vU8[2], vU8[2]+5) },
|
||||
{ CV_8UC1, Size( 256, 128), Size(7, 7), 0, 0, vector<int64_t>(vU8[3], vU8[3]+7), vector<int64_t>(vU8[3], vU8[3]+7) },
|
||||
{ CV_8UC1, Size( 256, 128), Size(9, 9), 0, 0, vector<int64_t>(vU8[4], vU8[4]+9), vector<int64_t>(vU8[4], vU8[4]+9) },
|
||||
#ifdef CV_TEST_INACCURATE_GAUSSIAN_BLUR
|
||||
{ CV_8UC1, Size( 256, 128), Size(3, 3), 1.75, 0.875, vector<int64_t>(vU8[5], vU8[5]+3), vector<int64_t>(vU8[6], vU8[6]+3) },
|
||||
{ CV_8UC2, Size( 256, 128), Size(3, 3), 1.75, 0.875, vector<int64_t>(vU8[5], vU8[5]+3), vector<int64_t>(vU8[6], vU8[6]+3) },
|
||||
{ CV_8UC3, Size( 256, 128), Size(3, 3), 1.75, 0.875, vector<int64_t>(vU8[5], vU8[5]+3), vector<int64_t>(vU8[6], vU8[6]+3) },
|
||||
{ CV_8UC4, Size( 256, 128), Size(3, 3), 1.75, 0.875, vector<int64_t>(vU8[5], vU8[5]+3), vector<int64_t>(vU8[6], vU8[6]+3) },
|
||||
{ CV_8UC1, Size( 256, 128), Size(5, 5), 0.375, 0.75, vector<int64_t>(vU8[7], vU8[7]+5), vector<int64_t>(vU8[8], vU8[8]+5) }
|
||||
#endif
|
||||
};
|
||||
|
||||
for (int modeind = 0, _modecnt = sizeof(modes) / sizeof(modes[0]); modeind < _modecnt; ++modeind)
|
||||
{
|
||||
checkMode<fixedShiftU8>(modes[modeind]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(GaussianBlur_Bitexact, Linear16U)
|
||||
{
|
||||
testmode modes[] = {
|
||||
{ CV_16UC1, Size( 1, 1), Size(3, 3), 0, 0, vector<int64_t>(vU16[1], vU16[1]+3), vector<int64_t>(vU16[1], vU16[1]+3) },
|
||||
{ CV_16UC1, Size( 2, 2), Size(3, 3), 0, 0, vector<int64_t>(vU16[1], vU16[1]+3), vector<int64_t>(vU16[1], vU16[1]+3) },
|
||||
{ CV_16UC1, Size( 3, 1), Size(3, 3), 0, 0, vector<int64_t>(vU16[1], vU16[1]+3), vector<int64_t>(vU16[1], vU16[1]+3) },
|
||||
{ CV_16UC1, Size( 1, 3), Size(3, 3), 0, 0, vector<int64_t>(vU16[1], vU16[1]+3), vector<int64_t>(vU16[1], vU16[1]+3) },
|
||||
{ CV_16UC1, Size( 3, 3), Size(3, 3), 0, 0, vector<int64_t>(vU16[1], vU16[1]+3), vector<int64_t>(vU16[1], vU16[1]+3) },
|
||||
{ CV_16UC1, Size( 3, 3), Size(5, 5), 0, 0, vector<int64_t>(vU16[2], vU16[2]+5), vector<int64_t>(vU16[2], vU16[2]+5) },
|
||||
{ CV_16UC1, Size( 3, 3), Size(7, 7), 0, 0, vector<int64_t>(vU16[3], vU16[3]+7), vector<int64_t>(vU16[3], vU16[3]+7) },
|
||||
{ CV_16UC1, Size( 5, 5), Size(3, 3), 0, 0, vector<int64_t>(vU16[1], vU16[1]+3), vector<int64_t>(vU16[1], vU16[1]+3) },
|
||||
{ CV_16UC1, Size( 5, 5), Size(5, 5), 0, 0, vector<int64_t>(vU16[2], vU16[2]+5), vector<int64_t>(vU16[2], vU16[2]+5) },
|
||||
{ CV_16UC1, Size( 3, 5), Size(5, 5), 0, 0, vector<int64_t>(vU16[2], vU16[2]+5), vector<int64_t>(vU16[2], vU16[2]+5) },
|
||||
{ CV_16UC1, Size( 5, 5), Size(5, 5), 0, 0, vector<int64_t>(vU16[2], vU16[2]+5), vector<int64_t>(vU16[2], vU16[2]+5) },
|
||||
{ CV_16UC1, Size( 5, 5), Size(7, 7), 0, 0, vector<int64_t>(vU16[3], vU16[3]+7), vector<int64_t>(vU16[3], vU16[3]+7) },
|
||||
{ CV_16UC1, Size( 7, 7), Size(7, 7), 0, 0, vector<int64_t>(vU16[3], vU16[3]+7), vector<int64_t>(vU16[3], vU16[3]+7) },
|
||||
{ CV_16UC1, Size( 256, 128), Size(3, 3), 0, 0, vector<int64_t>(vU16[1], vU16[1]+3), vector<int64_t>(vU16[1], vU16[1]+3) },
|
||||
{ CV_16UC2, Size( 256, 128), Size(3, 3), 0, 0, vector<int64_t>(vU16[1], vU16[1]+3), vector<int64_t>(vU16[1], vU16[1]+3) },
|
||||
{ CV_16UC3, Size( 256, 128), Size(3, 3), 0, 0, vector<int64_t>(vU16[1], vU16[1]+3), vector<int64_t>(vU16[1], vU16[1]+3) },
|
||||
{ CV_16UC4, Size( 256, 128), Size(3, 3), 0, 0, vector<int64_t>(vU16[1], vU16[1]+3), vector<int64_t>(vU16[1], vU16[1]+3) },
|
||||
{ CV_16UC1, Size( 256, 128), Size(5, 5), 0, 0, vector<int64_t>(vU16[2], vU16[2]+5), vector<int64_t>(vU16[2], vU16[2]+5) },
|
||||
{ CV_16UC1, Size( 256, 128), Size(7, 7), 0, 0, vector<int64_t>(vU16[3], vU16[3]+7), vector<int64_t>(vU16[3], vU16[3]+7) },
|
||||
{ CV_16UC1, Size( 256, 128), Size(9, 9), 0, 0, vector<int64_t>(vU16[4], vU16[4]+9), vector<int64_t>(vU16[4], vU16[4]+9) },
|
||||
};
|
||||
|
||||
for (int modeind = 0, _modecnt = sizeof(modes) / sizeof(modes[0]); modeind < _modecnt; ++modeind)
|
||||
{
|
||||
checkMode<16>(modes[modeind]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(GaussianBlur_Bitexact, regression_15015)
|
||||
{
|
||||
Mat src(100,100,CV_8UC3,Scalar(255,255,255));
|
||||
Mat dst;
|
||||
GaussianBlur(src, dst, Size(5, 5), 0);
|
||||
ASSERT_EQ(0.0, cvtest::norm(dst, src, NORM_INF));
|
||||
}
|
||||
|
||||
TEST(GaussianBlur_Bitexact, overflow_20121)
|
||||
{
|
||||
Mat src(100, 100, CV_16UC1, Scalar(65535));
|
||||
Mat dst;
|
||||
GaussianBlur(src, dst, cv::Size(9, 9), 0.0);
|
||||
double min_val;
|
||||
minMaxLoc(dst, &min_val);
|
||||
ASSERT_EQ(cvRound(min_val), 65535);
|
||||
}
|
||||
|
||||
static void checkGaussianBlur_8Uvs32F(const Mat& src8u, const Mat& src32f, int N, double sigma)
|
||||
{
|
||||
Mat dst8u; GaussianBlur(src8u, dst8u, Size(N, N), sigma); // through bit-exact path
|
||||
Mat dst8u_32f; dst8u.convertTo(dst8u_32f, CV_32F);
|
||||
|
||||
Mat dst32f; GaussianBlur(src32f, dst32f, Size(N, N), sigma); // without bit-exact computations
|
||||
|
||||
double normINF_32f = cv::norm(dst8u_32f, dst32f, NORM_INF);
|
||||
EXPECT_LE(normINF_32f, 1.0);
|
||||
}
|
||||
|
||||
TEST(GaussianBlur_Bitexact, regression_9863)
|
||||
{
|
||||
Mat src8u = imread(cvtest::findDataFile("shared/lena.png"));
|
||||
Mat src32f; src8u.convertTo(src32f, CV_32F);
|
||||
|
||||
checkGaussianBlur_8Uvs32F(src8u, src32f, 151, 30);
|
||||
}
|
||||
|
||||
TEST(GaussianBlur_Bitexact, overflow_20792)
|
||||
{
|
||||
Mat src(128, 128, CV_16UC1, Scalar(255));
|
||||
Mat dst;
|
||||
double sigma = theRNG().uniform(0.0, 0.2); // a peaky kernel
|
||||
GaussianBlur(src, dst, Size(7, 7), sigma, 0.9);
|
||||
int count = (int)countNonZero(dst);
|
||||
int nintyPercent = (int)(src.rows*src.cols * 0.9);
|
||||
EXPECT_GT(count, nintyPercent);
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
53
3rdparty/opencv-4.5.4/modules/imgproc/test/test_subdivision2d.cpp
vendored
Normal file
53
3rdparty/opencv-4.5.4/modules/imgproc/test/test_subdivision2d.cpp
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.
|
||||
//M*/
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
TEST(Imgproc_Subdiv2D_getTriangleList, regression_5788)
|
||||
{
|
||||
const float points[65][2] = {
|
||||
{ 390, 802}, { 397, 883}, { 414, 963 }, { 439, 1042 }, { 472, 1113},
|
||||
{ 521, 1181}, { 591, 1238}, { 678, 1284 }, { 771, 1292 }, { 853, 1281},
|
||||
{ 921, 1243}, { 982, 1191}, {1030, 1121 }, {1059, 1038 }, {1072, 945},
|
||||
{1081, 849}, {1082, 749}, { 459, 734 }, { 502, 704 }, { 554, 696},
|
||||
{ 609, 698}, { 660, 707}, { 818, 688 }, { 874, 661 }, { 929, 646},
|
||||
{ 982, 653}, {1026, 682}, { 740, 771 }, { 748, 834 }, { 756, 897},
|
||||
{ 762, 960}, { 700, 998}, { 733, 1006 }, { 766, 1011 }, { 797, 999},
|
||||
{ 825, 987}, { 528, 796}, { 566, 766 }, { 617, 763 }, { 659, 794},
|
||||
{ 619, 808}, { 569, 812}, { 834, 777 }, { 870, 735 }, { 918, 729},
|
||||
{ 958, 750}, { 929, 773}, { 882, 780 }, { 652, 1102 }, { 701, 1079},
|
||||
{ 743, 1063}, { 774, 1068}, { 807, 1057 }, { 852, 1065 }, { 896, 1077},
|
||||
{ 860, 1117}, { 820, 1135}, { 783, 1141 }, { 751, 1140 }, { 706, 1130},
|
||||
{ 675, 1102}, { 743, 1094}, { 774, 1094 }, { 809, 1088 }, { 878, 1082}
|
||||
};
|
||||
std::vector<cv::Point2f> pts;
|
||||
cv::Rect rect(0, 0, 1500, 2000);
|
||||
cv::Subdiv2D subdiv(rect);
|
||||
for( int i = 0; i < 65; i++ )
|
||||
{
|
||||
cv::Point2f pt(points[i][0], points[i][1]);
|
||||
pts.push_back(pt);
|
||||
}
|
||||
|
||||
subdiv.insert(pts);
|
||||
|
||||
std::vector<cv::Vec6f> triangles;
|
||||
subdiv.getTriangleList(triangles);
|
||||
|
||||
int trig_cnt = 0;
|
||||
for( std::vector<cv::Vec6f>::const_iterator it = triangles.begin(); it != triangles.end(); it++, trig_cnt++ )
|
||||
{
|
||||
EXPECT_TRUE( (0 <= triangles.at(trig_cnt).val[0] && triangles.at(trig_cnt).val[0] < 1500) &&
|
||||
(0 <= triangles.at(trig_cnt).val[1] && triangles.at(trig_cnt).val[1] < 2000) &&
|
||||
(0 <= triangles.at(trig_cnt).val[2] && triangles.at(trig_cnt).val[2] < 1500) &&
|
||||
(0 <= triangles.at(trig_cnt).val[3] && triangles.at(trig_cnt).val[3] < 2000) &&
|
||||
(0 <= triangles.at(trig_cnt).val[4] && triangles.at(trig_cnt).val[4] < 1500) &&
|
||||
(0 <= triangles.at(trig_cnt).val[5] && triangles.at(trig_cnt).val[5] < 2000) );
|
||||
}
|
||||
EXPECT_EQ(trig_cnt, 105);
|
||||
}
|
||||
|
||||
}};
|
||||
428
3rdparty/opencv-4.5.4/modules/imgproc/test/test_templmatch.cpp
vendored
Normal file
428
3rdparty/opencv-4.5.4/modules/imgproc/test/test_templmatch.cpp
vendored
Normal file
@@ -0,0 +1,428 @@
|
||||
/*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.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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_TemplMatchTest : public cvtest::ArrayTest
|
||||
{
|
||||
public:
|
||||
CV_TemplMatchTest();
|
||||
|
||||
protected:
|
||||
int read_params( const cv::FileStorage& fs );
|
||||
void get_test_array_types_and_sizes( int test_case_idx, vector<vector<Size> >& sizes, vector<vector<int> >& types );
|
||||
void get_minmax_bounds( int i, int j, int type, Scalar& low, Scalar& high );
|
||||
double get_success_error_level( int test_case_idx, int i, int j );
|
||||
void run_func();
|
||||
void prepare_to_validation( int );
|
||||
|
||||
int max_template_size;
|
||||
int method;
|
||||
bool test_cpp;
|
||||
};
|
||||
|
||||
|
||||
CV_TemplMatchTest::CV_TemplMatchTest()
|
||||
{
|
||||
test_array[INPUT].push_back(NULL);
|
||||
test_array[INPUT].push_back(NULL);
|
||||
test_array[OUTPUT].push_back(NULL);
|
||||
test_array[REF_OUTPUT].push_back(NULL);
|
||||
element_wise_relative_error = false;
|
||||
max_template_size = 100;
|
||||
method = 0;
|
||||
test_cpp = false;
|
||||
}
|
||||
|
||||
|
||||
int CV_TemplMatchTest::read_params( const cv::FileStorage& fs )
|
||||
{
|
||||
int code = cvtest::ArrayTest::read_params( fs );
|
||||
if( code < 0 )
|
||||
return code;
|
||||
|
||||
read( find_param( fs, "max_template_size" ), max_template_size, max_template_size );
|
||||
max_template_size = cvtest::clipInt( max_template_size, 1, 100 );
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
void CV_TemplMatchTest::get_minmax_bounds( int i, int j, int type, Scalar& low, Scalar& high )
|
||||
{
|
||||
cvtest::ArrayTest::get_minmax_bounds( i, j, type, low, high );
|
||||
int depth = CV_MAT_DEPTH(type);
|
||||
if( depth == CV_32F )
|
||||
{
|
||||
low = Scalar::all(-10.);
|
||||
high = Scalar::all(10.);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CV_TemplMatchTest::get_test_array_types_and_sizes( int test_case_idx,
|
||||
vector<vector<Size> >& sizes, vector<vector<int> >& types )
|
||||
{
|
||||
RNG& rng = ts->get_rng();
|
||||
int depth = cvtest::randInt(rng) % 2, cn = cvtest::randInt(rng) & 1 ? 3 : 1;
|
||||
cvtest::ArrayTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
|
||||
depth = depth == 0 ? CV_8U : CV_32F;
|
||||
|
||||
types[INPUT][0] = types[INPUT][1] = CV_MAKETYPE(depth,cn);
|
||||
types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_32FC1;
|
||||
|
||||
sizes[INPUT][1].width = cvtest::randInt(rng)%MIN(sizes[INPUT][1].width,max_template_size) + 1;
|
||||
sizes[INPUT][1].height = cvtest::randInt(rng)%MIN(sizes[INPUT][1].height,max_template_size) + 1;
|
||||
sizes[OUTPUT][0].width = sizes[INPUT][0].width - sizes[INPUT][1].width + 1;
|
||||
sizes[OUTPUT][0].height = sizes[INPUT][0].height - sizes[INPUT][1].height + 1;
|
||||
sizes[REF_OUTPUT][0] = sizes[OUTPUT][0];
|
||||
|
||||
method = cvtest::randInt(rng)%6;
|
||||
test_cpp = (cvtest::randInt(rng) & 256) == 0;
|
||||
}
|
||||
|
||||
|
||||
double CV_TemplMatchTest::get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ )
|
||||
{
|
||||
if( test_mat[INPUT][1].depth() == CV_8U ||
|
||||
(method >= CV_TM_CCOEFF && test_mat[INPUT][1].cols*test_mat[INPUT][1].rows <= 2) )
|
||||
return 1e-2;
|
||||
else
|
||||
return 1e-3;
|
||||
}
|
||||
|
||||
|
||||
void CV_TemplMatchTest::run_func()
|
||||
{
|
||||
if(!test_cpp)
|
||||
cvMatchTemplate( test_array[INPUT][0], test_array[INPUT][1], test_array[OUTPUT][0], method );
|
||||
else
|
||||
{
|
||||
cv::Mat _out = cv::cvarrToMat(test_array[OUTPUT][0]);
|
||||
cv::matchTemplate(cv::cvarrToMat(test_array[INPUT][0]), cv::cvarrToMat(test_array[INPUT][1]), _out, method);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void cvTsMatchTemplate( const CvMat* img, const CvMat* templ, CvMat* result, int method )
|
||||
{
|
||||
int i, j, k, l;
|
||||
int depth = CV_MAT_DEPTH(img->type), cn = CV_MAT_CN(img->type);
|
||||
int width_n = templ->cols*cn, height = templ->rows;
|
||||
int a_step = img->step / CV_ELEM_SIZE(img->type & CV_MAT_DEPTH_MASK);
|
||||
int b_step = templ->step / CV_ELEM_SIZE(templ->type & CV_MAT_DEPTH_MASK);
|
||||
CvScalar b_mean = CV_STRUCT_INITIALIZER, b_sdv = CV_STRUCT_INITIALIZER;
|
||||
double b_denom = 1., b_sum2 = 0;
|
||||
int area = templ->rows*templ->cols;
|
||||
|
||||
cvAvgSdv(templ, &b_mean, &b_sdv);
|
||||
|
||||
for( i = 0; i < cn; i++ )
|
||||
b_sum2 += (b_sdv.val[i]*b_sdv.val[i] + b_mean.val[i]*b_mean.val[i])*area;
|
||||
|
||||
if( b_sdv.val[0]*b_sdv.val[0] + b_sdv.val[1]*b_sdv.val[1] +
|
||||
b_sdv.val[2]*b_sdv.val[2] + b_sdv.val[3]*b_sdv.val[3] < DBL_EPSILON &&
|
||||
method == CV_TM_CCOEFF_NORMED )
|
||||
{
|
||||
cvSet( result, cvScalarAll(1.) );
|
||||
return;
|
||||
}
|
||||
|
||||
if( method & 1 )
|
||||
{
|
||||
b_denom = 0;
|
||||
if( method != CV_TM_CCOEFF_NORMED )
|
||||
{
|
||||
b_denom = b_sum2;
|
||||
}
|
||||
else
|
||||
{
|
||||
for( i = 0; i < cn; i++ )
|
||||
b_denom += b_sdv.val[i]*b_sdv.val[i]*area;
|
||||
}
|
||||
b_denom = sqrt(b_denom);
|
||||
if( b_denom == 0 )
|
||||
b_denom = 1.;
|
||||
}
|
||||
|
||||
assert( CV_TM_SQDIFF <= method && method <= CV_TM_CCOEFF_NORMED );
|
||||
|
||||
for( i = 0; i < result->rows; i++ )
|
||||
{
|
||||
for( j = 0; j < result->cols; j++ )
|
||||
{
|
||||
Scalar a_sum(0), a_sum2(0);
|
||||
Scalar ccorr(0);
|
||||
double value = 0.;
|
||||
|
||||
if( depth == CV_8U )
|
||||
{
|
||||
const uchar* a = img->data.ptr + i*img->step + j*cn;
|
||||
const uchar* b = templ->data.ptr;
|
||||
|
||||
if( cn == 1 || method < CV_TM_CCOEFF )
|
||||
{
|
||||
for( k = 0; k < height; k++, a += a_step, b += b_step )
|
||||
for( l = 0; l < width_n; l++ )
|
||||
{
|
||||
ccorr.val[0] += a[l]*b[l];
|
||||
a_sum.val[0] += a[l];
|
||||
a_sum2.val[0] += a[l]*a[l];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( k = 0; k < height; k++, a += a_step, b += b_step )
|
||||
for( l = 0; l < width_n; l += 3 )
|
||||
{
|
||||
ccorr.val[0] += a[l]*b[l];
|
||||
ccorr.val[1] += a[l+1]*b[l+1];
|
||||
ccorr.val[2] += a[l+2]*b[l+2];
|
||||
a_sum.val[0] += a[l];
|
||||
a_sum.val[1] += a[l+1];
|
||||
a_sum.val[2] += a[l+2];
|
||||
a_sum2.val[0] += a[l]*a[l];
|
||||
a_sum2.val[1] += a[l+1]*a[l+1];
|
||||
a_sum2.val[2] += a[l+2]*a[l+2];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const float* a = (const float*)(img->data.ptr + i*img->step) + j*cn;
|
||||
const float* b = (const float*)templ->data.ptr;
|
||||
|
||||
if( cn == 1 || method < CV_TM_CCOEFF )
|
||||
{
|
||||
for( k = 0; k < height; k++, a += a_step, b += b_step )
|
||||
for( l = 0; l < width_n; l++ )
|
||||
{
|
||||
ccorr.val[0] += a[l]*b[l];
|
||||
a_sum.val[0] += a[l];
|
||||
a_sum2.val[0] += a[l]*a[l];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( k = 0; k < height; k++, a += a_step, b += b_step )
|
||||
for( l = 0; l < width_n; l += 3 )
|
||||
{
|
||||
ccorr.val[0] += a[l]*b[l];
|
||||
ccorr.val[1] += a[l+1]*b[l+1];
|
||||
ccorr.val[2] += a[l+2]*b[l+2];
|
||||
a_sum.val[0] += a[l];
|
||||
a_sum.val[1] += a[l+1];
|
||||
a_sum.val[2] += a[l+2];
|
||||
a_sum2.val[0] += a[l]*a[l];
|
||||
a_sum2.val[1] += a[l+1]*a[l+1];
|
||||
a_sum2.val[2] += a[l+2]*a[l+2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch( method )
|
||||
{
|
||||
case CV_TM_CCORR:
|
||||
case CV_TM_CCORR_NORMED:
|
||||
value = ccorr.val[0];
|
||||
break;
|
||||
case CV_TM_SQDIFF:
|
||||
case CV_TM_SQDIFF_NORMED:
|
||||
value = (a_sum2.val[0] + b_sum2 - 2*ccorr.val[0]);
|
||||
break;
|
||||
default:
|
||||
value = (ccorr.val[0] - a_sum.val[0]*b_mean.val[0]+
|
||||
ccorr.val[1] - a_sum.val[1]*b_mean.val[1]+
|
||||
ccorr.val[2] - a_sum.val[2]*b_mean.val[2]);
|
||||
}
|
||||
|
||||
if( method & 1 )
|
||||
{
|
||||
double denom;
|
||||
|
||||
// calc denominator
|
||||
if( method != CV_TM_CCOEFF_NORMED )
|
||||
{
|
||||
denom = a_sum2.val[0] + a_sum2.val[1] + a_sum2.val[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
denom = a_sum2.val[0] - (a_sum.val[0]*a_sum.val[0])/area;
|
||||
denom += a_sum2.val[1] - (a_sum.val[1]*a_sum.val[1])/area;
|
||||
denom += a_sum2.val[2] - (a_sum.val[2]*a_sum.val[2])/area;
|
||||
}
|
||||
denom = sqrt(MAX(denom,0))*b_denom;
|
||||
if( fabs(value) < denom )
|
||||
value /= denom;
|
||||
else if( fabs(value) < denom*1.125 )
|
||||
value = value > 0 ? 1 : -1;
|
||||
else
|
||||
value = method != CV_TM_SQDIFF_NORMED ? 0 : 1;
|
||||
}
|
||||
|
||||
((float*)(result->data.ptr + result->step*i))[j] = (float)value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CV_TemplMatchTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
{
|
||||
CvMat _input = cvMat(test_mat[INPUT][0]), _templ = cvMat(test_mat[INPUT][1]);
|
||||
CvMat _output = cvMat(test_mat[REF_OUTPUT][0]);
|
||||
cvTsMatchTemplate( &_input, &_templ, &_output, method );
|
||||
|
||||
//if( ts->get_current_test_info()->test_case_idx == 0 )
|
||||
/*{
|
||||
CvFileStorage* fs = cvOpenFileStorage( "_match_template.yml", 0, CV_STORAGE_WRITE );
|
||||
cvWrite( fs, "image", &test_mat[INPUT][0] );
|
||||
cvWrite( fs, "template", &test_mat[INPUT][1] );
|
||||
cvWrite( fs, "ref", &test_mat[REF_OUTPUT][0] );
|
||||
cvWrite( fs, "opencv", &test_mat[OUTPUT][0] );
|
||||
cvWriteInt( fs, "method", method );
|
||||
cvReleaseFileStorage( &fs );
|
||||
}*/
|
||||
|
||||
if( method >= CV_TM_CCOEFF )
|
||||
{
|
||||
// avoid numerical stability problems in singular cases (when the results are near to 0)
|
||||
const double delta = 10.;
|
||||
test_mat[REF_OUTPUT][0] += Scalar::all(delta);
|
||||
test_mat[OUTPUT][0] += Scalar::all(delta);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Imgproc_MatchTemplate, accuracy) { CV_TemplMatchTest test; test.safe_run(); }
|
||||
|
||||
}
|
||||
|
||||
TEST(Imgproc_MatchTemplate, bug_9597) {
|
||||
const uint8_t img[] = {
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 246, 246, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 246, 246, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 246, 246, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 246, 246, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 246,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 246, 246, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 246, 246, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 246, 246, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 246, 246, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 247, 247, 247, 247, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 247, 247, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245};
|
||||
const uint8_t tmpl[] = {
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245,
|
||||
245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245 };
|
||||
cv::Mat cvimg(cv::Size(61, 82), CV_8UC1, (void*)img, cv::Mat::AUTO_STEP);
|
||||
cv::Mat cvtmpl(cv::Size(17, 17), CV_8UC1, (void*)tmpl, cv::Mat::AUTO_STEP);
|
||||
cv::Mat result;
|
||||
cv::matchTemplate(cvimg, cvtmpl, result, CV_TM_SQDIFF);
|
||||
double minValue;
|
||||
cv::minMaxLoc(result, &minValue, NULL, NULL, NULL);
|
||||
ASSERT_GE(minValue, 0);
|
||||
}
|
||||
} // namespace
|
||||
278
3rdparty/opencv-4.5.4/modules/imgproc/test/test_templmatchmask.cpp
vendored
Normal file
278
3rdparty/opencv-4.5.4/modules/imgproc/test/test_templmatchmask.cpp
vendored
Normal file
@@ -0,0 +1,278 @@
|
||||
// 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"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
CV_ENUM(MatchTemplType, CV_TM_CCORR, CV_TM_CCORR_NORMED,
|
||||
CV_TM_SQDIFF, CV_TM_SQDIFF_NORMED,
|
||||
CV_TM_CCOEFF, CV_TM_CCOEFF_NORMED)
|
||||
|
||||
class Imgproc_MatchTemplateWithMask : public TestWithParam<std::tuple<MatType,MatType>>
|
||||
{
|
||||
protected:
|
||||
// Member functions inherited from ::testing::Test
|
||||
void SetUp() override;
|
||||
|
||||
// Matrices for test calculations (always CV_32)
|
||||
Mat img_;
|
||||
Mat templ_;
|
||||
Mat mask_;
|
||||
Mat templ_masked_;
|
||||
Mat img_roi_masked_;
|
||||
// Matrices for call to matchTemplate (have test type)
|
||||
Mat img_testtype_;
|
||||
Mat templ_testtype_;
|
||||
Mat mask_testtype_;
|
||||
Mat result_;
|
||||
|
||||
// Constants
|
||||
static const Size IMG_SIZE;
|
||||
static const Size TEMPL_SIZE;
|
||||
static const Point TEST_POINT;
|
||||
};
|
||||
|
||||
// Arbitraryly chosen test constants
|
||||
const Size Imgproc_MatchTemplateWithMask::IMG_SIZE(160, 100);
|
||||
const Size Imgproc_MatchTemplateWithMask::TEMPL_SIZE(21, 13);
|
||||
const Point Imgproc_MatchTemplateWithMask::TEST_POINT(8, 9);
|
||||
|
||||
void Imgproc_MatchTemplateWithMask::SetUp()
|
||||
{
|
||||
int type = std::get<0>(GetParam());
|
||||
int type_mask = std::get<1>(GetParam());
|
||||
|
||||
// Matrices are created with the depth to test (for the call to matchTemplate()), but are also
|
||||
// converted to CV_32 for the test calculations, because matchTemplate() also only operates on
|
||||
// and returns CV_32.
|
||||
img_testtype_.create(IMG_SIZE, type);
|
||||
templ_testtype_.create(TEMPL_SIZE, type);
|
||||
mask_testtype_.create(TEMPL_SIZE, type_mask);
|
||||
|
||||
randu(img_testtype_, 0, 10);
|
||||
randu(templ_testtype_, 0, 10);
|
||||
randu(mask_testtype_, 0, 5);
|
||||
|
||||
img_testtype_.convertTo(img_, CV_32F);
|
||||
templ_testtype_.convertTo(templ_, CV_32F);
|
||||
mask_testtype_.convertTo(mask_, CV_32F);
|
||||
if (CV_MAT_DEPTH(type_mask) == CV_8U)
|
||||
{
|
||||
// CV_8U masks are interpreted as binary masks
|
||||
mask_.setTo(Scalar::all(1), mask_ != 0);
|
||||
}
|
||||
if (mask_.channels() != templ_.channels())
|
||||
{
|
||||
std::vector<Mat> mask_channels(templ_.channels(), mask_);
|
||||
merge(mask_channels.data(), templ_.channels(), mask_);
|
||||
}
|
||||
|
||||
Rect roi(TEST_POINT, TEMPL_SIZE);
|
||||
img_roi_masked_ = img_(roi).mul(mask_);
|
||||
templ_masked_ = templ_.mul(mask_);
|
||||
}
|
||||
|
||||
TEST_P(Imgproc_MatchTemplateWithMask, CompareNaiveImplSQDIFF)
|
||||
{
|
||||
matchTemplate(img_testtype_, templ_testtype_, result_, CV_TM_SQDIFF, mask_testtype_);
|
||||
// Naive implementation for one point
|
||||
Mat temp = img_roi_masked_ - templ_masked_;
|
||||
Scalar temp_s = sum(temp.mul(temp));
|
||||
double val = temp_s[0] + temp_s[1] + temp_s[2] + temp_s[3];
|
||||
|
||||
EXPECT_NEAR(val, result_.at<float>(TEST_POINT), TEMPL_SIZE.area()*abs(val)*FLT_EPSILON);
|
||||
}
|
||||
|
||||
TEST_P(Imgproc_MatchTemplateWithMask, CompareNaiveImplSQDIFF_NORMED)
|
||||
{
|
||||
matchTemplate(img_testtype_, templ_testtype_, result_, CV_TM_SQDIFF_NORMED, mask_testtype_);
|
||||
// Naive implementation for one point
|
||||
Mat temp = img_roi_masked_ - templ_masked_;
|
||||
Scalar temp_s = sum(temp.mul(temp));
|
||||
double val = temp_s[0] + temp_s[1] + temp_s[2] + temp_s[3];
|
||||
|
||||
// Normalization
|
||||
temp_s = sum(templ_masked_.mul(templ_masked_));
|
||||
double norm = temp_s[0] + temp_s[1] + temp_s[2] + temp_s[3];
|
||||
temp_s = sum(img_roi_masked_.mul(img_roi_masked_));
|
||||
norm *= temp_s[0] + temp_s[1] + temp_s[2] + temp_s[3];
|
||||
norm = sqrt(norm);
|
||||
val /= norm;
|
||||
|
||||
EXPECT_NEAR(val, result_.at<float>(TEST_POINT), TEMPL_SIZE.area()*abs(val)*FLT_EPSILON);
|
||||
}
|
||||
|
||||
TEST_P(Imgproc_MatchTemplateWithMask, CompareNaiveImplCCORR)
|
||||
{
|
||||
matchTemplate(img_testtype_, templ_testtype_, result_, CV_TM_CCORR, mask_testtype_);
|
||||
// Naive implementation for one point
|
||||
Scalar temp_s = sum(templ_masked_.mul(img_roi_masked_));
|
||||
double val = temp_s[0] + temp_s[1] + temp_s[2] + temp_s[3];
|
||||
|
||||
EXPECT_NEAR(val, result_.at<float>(TEST_POINT), TEMPL_SIZE.area()*abs(val)*FLT_EPSILON);
|
||||
}
|
||||
|
||||
TEST_P(Imgproc_MatchTemplateWithMask, CompareNaiveImplCCORR_NORMED)
|
||||
{
|
||||
matchTemplate(img_testtype_, templ_testtype_, result_, CV_TM_CCORR_NORMED, mask_testtype_);
|
||||
// Naive implementation for one point
|
||||
Scalar temp_s = sum(templ_masked_.mul(img_roi_masked_));
|
||||
double val = temp_s[0] + temp_s[1] + temp_s[2] + temp_s[3];
|
||||
|
||||
// Normalization
|
||||
temp_s = sum(templ_masked_.mul(templ_masked_));
|
||||
double norm = temp_s[0] + temp_s[1] + temp_s[2] + temp_s[3];
|
||||
temp_s = sum(img_roi_masked_.mul(img_roi_masked_));
|
||||
norm *= temp_s[0] + temp_s[1] + temp_s[2] + temp_s[3];
|
||||
norm = sqrt(norm);
|
||||
val /= norm;
|
||||
|
||||
EXPECT_NEAR(val, result_.at<float>(TEST_POINT), TEMPL_SIZE.area()*abs(val)*FLT_EPSILON);
|
||||
}
|
||||
|
||||
TEST_P(Imgproc_MatchTemplateWithMask, CompareNaiveImplCCOEFF)
|
||||
{
|
||||
matchTemplate(img_testtype_, templ_testtype_, result_, CV_TM_CCOEFF, mask_testtype_);
|
||||
// Naive implementation for one point
|
||||
Scalar temp_s = sum(mask_);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (temp_s[i] != 0.0)
|
||||
temp_s[i] = 1.0 / temp_s[i];
|
||||
else
|
||||
temp_s[i] = 1.0;
|
||||
}
|
||||
Mat temp = mask_.clone(); temp = temp_s; // Workaround to multiply Mat by Scalar
|
||||
Mat temp2 = mask_.clone(); temp2 = sum(templ_masked_); // Workaround to multiply Mat by Scalar
|
||||
Mat templx = templ_masked_ - mask_.mul(temp).mul(temp2);
|
||||
temp2 = sum(img_roi_masked_); // Workaround to multiply Mat by Scalar
|
||||
Mat imgx = img_roi_masked_ - mask_.mul(temp).mul(temp2);
|
||||
temp_s = sum(templx.mul(imgx));
|
||||
double val = temp_s[0] + temp_s[1] + temp_s[2] + temp_s[3];
|
||||
|
||||
EXPECT_NEAR(val, result_.at<float>(TEST_POINT), TEMPL_SIZE.area()*abs(val)*FLT_EPSILON);
|
||||
}
|
||||
|
||||
TEST_P(Imgproc_MatchTemplateWithMask, CompareNaiveImplCCOEFF_NORMED)
|
||||
{
|
||||
matchTemplate(img_testtype_, templ_testtype_, result_, CV_TM_CCOEFF_NORMED, mask_testtype_);
|
||||
// Naive implementation for one point
|
||||
Scalar temp_s = sum(mask_);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (temp_s[i] != 0.0)
|
||||
temp_s[i] = 1.0 / temp_s[i];
|
||||
else
|
||||
temp_s[i] = 1.0;
|
||||
}
|
||||
Mat temp = mask_.clone(); temp = temp_s; // Workaround to multiply Mat by Scalar
|
||||
Mat temp2 = mask_.clone(); temp2 = sum(templ_masked_); // Workaround to multiply Mat by Scalar
|
||||
Mat templx = templ_masked_ - mask_.mul(temp).mul(temp2);
|
||||
temp2 = sum(img_roi_masked_); // Workaround to multiply Mat by Scalar
|
||||
Mat imgx = img_roi_masked_ - mask_.mul(temp).mul(temp2);
|
||||
temp_s = sum(templx.mul(imgx));
|
||||
double val = temp_s[0] + temp_s[1] + temp_s[2] + temp_s[3];
|
||||
|
||||
// Normalization
|
||||
temp_s = sum(templx.mul(templx));
|
||||
double norm = temp_s[0] + temp_s[1] + temp_s[2] + temp_s[3];
|
||||
temp_s = sum(imgx.mul(imgx));
|
||||
norm *= temp_s[0] + temp_s[1] + temp_s[2] + temp_s[3];
|
||||
norm = sqrt(norm);
|
||||
val /= norm;
|
||||
|
||||
EXPECT_NEAR(val, result_.at<float>(TEST_POINT), TEMPL_SIZE.area()*abs(val)*FLT_EPSILON);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(SingleChannelMask, Imgproc_MatchTemplateWithMask,
|
||||
Combine(
|
||||
Values(CV_32FC1, CV_32FC3, CV_8UC1, CV_8UC3),
|
||||
Values(CV_32FC1, CV_8UC1)));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(MultiChannelMask, Imgproc_MatchTemplateWithMask,
|
||||
Combine(
|
||||
Values(CV_32FC3, CV_8UC3),
|
||||
Values(CV_32FC3, CV_8UC3)));
|
||||
|
||||
class Imgproc_MatchTemplateWithMask2 : public TestWithParam<std::tuple<MatType,MatType,
|
||||
MatchTemplType>>
|
||||
{
|
||||
protected:
|
||||
// Member functions inherited from ::testing::Test
|
||||
void SetUp() override;
|
||||
|
||||
// Data members
|
||||
Mat img_;
|
||||
Mat templ_;
|
||||
Mat mask_;
|
||||
Mat result_withoutmask_;
|
||||
Mat result_withmask_;
|
||||
|
||||
// Constants
|
||||
static const Size IMG_SIZE;
|
||||
static const Size TEMPL_SIZE;
|
||||
};
|
||||
|
||||
// Arbitraryly chosen test constants
|
||||
const Size Imgproc_MatchTemplateWithMask2::IMG_SIZE(160, 100);
|
||||
const Size Imgproc_MatchTemplateWithMask2::TEMPL_SIZE(21, 13);
|
||||
|
||||
void Imgproc_MatchTemplateWithMask2::SetUp()
|
||||
{
|
||||
int type = std::get<0>(GetParam());
|
||||
int type_mask = std::get<1>(GetParam());
|
||||
|
||||
img_.create(IMG_SIZE, type);
|
||||
templ_.create(TEMPL_SIZE, type);
|
||||
mask_.create(TEMPL_SIZE, type_mask);
|
||||
|
||||
randu(img_, 0, 100);
|
||||
randu(templ_, 0, 100);
|
||||
|
||||
if (CV_MAT_DEPTH(type_mask) == CV_8U)
|
||||
{
|
||||
// CV_8U implies binary mask, so all nonzero values should work
|
||||
randu(mask_, 1, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
mask_ = Scalar(1, 1, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(Imgproc_MatchTemplateWithMask2, CompareWithAndWithoutMask)
|
||||
{
|
||||
int method = std::get<2>(GetParam());
|
||||
|
||||
matchTemplate(img_, templ_, result_withmask_, method, mask_);
|
||||
matchTemplate(img_, templ_, result_withoutmask_, method);
|
||||
|
||||
// Get maximum result for relative error calculation
|
||||
double min_val, max_val;
|
||||
minMaxLoc(abs(result_withmask_), &min_val, &max_val);
|
||||
|
||||
// Get maximum of absolute diff for comparison
|
||||
double mindiff, maxdiff;
|
||||
minMaxLoc(abs(result_withmask_ - result_withoutmask_), &mindiff, &maxdiff);
|
||||
|
||||
EXPECT_LT(maxdiff, max_val*TEMPL_SIZE.area()*FLT_EPSILON);
|
||||
}
|
||||
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(SingleChannelMask, Imgproc_MatchTemplateWithMask2,
|
||||
Combine(
|
||||
Values(CV_32FC1, CV_32FC3, CV_8UC1, CV_8UC3),
|
||||
Values(CV_32FC1, CV_8UC1),
|
||||
Values(CV_TM_SQDIFF, CV_TM_SQDIFF_NORMED, CV_TM_CCORR, CV_TM_CCORR_NORMED,
|
||||
CV_TM_CCOEFF, CV_TM_CCOEFF_NORMED)));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(MultiChannelMask, Imgproc_MatchTemplateWithMask2,
|
||||
Combine(
|
||||
Values(CV_32FC3, CV_8UC3),
|
||||
Values(CV_32FC3, CV_8UC3),
|
||||
Values(CV_TM_SQDIFF, CV_TM_SQDIFF_NORMED, CV_TM_CCORR, CV_TM_CCORR_NORMED,
|
||||
CV_TM_CCOEFF, CV_TM_CCOEFF_NORMED)));
|
||||
|
||||
}} // namespace
|
||||
514
3rdparty/opencv-4.5.4/modules/imgproc/test/test_thresh.cpp
vendored
Normal file
514
3rdparty/opencv-4.5.4/modules/imgproc/test/test_thresh.cpp
vendored
Normal file
@@ -0,0 +1,514 @@
|
||||
/*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.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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_ThreshTest : public cvtest::ArrayTest
|
||||
{
|
||||
public:
|
||||
CV_ThreshTest(int test_type = 0);
|
||||
|
||||
protected:
|
||||
void get_test_array_types_and_sizes( int test_case_idx, vector<vector<Size> >& sizes, vector<vector<int> >& types );
|
||||
double get_success_error_level( int test_case_idx, int i, int j );
|
||||
void run_func();
|
||||
void prepare_to_validation( int );
|
||||
|
||||
int thresh_type;
|
||||
double thresh_val;
|
||||
double max_val;
|
||||
int extra_type;
|
||||
};
|
||||
|
||||
|
||||
CV_ThreshTest::CV_ThreshTest(int test_type)
|
||||
{
|
||||
CV_Assert( (test_type & CV_THRESH_MASK) == 0 );
|
||||
test_array[INPUT].push_back(NULL);
|
||||
test_array[OUTPUT].push_back(NULL);
|
||||
test_array[REF_OUTPUT].push_back(NULL);
|
||||
optional_mask = false;
|
||||
element_wise_relative_error = true;
|
||||
extra_type = test_type;
|
||||
// Reduce number of test with automated thresholding
|
||||
if (extra_type != 0)
|
||||
test_case_count = 250;
|
||||
}
|
||||
|
||||
|
||||
void CV_ThreshTest::get_test_array_types_and_sizes( int test_case_idx,
|
||||
vector<vector<Size> >& sizes, vector<vector<int> >& types )
|
||||
{
|
||||
RNG& rng = ts->get_rng();
|
||||
int depth = cvtest::randInt(rng) % 5, cn = cvtest::randInt(rng) % 4 + 1;
|
||||
cvtest::ArrayTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
|
||||
depth = depth == 0 ? CV_8U : depth == 1 ? CV_16S : depth == 2 ? CV_16U : depth == 3 ? CV_32F : CV_64F;
|
||||
|
||||
if ( extra_type == CV_THRESH_OTSU )
|
||||
{
|
||||
depth = cvtest::randInt(rng) % 2 == 0 ? CV_8U : CV_16U;
|
||||
cn = 1;
|
||||
}
|
||||
|
||||
types[INPUT][0] = types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_MAKETYPE(depth,cn);
|
||||
thresh_type = cvtest::randInt(rng) % 5;
|
||||
|
||||
if( depth == CV_8U )
|
||||
{
|
||||
thresh_val = (cvtest::randReal(rng)*350. - 50.);
|
||||
max_val = (cvtest::randReal(rng)*350. - 50.);
|
||||
if( cvtest::randInt(rng)%4 == 0 )
|
||||
max_val = 255.f;
|
||||
}
|
||||
else if( depth == CV_16S )
|
||||
{
|
||||
double min_val = SHRT_MIN-100.f;
|
||||
max_val = SHRT_MAX+100.f;
|
||||
thresh_val = (cvtest::randReal(rng)*(max_val - min_val) + min_val);
|
||||
max_val = (cvtest::randReal(rng)*(max_val - min_val) + min_val);
|
||||
if( cvtest::randInt(rng)%4 == 0 )
|
||||
max_val = (double)SHRT_MAX;
|
||||
}
|
||||
else if( depth == CV_16U )
|
||||
{
|
||||
double min_val = -100.f;
|
||||
max_val = USHRT_MAX+100.f;
|
||||
thresh_val = (cvtest::randReal(rng)*(max_val - min_val) + min_val);
|
||||
max_val = (cvtest::randReal(rng)*(max_val - min_val) + min_val);
|
||||
if( cvtest::randInt(rng)%4 == 0 )
|
||||
max_val = (double)USHRT_MAX;
|
||||
}
|
||||
else
|
||||
{
|
||||
thresh_val = (cvtest::randReal(rng)*1000. - 500.);
|
||||
max_val = (cvtest::randReal(rng)*1000. - 500.);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double CV_ThreshTest::get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ )
|
||||
{
|
||||
return FLT_EPSILON*10;
|
||||
}
|
||||
|
||||
|
||||
void CV_ThreshTest::run_func()
|
||||
{
|
||||
cvThreshold( test_array[INPUT][0], test_array[OUTPUT][0],
|
||||
thresh_val, max_val, thresh_type | extra_type);
|
||||
}
|
||||
|
||||
|
||||
static double compute_otsu_thresh(const Mat& _src)
|
||||
{
|
||||
int depth = _src.depth();
|
||||
int width = _src.cols, height = _src.rows;
|
||||
const int N = 65536;
|
||||
std::vector<int> h(N, 0);
|
||||
int i, j;
|
||||
double mu = 0, scale = 1./(width*height);
|
||||
for(i = 0; i < height; ++i)
|
||||
{
|
||||
for(j = 0; j < width; ++j)
|
||||
{
|
||||
const int val = depth == CV_16UC1 ? (int)_src.at<ushort>(i, j) : (int)_src.at<uchar>(i,j);
|
||||
h[val]++;
|
||||
}
|
||||
}
|
||||
for( i = 0; i < N; i++ )
|
||||
{
|
||||
mu += i*(double)h[i];
|
||||
}
|
||||
|
||||
mu *= scale;
|
||||
double mu1 = 0, q1 = 0;
|
||||
double max_sigma = 0, max_val = 0;
|
||||
|
||||
for( i = 0; i < N; i++ )
|
||||
{
|
||||
double p_i, q2, mu2, sigma;
|
||||
|
||||
p_i = h[i]*scale;
|
||||
mu1 *= q1;
|
||||
q1 += p_i;
|
||||
q2 = 1. - q1;
|
||||
|
||||
if( std::min(q1,q2) < FLT_EPSILON || std::max(q1,q2) > 1. - FLT_EPSILON )
|
||||
continue;
|
||||
|
||||
mu1 = (mu1 + i*p_i)/q1;
|
||||
mu2 = (mu - q1*mu1)/q2;
|
||||
sigma = q1*q2*(mu1 - mu2)*(mu1 - mu2);
|
||||
if( sigma > max_sigma )
|
||||
{
|
||||
max_sigma = sigma;
|
||||
max_val = i;
|
||||
}
|
||||
}
|
||||
|
||||
return max_val;
|
||||
}
|
||||
|
||||
static void test_threshold( const Mat& _src, Mat& _dst,
|
||||
double thresh, double maxval, int thresh_type, int extra_type )
|
||||
{
|
||||
int i, j;
|
||||
int depth = _src.depth(), cn = _src.channels();
|
||||
int width_n = _src.cols*cn, height = _src.rows;
|
||||
int ithresh = cvFloor(thresh);
|
||||
int imaxval, ithresh2;
|
||||
if (extra_type == CV_THRESH_OTSU)
|
||||
{
|
||||
thresh = compute_otsu_thresh(_src);
|
||||
ithresh = cvFloor(thresh);
|
||||
}
|
||||
|
||||
if( depth == CV_8U )
|
||||
{
|
||||
ithresh2 = saturate_cast<uchar>(ithresh);
|
||||
imaxval = saturate_cast<uchar>(maxval);
|
||||
}
|
||||
else if( depth == CV_16S )
|
||||
{
|
||||
ithresh2 = saturate_cast<short>(ithresh);
|
||||
imaxval = saturate_cast<short>(maxval);
|
||||
}
|
||||
else if( depth == CV_16U )
|
||||
{
|
||||
ithresh2 = saturate_cast<ushort>(ithresh);
|
||||
imaxval = saturate_cast<ushort>(maxval);
|
||||
}
|
||||
else
|
||||
{
|
||||
ithresh2 = cvRound(ithresh);
|
||||
imaxval = cvRound(maxval);
|
||||
}
|
||||
|
||||
CV_Assert( depth == CV_8U || depth == CV_16S || depth == CV_16U || depth == CV_32F || depth == CV_64F );
|
||||
|
||||
switch( thresh_type )
|
||||
{
|
||||
case CV_THRESH_BINARY:
|
||||
for( i = 0; i < height; i++ )
|
||||
{
|
||||
if( depth == CV_8U )
|
||||
{
|
||||
const uchar* src = _src.ptr<uchar>(i);
|
||||
uchar* dst = _dst.ptr<uchar>(i);
|
||||
for( j = 0; j < width_n; j++ )
|
||||
dst[j] = (uchar)(src[j] > ithresh ? imaxval : 0);
|
||||
}
|
||||
else if( depth == CV_16S )
|
||||
{
|
||||
const short* src = _src.ptr<short>(i);
|
||||
short* dst = _dst.ptr<short>(i);
|
||||
for( j = 0; j < width_n; j++ )
|
||||
dst[j] = (short)(src[j] > ithresh ? imaxval : 0);
|
||||
}
|
||||
else if( depth == CV_16U )
|
||||
{
|
||||
const ushort* src = _src.ptr<ushort>(i);
|
||||
ushort* dst = _dst.ptr<ushort>(i);
|
||||
for( j = 0; j < width_n; j++ )
|
||||
dst[j] = (ushort)(src[j] > ithresh ? imaxval : 0);
|
||||
}
|
||||
else if( depth == CV_32F )
|
||||
{
|
||||
const float* src = _src.ptr<float>(i);
|
||||
float* dst = _dst.ptr<float>(i);
|
||||
for( j = 0; j < width_n; j++ )
|
||||
dst[j] = (float)(src[j] > thresh ? maxval : 0.f);
|
||||
}
|
||||
else
|
||||
{
|
||||
const double* src = _src.ptr<double>(i);
|
||||
double* dst = _dst.ptr<double>(i);
|
||||
for( j = 0; j < width_n; j++ )
|
||||
dst[j] = src[j] > thresh ? maxval : 0.0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CV_THRESH_BINARY_INV:
|
||||
for( i = 0; i < height; i++ )
|
||||
{
|
||||
if( depth == CV_8U )
|
||||
{
|
||||
const uchar* src = _src.ptr<uchar>(i);
|
||||
uchar* dst = _dst.ptr<uchar>(i);
|
||||
for( j = 0; j < width_n; j++ )
|
||||
dst[j] = (uchar)(src[j] > ithresh ? 0 : imaxval);
|
||||
}
|
||||
else if( depth == CV_16S )
|
||||
{
|
||||
const short* src = _src.ptr<short>(i);
|
||||
short* dst = _dst.ptr<short>(i);
|
||||
for( j = 0; j < width_n; j++ )
|
||||
dst[j] = (short)(src[j] > ithresh ? 0 : imaxval);
|
||||
}
|
||||
else if( depth == CV_16U )
|
||||
{
|
||||
const ushort* src = _src.ptr<ushort>(i);
|
||||
ushort* dst = _dst.ptr<ushort>(i);
|
||||
for( j = 0; j < width_n; j++ )
|
||||
dst[j] = (ushort)(src[j] > ithresh ? 0 : imaxval);
|
||||
}
|
||||
else if( depth == CV_32F )
|
||||
{
|
||||
const float* src = _src.ptr<float>(i);
|
||||
float* dst = _dst.ptr<float>(i);
|
||||
for( j = 0; j < width_n; j++ )
|
||||
dst[j] = (float)(src[j] > thresh ? 0.f : maxval);
|
||||
}
|
||||
else
|
||||
{
|
||||
const double* src = _src.ptr<double>(i);
|
||||
double* dst = _dst.ptr<double>(i);
|
||||
for( j = 0; j < width_n; j++ )
|
||||
dst[j] = src[j] > thresh ? 0.0 : maxval;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CV_THRESH_TRUNC:
|
||||
for( i = 0; i < height; i++ )
|
||||
{
|
||||
if( depth == CV_8U )
|
||||
{
|
||||
const uchar* src = _src.ptr<uchar>(i);
|
||||
uchar* dst = _dst.ptr<uchar>(i);
|
||||
for( j = 0; j < width_n; j++ )
|
||||
{
|
||||
int s = src[j];
|
||||
dst[j] = (uchar)(s > ithresh ? ithresh2 : s);
|
||||
}
|
||||
}
|
||||
else if( depth == CV_16S )
|
||||
{
|
||||
const short* src = _src.ptr<short>(i);
|
||||
short* dst = _dst.ptr<short>(i);
|
||||
for( j = 0; j < width_n; j++ )
|
||||
{
|
||||
int s = src[j];
|
||||
dst[j] = (short)(s > ithresh ? ithresh2 : s);
|
||||
}
|
||||
}
|
||||
else if( depth == CV_16U )
|
||||
{
|
||||
const ushort* src = _src.ptr<ushort>(i);
|
||||
ushort* dst = _dst.ptr<ushort>(i);
|
||||
for( j = 0; j < width_n; j++ )
|
||||
{
|
||||
int s = src[j];
|
||||
dst[j] = (ushort)(s > ithresh ? ithresh2 : s);
|
||||
}
|
||||
}
|
||||
else if( depth == CV_32F )
|
||||
{
|
||||
const float* src = _src.ptr<float>(i);
|
||||
float* dst = _dst.ptr<float>(i);
|
||||
for( j = 0; j < width_n; j++ )
|
||||
{
|
||||
float s = src[j];
|
||||
dst[j] = (float)(s > thresh ? thresh : s);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const double* src = _src.ptr<double>(i);
|
||||
double* dst = _dst.ptr<double>(i);
|
||||
for( j = 0; j < width_n; j++ )
|
||||
{
|
||||
double s = src[j];
|
||||
dst[j] = s > thresh ? thresh : s;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CV_THRESH_TOZERO:
|
||||
for( i = 0; i < height; i++ )
|
||||
{
|
||||
if( depth == CV_8U )
|
||||
{
|
||||
const uchar* src = _src.ptr<uchar>(i);
|
||||
uchar* dst = _dst.ptr<uchar>(i);
|
||||
for( j = 0; j < width_n; j++ )
|
||||
{
|
||||
int s = src[j];
|
||||
dst[j] = (uchar)(s > ithresh ? s : 0);
|
||||
}
|
||||
}
|
||||
else if( depth == CV_16S )
|
||||
{
|
||||
const short* src = _src.ptr<short>(i);
|
||||
short* dst = _dst.ptr<short>(i);
|
||||
for( j = 0; j < width_n; j++ )
|
||||
{
|
||||
int s = src[j];
|
||||
dst[j] = (short)(s > ithresh ? s : 0);
|
||||
}
|
||||
}
|
||||
else if( depth == CV_16U )
|
||||
{
|
||||
const ushort* src = _src.ptr<ushort>(i);
|
||||
ushort* dst = _dst.ptr<ushort>(i);
|
||||
for( j = 0; j < width_n; j++ )
|
||||
{
|
||||
int s = src[j];
|
||||
dst[j] = (ushort)(s > ithresh ? s : 0);
|
||||
}
|
||||
}
|
||||
else if( depth == CV_32F )
|
||||
{
|
||||
const float* src = _src.ptr<float>(i);
|
||||
float* dst = _dst.ptr<float>(i);
|
||||
for( j = 0; j < width_n; j++ )
|
||||
{
|
||||
float s = src[j];
|
||||
dst[j] = s > thresh ? s : 0.f;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const double* src = _src.ptr<double>(i);
|
||||
double* dst = _dst.ptr<double>(i);
|
||||
for( j = 0; j < width_n; j++ )
|
||||
{
|
||||
double s = src[j];
|
||||
dst[j] = s > thresh ? s : 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CV_THRESH_TOZERO_INV:
|
||||
for( i = 0; i < height; i++ )
|
||||
{
|
||||
if( depth == CV_8U )
|
||||
{
|
||||
const uchar* src = _src.ptr<uchar>(i);
|
||||
uchar* dst = _dst.ptr<uchar>(i);
|
||||
for( j = 0; j < width_n; j++ )
|
||||
{
|
||||
int s = src[j];
|
||||
dst[j] = (uchar)(s > ithresh ? 0 : s);
|
||||
}
|
||||
}
|
||||
else if( depth == CV_16S )
|
||||
{
|
||||
const short* src = _src.ptr<short>(i);
|
||||
short* dst = _dst.ptr<short>(i);
|
||||
for( j = 0; j < width_n; j++ )
|
||||
{
|
||||
int s = src[j];
|
||||
dst[j] = (short)(s > ithresh ? 0 : s);
|
||||
}
|
||||
}
|
||||
else if( depth == CV_16U )
|
||||
{
|
||||
const ushort* src = _src.ptr<ushort>(i);
|
||||
ushort* dst = _dst.ptr<ushort>(i);
|
||||
for( j = 0; j < width_n; j++ )
|
||||
{
|
||||
int s = src[j];
|
||||
dst[j] = (ushort)(s > ithresh ? 0 : s);
|
||||
}
|
||||
}
|
||||
else if (depth == CV_32F)
|
||||
{
|
||||
const float* src = _src.ptr<float>(i);
|
||||
float* dst = _dst.ptr<float>(i);
|
||||
for( j = 0; j < width_n; j++ )
|
||||
{
|
||||
float s = src[j];
|
||||
dst[j] = s > thresh ? 0.f : s;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const double* src = _src.ptr<double>(i);
|
||||
double* dst = _dst.ptr<double>(i);
|
||||
for( j = 0; j < width_n; j++ )
|
||||
{
|
||||
double s = src[j];
|
||||
dst[j] = s > thresh ? 0.0 : s;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CV_ThreshTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
{
|
||||
test_threshold( test_mat[INPUT][0], test_mat[REF_OUTPUT][0],
|
||||
thresh_val, max_val, thresh_type, extra_type );
|
||||
}
|
||||
|
||||
TEST(Imgproc_Threshold, accuracy) { CV_ThreshTest test; test.safe_run(); }
|
||||
TEST(Imgproc_Threshold, accuracyOtsu) { CV_ThreshTest test(CV_THRESH_OTSU); test.safe_run(); }
|
||||
|
||||
BIGDATA_TEST(Imgproc_Threshold, huge)
|
||||
{
|
||||
Mat m(65000, 40000, CV_8U);
|
||||
ASSERT_FALSE(m.isContinuous());
|
||||
|
||||
uint64 i, n = (uint64)m.rows*m.cols;
|
||||
for( i = 0; i < n; i++ )
|
||||
m.data[i] = (uchar)(i & 255);
|
||||
|
||||
cv::threshold(m, m, 127, 255, cv::THRESH_BINARY);
|
||||
int nz = cv::countNonZero(m); // FIXIT 'int' is not enough here (overflow is possible with other inputs)
|
||||
ASSERT_EQ((uint64)nz, n / 2);
|
||||
}
|
||||
|
||||
TEST(Imgproc_Threshold, regression_THRESH_TOZERO_IPP_16085)
|
||||
{
|
||||
Size sz(16, 16);
|
||||
Mat input(sz, CV_32F, Scalar::all(2));
|
||||
Mat result;
|
||||
cv::threshold(input, result, 2.0, 0.0, THRESH_TOZERO);
|
||||
EXPECT_EQ(0, cv::norm(result, NORM_INF));
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
130
3rdparty/opencv-4.5.4/modules/imgproc/test/test_watershed.cpp
vendored
Normal file
130
3rdparty/opencv-4.5.4/modules/imgproc/test/test_watershed.cpp
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
/*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"
|
||||
|
||||
#if 0
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
class CV_WatershedTest : public cvtest::BaseTest
|
||||
{
|
||||
public:
|
||||
CV_WatershedTest();
|
||||
~CV_WatershedTest();
|
||||
protected:
|
||||
void run(int);
|
||||
};
|
||||
|
||||
CV_WatershedTest::CV_WatershedTest() {}
|
||||
CV_WatershedTest::~CV_WatershedTest() {}
|
||||
|
||||
void CV_WatershedTest::run( int /* start_from */)
|
||||
{
|
||||
string exp_path = string(ts->get_data_path()) + "watershed/wshed_exp.png";
|
||||
Mat exp = imread(exp_path, 0);
|
||||
Mat orig = imread(string(ts->get_data_path()) + "inpaint/orig.png");
|
||||
FileStorage fs(string(ts->get_data_path()) + "watershed/comp.xml", FileStorage::READ);
|
||||
|
||||
if (orig.empty() || !fs.isOpened())
|
||||
{
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );
|
||||
return;
|
||||
}
|
||||
|
||||
CvSeq* cnts = (CvSeq*)fs["contours"].readObj();
|
||||
|
||||
Mat markers(orig.size(), CV_32SC1);
|
||||
markers = Scalar(0);
|
||||
IplImage iplmrks = cvIplImage(markers);
|
||||
|
||||
vector<unsigned char> colors(1);
|
||||
for(int i = 0; cnts != 0; cnts = cnts->h_next, ++i )
|
||||
{
|
||||
cvDrawContours( &iplmrks, cnts, cvScalar(Scalar::all(i + 1)), cvScalar(Scalar::all(i + 1)), -1, CV_FILLED);
|
||||
Point* p = (Point*)cvGetSeqElem(cnts, 0);
|
||||
|
||||
//expected image was added with 1 in order to save to png
|
||||
//so now we subtract 1 to get real color
|
||||
if(!exp.empty())
|
||||
colors.push_back(exp.ptr(p->y)[p->x] - 1);
|
||||
}
|
||||
fs.release();
|
||||
const int compNum = (int)(colors.size() - 1);
|
||||
|
||||
watershed(orig, markers);
|
||||
|
||||
for(int j = 0; j < markers.rows; ++j)
|
||||
{
|
||||
int* line = markers.ptr<int>(j);
|
||||
for(int i = 0; i < markers.cols; ++i)
|
||||
{
|
||||
int& pixel = line[i];
|
||||
|
||||
if (pixel == -1) // border
|
||||
continue;
|
||||
|
||||
if (pixel <= 0 || pixel > compNum)
|
||||
continue; // bad result, doing nothing and going to get error latter;
|
||||
|
||||
// repaint in saved color to compare with expected;
|
||||
if(!exp.empty())
|
||||
pixel = colors[pixel];
|
||||
}
|
||||
}
|
||||
|
||||
Mat markers8U;
|
||||
markers.convertTo(markers8U, CV_8U, 1, 1);
|
||||
|
||||
if( exp.empty() || orig.size() != exp.size() )
|
||||
{
|
||||
imwrite(exp_path, markers8U);
|
||||
exp = markers8U;
|
||||
}
|
||||
|
||||
ASSERT_EQ(0, cvtest::norm(markers8U, exp, NORM_INF));
|
||||
}
|
||||
|
||||
TEST(Imgproc_Watershed, regression) { CV_WatershedTest test; test.safe_run(); }
|
||||
|
||||
}} // namespace
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user