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.
4
5// Copyright (C) 2014, Itseez, Inc., all rights reserved.
6// Third party copyrights are property of their respective owners.
7
8#include "../perf_precomp.hpp"
9#include "opencv2/ts/ocl_perf.hpp"
10
11#ifdef HAVE_OPENCL
12
13namespace cvtest {
14namespace ocl {
15
16///////////// HoughLines //////////////////////
17
18struct Vec2fComparator
19{
20    bool operator()(const Vec2f& a, const Vec2f b) const
21    {
22        if(a[0] != b[0]) return a[0] < b[0];
23        else return a[1] < b[1];
24    }
25};
26
27typedef std::tr1::tuple<Size, double, double> ImageSize_RhoStep_ThetaStep_t;
28typedef TestBaseWithParam<ImageSize_RhoStep_ThetaStep_t> HoughLinesFixture;
29
30OCL_PERF_TEST_P(HoughLinesFixture, HoughLines, Combine(OCL_TEST_SIZES,
31                                                       Values( 0.1, 1 ),
32                                                       Values( CV_PI / 180.0, 0.1 )))
33{
34    const Size srcSize = get<0>(GetParam());
35    double rhoStep = get<1>(GetParam());
36    double thetaStep = get<2>(GetParam());
37    int threshold = 250;
38
39    UMat usrc(srcSize, CV_8UC1), lines(1, 1, CV_32FC2);
40    Mat src(srcSize, CV_8UC1);
41    src.setTo(Scalar::all(0));
42    line(src, Point(0, 100), Point(src.cols, 100), Scalar::all(255), 1);
43    line(src, Point(0, 200), Point(src.cols, 200), Scalar::all(255), 1);
44    line(src, Point(0, 400), Point(src.cols, 400), Scalar::all(255), 1);
45    line(src, Point(100, 0), Point(100, src.rows), Scalar::all(255), 1);
46    line(src, Point(200, 0), Point(200, src.rows), Scalar::all(255), 1);
47    line(src, Point(400, 0), Point(400, src.rows), Scalar::all(255), 1);
48    src.copyTo(usrc);
49
50    declare.in(usrc).out(lines);
51
52    OCL_TEST_CYCLE() cv::HoughLines(usrc, lines, rhoStep, thetaStep, threshold);
53
54    Mat result;
55    lines.copyTo(result);
56    std::sort(result.begin<Vec2f>(), result.end<Vec2f>(), Vec2fComparator());
57
58    SANITY_CHECK(result, 1e-6);
59}
60
61///////////// HoughLinesP /////////////////////
62
63typedef std::tr1::tuple<string, double, double> Image_RhoStep_ThetaStep_t;
64typedef TestBaseWithParam<Image_RhoStep_ThetaStep_t> HoughLinesPFixture;
65
66OCL_PERF_TEST_P(HoughLinesPFixture, HoughLinesP, Combine(Values("cv/shared/pic5.png", "stitching/a1.png"),
67                                                         Values( 0.1, 1 ),
68                                                         Values( CV_PI / 180.0, 0.1 )))
69{
70    string filename = get<0>(GetParam());
71    double rhoStep = get<1>(GetParam());
72    double thetaStep = get<2>(GetParam());
73    int threshold = 100;
74    double minLineLength = 50, maxGap = 5;
75
76    Mat image = imread(getDataPath(filename), IMREAD_GRAYSCALE);
77    Canny(image, image, 50, 200, 3);
78    UMat usrc, lines(1, 1, CV_32SC4);
79    image.copyTo(usrc);
80
81    declare.in(usrc).out(lines);
82
83    OCL_TEST_CYCLE() cv::HoughLinesP(usrc, lines, rhoStep, thetaStep, threshold, minLineLength, maxGap);
84
85    EXPECT_NE((int) lines.total(), 0);
86    SANITY_CHECK_NOTHING();
87}
88
89} } // namespace cvtest::ocl
90
91#endif // HAVE_OPENCL