This source file includes following definitions.
- PARAM_TEST_CASE
- OCL_TEST_P
- OCL_TEST_P
- OCL_TEST_P
- OCL_TEST_P
- OCL_TEST_P
- OCL_TEST_P
- OCL_TEST_P
- IMPLEMENT_PARAM_CLASS
- OCL_TEST_P
#include "../test_precomp.hpp"
#include "cvconfig.h"
#include "opencv2/ts/ocl_test.hpp"
#ifdef HAVE_OPENCL
namespace cvtest {
namespace ocl {
PARAM_TEST_CASE(FilterTestBase, MatType,
int,
Size,
BorderType,
double,
bool,
int)
{
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);
}
};
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();
}
}
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();
}
}
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, 0, borderType));
OCL_ON(cv::Sobel(usrc_roi, udst_roi, -1, dx, dy, ksize, scale, 0, borderType));
Near();
}
}
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, 0, borderType));
OCL_ON(cv::Scharr(usrc_roi, udst_roi, -1, dx, dy, scale, 0, borderType));
Near();
}
}
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 ? 7e-5 : 1, false);
}
}
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, 3);
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();
}
}
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, 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();
}
}
IMPLEMENT_PARAM_CLASS(MorphOp, int)
PARAM_TEST_CASE(MorphologyEx, MatType,
int,
MorphOp,
int,
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
)
#define FILTER_BORDER_SET_NO_WRAP_NO_ISOLATED \
Values((BorderType)BORDER_CONSTANT, (BorderType)BORDER_REPLICATE, (BorderType)BORDER_REFLECT, (BorderType)BORDER_REFLECT_101
)
#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),
Values(Size(0, 0)),
FILTER_BORDER_SET_NO_ISOLATED,
Values(0.0),
Bool(),
Values(1, 4)));
OCL_INSTANTIATE_TEST_CASE_P(Filter, LaplacianTest, Combine(
FILTER_TYPES,
Values(1, 3, 5),
Values(Size(0, 0)),
FILTER_BORDER_SET_NO_WRAP_NO_ISOLATED,
Values(1.0, 0.2, 3.0),
Bool(),
Values(1)));
OCL_INSTANTIATE_TEST_CASE_P(Filter, SobelTest, Combine(
FILTER_TYPES,
Values(3, 5),
Values(Size(1, 0), Size(1, 1), Size(2, 0), Size(2, 1)),
FILTER_BORDER_SET_NO_WRAP_NO_ISOLATED,
Values(0.0),
Bool(),
Values(1)));
OCL_INSTANTIATE_TEST_CASE_P(Filter, ScharrTest, Combine(
FILTER_TYPES,
Values(0),
Values(Size(0, 1), Size(1, 0)),
FILTER_BORDER_SET_NO_WRAP_NO_ISOLATED,
Values(1.0, 0.2),
Bool(),
Values(1)));
OCL_INSTANTIATE_TEST_CASE_P(Filter, GaussianBlurTest, Combine(
FILTER_TYPES,
Values(3, 5),
Values(Size(0, 0)),
FILTER_BORDER_SET_NO_WRAP_NO_ISOLATED,
Values(0.0),
Bool(),
Values(1)));
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, 3, 5, 7),
Values(Size(0, 0)),
Values((BorderType)BORDER_CONSTANT),
Values(1.0, 2.0, 3.0),
Bool(),
Values(1)));
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),
Values(Size(0, 0)),
Values((BorderType)BORDER_CONSTANT),
Values(1.0, 2.0, 3.0),
Bool(),
Values(1)));
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),
Values((MorphOp)MORPH_OPEN, (MorphOp)MORPH_CLOSE, (MorphOp)MORPH_GRADIENT, (MorphOp)MORPH_TOPHAT, (MorphOp)MORPH_BLACKHAT),
Values(1, 2, 3),
Bool()));
} }
#endif