further simplify the logics in filter tests
This commit is contained in:
parent
1a53e2cfb2
commit
35c6860f06
@ -116,6 +116,19 @@ PARAM_TEST_CASE(FilterTestBase,
|
|||||||
gmat1 = mat1_roi;
|
gmat1 = mat1_roi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Init(int mat_type)
|
||||||
|
{
|
||||||
|
cv::Size size(MWIDTH, MHEIGHT);
|
||||||
|
mat1 = randomMat(size, mat_type, 5, 16);
|
||||||
|
dst = randomMat(size, mat_type, 5, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Near(double threshold)
|
||||||
|
{
|
||||||
|
cv::Mat cpu_dst;
|
||||||
|
gdst_whole.download(cpu_dst);
|
||||||
|
EXPECT_MAT_NEAR(dst, cpu_dst, threshold, "");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -131,12 +144,7 @@ struct Blur : FilterTestBase
|
|||||||
type = GET_PARAM(0);
|
type = GET_PARAM(0);
|
||||||
ksize = GET_PARAM(1);
|
ksize = GET_PARAM(1);
|
||||||
bordertype = GET_PARAM(3);
|
bordertype = GET_PARAM(3);
|
||||||
|
Init(type);
|
||||||
cv::RNG &rng = TS::ptr()->get_rng();
|
|
||||||
cv::Size size(MWIDTH, MHEIGHT);
|
|
||||||
|
|
||||||
mat1 = randomMat(rng, size, type, 5, 16, false);
|
|
||||||
dst = randomMat(rng, size, type, 5, 16, false);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -145,20 +153,13 @@ TEST_P(Blur, Mat)
|
|||||||
for(int j = 0; j < LOOP_TIMES; j++)
|
for(int j = 0; j < LOOP_TIMES; j++)
|
||||||
{
|
{
|
||||||
random_roi();
|
random_roi();
|
||||||
|
|
||||||
cv::blur(mat1_roi, dst_roi, ksize, Point(-1, -1), bordertype);
|
cv::blur(mat1_roi, dst_roi, ksize, Point(-1, -1), bordertype);
|
||||||
cv::ocl::blur(gmat1, gdst, ksize, Point(-1, -1), bordertype);
|
cv::ocl::blur(gmat1, gdst, ksize, Point(-1, -1), bordertype);
|
||||||
|
Near(1.0);
|
||||||
cv::Mat cpu_dst;
|
|
||||||
gdst_whole.download(cpu_dst);
|
|
||||||
|
|
||||||
EXPECT_MAT_NEAR(dst, cpu_dst, 1.0, "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//Laplacian
|
//Laplacian
|
||||||
struct Laplacian : FilterTestBase
|
struct Laplacian : FilterTestBase
|
||||||
@ -170,15 +171,8 @@ struct Laplacian : FilterTestBase
|
|||||||
{
|
{
|
||||||
type = GET_PARAM(0);
|
type = GET_PARAM(0);
|
||||||
ksize = GET_PARAM(1);
|
ksize = GET_PARAM(1);
|
||||||
|
Init(type);
|
||||||
cv::RNG &rng = TS::ptr()->get_rng();
|
|
||||||
cv::Size size(MWIDTH, MHEIGHT);
|
|
||||||
|
|
||||||
mat1 = randomMat(rng, size, type, 5, 16, false);
|
|
||||||
dst = randomMat(rng, size, type, 5, 16, false);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_P(Laplacian, Accuracy)
|
TEST_P(Laplacian, Accuracy)
|
||||||
@ -186,14 +180,9 @@ TEST_P(Laplacian, Accuracy)
|
|||||||
for(int j = 0; j < LOOP_TIMES; j++)
|
for(int j = 0; j < LOOP_TIMES; j++)
|
||||||
{
|
{
|
||||||
random_roi();
|
random_roi();
|
||||||
|
|
||||||
cv::Laplacian(mat1_roi, dst_roi, -1, ksize.width, 1);
|
cv::Laplacian(mat1_roi, dst_roi, -1, ksize.width, 1);
|
||||||
cv::ocl::Laplacian(gmat1, gdst, -1, ksize.width, 1);
|
cv::ocl::Laplacian(gmat1, gdst, -1, ksize.width, 1);
|
||||||
|
Near(1e-5);
|
||||||
cv::Mat cpu_dst;
|
|
||||||
gdst_whole.download(cpu_dst);
|
|
||||||
|
|
||||||
EXPECT_MAT_NEAR(dst, cpu_dst, 1e-5, "");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,45 +202,28 @@ struct ErodeDilate : FilterTestBase
|
|||||||
{
|
{
|
||||||
type = GET_PARAM(0);
|
type = GET_PARAM(0);
|
||||||
iterations = GET_PARAM(3);
|
iterations = GET_PARAM(3);
|
||||||
|
Init(type);
|
||||||
cv::RNG &rng = TS::ptr()->get_rng();
|
|
||||||
cv::Size size(MWIDTH, MHEIGHT);
|
|
||||||
|
|
||||||
mat1 = randomMat(rng, size, type, 5, 16, false);
|
|
||||||
dst = randomMat(rng, size, type, 5, 16, false);
|
|
||||||
// rng.fill(kernel, cv::RNG::UNIFORM, cv::Scalar::all(0), cv::Scalar::all(3));
|
// rng.fill(kernel, cv::RNG::UNIFORM, cv::Scalar::all(0), cv::Scalar::all(3));
|
||||||
kernel = randomMat(rng, Size(3, 3), CV_8UC1, 0, 3, false);
|
kernel = randomMat(Size(3, 3), CV_8UC1, 0, 3);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// erode
|
|
||||||
|
|
||||||
TEST_P(ErodeDilate, Mat)
|
TEST_P(ErodeDilate, Mat)
|
||||||
{
|
{
|
||||||
for(int j = 0; j < LOOP_TIMES; j++)
|
for(int j = 0; j < LOOP_TIMES; j++)
|
||||||
{
|
{
|
||||||
random_roi();
|
random_roi();
|
||||||
|
|
||||||
cv::erode(mat1_roi, dst_roi, kernel, Point(-1, -1), iterations);
|
cv::erode(mat1_roi, dst_roi, kernel, Point(-1, -1), iterations);
|
||||||
cv::ocl::erode(gmat1, gdst, kernel, Point(-1, -1), iterations);
|
cv::ocl::erode(gmat1, gdst, kernel, Point(-1, -1), iterations);
|
||||||
|
Near(1e-5);
|
||||||
cv::Mat cpu_dst;
|
|
||||||
gdst_whole.download(cpu_dst);
|
|
||||||
|
|
||||||
EXPECT_MAT_NEAR(dst, cpu_dst, 1e-5, "");
|
|
||||||
}
|
}
|
||||||
for(int j = 0; j < LOOP_TIMES; j++)
|
for(int j = 0; j < LOOP_TIMES; j++)
|
||||||
{
|
{
|
||||||
random_roi();
|
random_roi();
|
||||||
cv::dilate(mat1_roi, dst_roi, kernel, Point(-1, -1), iterations);
|
cv::dilate(mat1_roi, dst_roi, kernel, Point(-1, -1), iterations);
|
||||||
cv::ocl::dilate(gmat1, gdst, kernel, Point(-1, -1), iterations);
|
cv::ocl::dilate(gmat1, gdst, kernel, Point(-1, -1), iterations);
|
||||||
|
Near(1e-5);
|
||||||
cv::Mat cpu_dst;
|
|
||||||
gdst_whole.download(cpu_dst);
|
|
||||||
|
|
||||||
EXPECT_MAT_NEAR(dst, cpu_dst, 1e-5, "");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,15 +244,8 @@ struct Sobel : FilterTestBase
|
|||||||
dx = s.width;
|
dx = s.width;
|
||||||
dy = s.height;
|
dy = s.height;
|
||||||
bordertype = GET_PARAM(3);
|
bordertype = GET_PARAM(3);
|
||||||
|
Init(type);
|
||||||
|
|
||||||
cv::RNG &rng = TS::ptr()->get_rng();
|
|
||||||
cv::Size size(MWIDTH, MHEIGHT);
|
|
||||||
|
|
||||||
mat1 = randomMat(rng, size, type, 5, 16, false);
|
|
||||||
dst = randomMat(rng, size, type, 5, 16, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_P(Sobel, Mat)
|
TEST_P(Sobel, Mat)
|
||||||
@ -288,16 +253,10 @@ TEST_P(Sobel, Mat)
|
|||||||
for(int j = 0; j < LOOP_TIMES; j++)
|
for(int j = 0; j < LOOP_TIMES; j++)
|
||||||
{
|
{
|
||||||
random_roi();
|
random_roi();
|
||||||
|
|
||||||
cv::Sobel(mat1_roi, dst_roi, -1, dx, dy, ksize, /*scale*/0.00001,/*delta*/0, bordertype);
|
cv::Sobel(mat1_roi, dst_roi, -1, dx, dy, ksize, /*scale*/0.00001,/*delta*/0, bordertype);
|
||||||
cv::ocl::Sobel(gmat1, gdst, -1, dx, dy, ksize,/*scale*/0.00001,/*delta*/0, bordertype);
|
cv::ocl::Sobel(gmat1, gdst, -1, dx, dy, ksize,/*scale*/0.00001,/*delta*/0, bordertype);
|
||||||
|
Near(1);
|
||||||
cv::Mat cpu_dst;
|
|
||||||
gdst_whole.download(cpu_dst);
|
|
||||||
|
|
||||||
EXPECT_MAT_NEAR(dst, cpu_dst, 1, "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -315,17 +274,8 @@ struct Scharr : FilterTestBase
|
|||||||
dx = s.width;
|
dx = s.width;
|
||||||
dy = s.height;
|
dy = s.height;
|
||||||
bordertype = GET_PARAM(3);
|
bordertype = GET_PARAM(3);
|
||||||
dx = 1;
|
Init(type);
|
||||||
dy = 0;
|
|
||||||
|
|
||||||
cv::RNG &rng = TS::ptr()->get_rng();
|
|
||||||
cv::Size size(MWIDTH, MHEIGHT);
|
|
||||||
|
|
||||||
mat1 = randomMat(rng, size, type, 5, 16, false);
|
|
||||||
dst = randomMat(rng, size, type, 5, 16, false);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_P(Scharr, Mat)
|
TEST_P(Scharr, Mat)
|
||||||
@ -333,14 +283,9 @@ TEST_P(Scharr, Mat)
|
|||||||
for(int j = 0; j < LOOP_TIMES; j++)
|
for(int j = 0; j < LOOP_TIMES; j++)
|
||||||
{
|
{
|
||||||
random_roi();
|
random_roi();
|
||||||
|
|
||||||
cv::Scharr(mat1_roi, dst_roi, -1, dx, dy, /*scale*/1,/*delta*/0, bordertype);
|
cv::Scharr(mat1_roi, dst_roi, -1, dx, dy, /*scale*/1,/*delta*/0, bordertype);
|
||||||
cv::ocl::Scharr(gmat1, gdst, -1, dx, dy,/*scale*/1,/*delta*/0, bordertype);
|
cv::ocl::Scharr(gmat1, gdst, -1, dx, dy,/*scale*/1,/*delta*/0, bordertype);
|
||||||
|
Near(1);
|
||||||
cv::Mat cpu_dst;
|
|
||||||
gdst_whole.download(cpu_dst);
|
|
||||||
|
|
||||||
EXPECT_MAT_NEAR(dst, cpu_dst, 1, "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -360,18 +305,11 @@ struct GaussianBlur : FilterTestBase
|
|||||||
type = GET_PARAM(0);
|
type = GET_PARAM(0);
|
||||||
ksize = GET_PARAM(1);
|
ksize = GET_PARAM(1);
|
||||||
bordertype = GET_PARAM(3);
|
bordertype = GET_PARAM(3);
|
||||||
|
Init(type);
|
||||||
cv::RNG &rng = TS::ptr()->get_rng();
|
cv::RNG &rng = TS::ptr()->get_rng();
|
||||||
cv::Size size(MWIDTH, MHEIGHT);
|
|
||||||
|
|
||||||
sigma1 = rng.uniform(0.1, 1.0);
|
sigma1 = rng.uniform(0.1, 1.0);
|
||||||
sigma2 = rng.uniform(0.1, 1.0);
|
sigma2 = rng.uniform(0.1, 1.0);
|
||||||
|
|
||||||
mat1 = randomMat(rng, size, type, 5, 16, false);
|
|
||||||
dst = randomMat(rng, size, type, 5, 16, false);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_P(GaussianBlur, Mat)
|
TEST_P(GaussianBlur, Mat)
|
||||||
@ -379,14 +317,9 @@ TEST_P(GaussianBlur, Mat)
|
|||||||
for(int j = 0; j < LOOP_TIMES; j++)
|
for(int j = 0; j < LOOP_TIMES; j++)
|
||||||
{
|
{
|
||||||
random_roi();
|
random_roi();
|
||||||
|
|
||||||
cv::GaussianBlur(mat1_roi, dst_roi, ksize, sigma1, sigma2, bordertype);
|
cv::GaussianBlur(mat1_roi, dst_roi, ksize, sigma1, sigma2, bordertype);
|
||||||
cv::ocl::GaussianBlur(gmat1, gdst, ksize, sigma1, sigma2, bordertype);
|
cv::ocl::GaussianBlur(gmat1, gdst, ksize, sigma1, sigma2, bordertype);
|
||||||
|
Near(1);
|
||||||
cv::Mat cpu_dst;
|
|
||||||
gdst_whole.download(cpu_dst);
|
|
||||||
|
|
||||||
EXPECT_MAT_NEAR(dst, cpu_dst, 1.0, "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -423,7 +356,7 @@ INSTANTIATE_TEST_CASE_P(Filter, Sobel, Combine(
|
|||||||
INSTANTIATE_TEST_CASE_P(Filter, Scharr, Combine(
|
INSTANTIATE_TEST_CASE_P(Filter, Scharr, Combine(
|
||||||
Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC4),
|
Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1, CV_32FC4),
|
||||||
Values(Size(0, 0)), //not use
|
Values(Size(0, 0)), //not use
|
||||||
Values(Size(0, 0), Size(0, 1), Size(1, 0), Size(1, 1)),
|
Values(Size(0, 1), Size(1, 0)),
|
||||||
Values((MatType)cv::BORDER_CONSTANT, (MatType)cv::BORDER_REPLICATE)));
|
Values((MatType)cv::BORDER_CONSTANT, (MatType)cv::BORDER_REPLICATE)));
|
||||||
|
|
||||||
INSTANTIATE_TEST_CASE_P(Filter, GaussianBlur, Combine(
|
INSTANTIATE_TEST_CASE_P(Filter, GaussianBlur, Combine(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user