File: perf_houghlines.cpp

package info (click to toggle)
opencv 4.5.1%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 268,248 kB
  • sloc: cpp: 969,170; xml: 682,525; python: 36,732; lisp: 30,170; java: 25,155; ansic: 7,927; javascript: 5,643; objc: 2,041; sh: 935; cs: 601; perl: 494; makefile: 145
file content (91 lines) | stat: -rw-r--r-- 3,142 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// 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 "../perf_precomp.hpp"
#include "opencv2/ts/ocl_perf.hpp"

#ifdef HAVE_OPENCL

namespace opencv_test {
namespace ocl {

///////////// HoughLines //////////////////////

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];
    }
};

typedef tuple<Size, double, double> ImageSize_RhoStep_ThetaStep_t;
typedef TestBaseWithParam<ImageSize_RhoStep_ThetaStep_t> HoughLinesFixture;

OCL_PERF_TEST_P(HoughLinesFixture, HoughLines, Combine(OCL_TEST_SIZES,
                                                       Values( 0.1, 1 ),
                                                       Values( CV_PI / 180.0, 0.1 )))
{
    const Size srcSize = get<0>(GetParam());
    double rhoStep = get<1>(GetParam());
    double thetaStep = get<2>(GetParam());
    int threshold = 250;

    UMat usrc(srcSize, CV_8UC1), lines(1, 1, CV_32FC2);
    Mat src(srcSize, CV_8UC1);
    src.setTo(Scalar::all(0));
    line(src, Point(0, 100), Point(src.cols, 100), Scalar::all(255), 1);
    line(src, Point(0, 200), Point(src.cols, 200), Scalar::all(255), 1);
    line(src, Point(0, 400), Point(src.cols, 400), Scalar::all(255), 1);
    line(src, Point(100, 0), Point(100, src.rows), Scalar::all(255), 1);
    line(src, Point(200, 0), Point(200, src.rows), Scalar::all(255), 1);
    line(src, Point(400, 0), Point(400, src.rows), Scalar::all(255), 1);
    src.copyTo(usrc);

    declare.in(usrc).out(lines);

    OCL_TEST_CYCLE() cv::HoughLines(usrc, lines, rhoStep, thetaStep, threshold);

    Mat result;
    lines.copyTo(result);
    std::sort(result.begin<Vec2f>(), result.end<Vec2f>(), Vec2fComparator());

    SANITY_CHECK(result, 1e-6);
}

///////////// HoughLinesP /////////////////////

typedef tuple<string, double, double> Image_RhoStep_ThetaStep_t;
typedef TestBaseWithParam<Image_RhoStep_ThetaStep_t> HoughLinesPFixture;

OCL_PERF_TEST_P(HoughLinesPFixture, HoughLinesP, Combine(Values("cv/shared/pic5.png", "stitching/a1.png"),
                                                         Values( 0.1, 1 ),
                                                         Values( CV_PI / 180.0, 0.1 )))
{
    string filename = get<0>(GetParam());
    double rhoStep = get<1>(GetParam());
    double thetaStep = get<2>(GetParam());
    int threshold = 100;
    double minLineLength = 50, maxGap = 5;

    Mat image = imread(getDataPath(filename), IMREAD_GRAYSCALE);
    Canny(image, image, 50, 200, 3);
    UMat usrc, lines(1, 1, CV_32SC4);
    image.copyTo(usrc);

    declare.in(usrc).out(lines);

    OCL_TEST_CYCLE() cv::HoughLinesP(usrc, lines, rhoStep, thetaStep, threshold, minLineLength, maxGap);

    EXPECT_NE((int) lines.total(), 0);
    SANITY_CHECK_NOTHING();
}

} } // namespace opencv_test::ocl

#endif // HAVE_OPENCL