1
// This file is part of OpenCV project.
2
// It is subject to the license terms in the LICENSE file found in the top-level directory
3
// of this distribution and at http://opencv.org/license.html.
5
// Copyright (C) 2014, Itseez, Inc., all rights reserved.
6
// Third party copyrights are property of their respective owners.
8
#include "../test_precomp.hpp"
9
#include "opencv2/ts/ocl_test.hpp"
16
struct Vec2fComparator
18
bool operator()(const Vec2f& a, const Vec2f b) const
20
if(a[0] != b[0]) return a[0] < b[0];
21
else return a[1] < b[1];
25
/////////////////////////////// HoughLines ////////////////////////////////////
27
PARAM_TEST_CASE(HoughLines, double, double, int)
29
double rhoStep, thetaStep;
38
rhoStep = GET_PARAM(0);
39
thetaStep = GET_PARAM(1);
40
threshold = GET_PARAM(2);
43
virtual void generateTestData()
45
src_size = randomSize(500, 1920);
46
src.create(src_size, CV_8UC1);
47
src.setTo(Scalar::all(0));
48
line(src, Point(0, 100), Point(100, 100), Scalar::all(255), 1);
49
line(src, Point(0, 200), Point(100, 200), Scalar::all(255), 1);
50
line(src, Point(0, 400), Point(100, 400), Scalar::all(255), 1);
51
line(src, Point(100, 0), Point(100, 200), Scalar::all(255), 1);
52
line(src, Point(200, 0), Point(200, 200), Scalar::all(255), 1);
53
line(src, Point(400, 0), Point(400, 200), Scalar::all(255), 1);
58
virtual void readRealTestData()
60
Mat img = readImage("shared/pic5.png", IMREAD_GRAYSCALE);
61
Canny(img, src, 100, 150, 3);
66
virtual void Near(double eps = 0.)
68
EXPECT_EQ(dst.size(), udst.size());
72
Mat lines_cpu, lines_gpu;
73
dst.copyTo(lines_cpu);
74
udst.copyTo(lines_gpu);
76
std::sort(lines_cpu.begin<Vec2f>(), lines_cpu.end<Vec2f>(), Vec2fComparator());
77
std::sort(lines_gpu.begin<Vec2f>(), lines_gpu.end<Vec2f>(), Vec2fComparator());
79
EXPECT_LE(TestUtils::checkNorm2(lines_cpu, lines_gpu), eps);
84
OCL_TEST_P(HoughLines, RealImage)
88
OCL_OFF(cv::HoughLines(src, dst, rhoStep, thetaStep, threshold));
89
OCL_ON(cv::HoughLines(usrc, udst, rhoStep, thetaStep, threshold));
94
OCL_TEST_P(HoughLines, GeneratedImage)
96
for (int j = 0; j < test_loop_times; j++)
100
OCL_OFF(cv::HoughLines(src, dst, rhoStep, thetaStep, threshold));
101
OCL_ON(cv::HoughLines(usrc, udst, rhoStep, thetaStep, threshold));
107
/////////////////////////////// HoughLinesP ///////////////////////////////////
109
PARAM_TEST_CASE(HoughLinesP, int, double, double)
111
double rhoStep, thetaStep, minLineLength, maxGap;
121
thetaStep = CV_PI / 180;
122
threshold = GET_PARAM(0);
123
minLineLength = GET_PARAM(1);
124
maxGap = GET_PARAM(2);
127
virtual void readRealTestData()
129
Mat img = readImage("shared/pic5.png", IMREAD_GRAYSCALE);
130
Canny(img, src, 50, 200, 3);
135
virtual void Near(double eps = 0.)
137
Mat lines_gpu = udst.getMat(ACCESS_READ);
139
if (dst.total() > 0 && lines_gpu.total() > 0)
141
Mat result_cpu(src.size(), CV_8UC1, Scalar::all(0));
142
Mat result_gpu(src.size(), CV_8UC1, Scalar::all(0));
144
MatConstIterator_<Vec4i> it = dst.begin<Vec4i>(), end = dst.end<Vec4i>();
145
for ( ; it != end; it++)
148
line(result_cpu, Point(p[0], p[1]), Point(p[2], p[3]), Scalar(255));
151
it = lines_gpu.begin<Vec4i>(), end = lines_gpu.end<Vec4i>();
152
for ( ; it != end; it++)
155
line(result_gpu, Point(p[0], p[1]), Point(p[2], p[3]), Scalar(255));
158
EXPECT_MAT_SIMILAR(result_cpu, result_gpu, eps);
164
OCL_TEST_P(HoughLinesP, RealImage)
168
OCL_OFF(cv::HoughLinesP(src, dst, rhoStep, thetaStep, threshold, minLineLength, maxGap));
169
OCL_ON(cv::HoughLinesP(usrc, udst, rhoStep, thetaStep, threshold, minLineLength, maxGap));
174
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, HoughLines, Combine(Values(1, 0.5), // rhoStep
175
Values(CV_PI / 180.0, CV_PI / 360.0), // thetaStep
176
Values(80, 150))); // threshold
178
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, HoughLinesP, Combine(Values(100, 150), // threshold
179
Values(50, 100), // minLineLength
180
Values(5, 10))); // maxLineGap
182
} } // namespace cvtest::ocl
184
#endif // HAVE_OPENCL
b'\\ No newline at end of file'