Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/imgproc/perf/perf_houghlines.cpp
16339 views
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
#include "perf_precomp.hpp"
5
6
namespace opencv_test {
7
8
typedef tuple<string, double, double, double> Image_RhoStep_ThetaStep_Threshold_t;
9
typedef perf::TestBaseWithParam<Image_RhoStep_ThetaStep_Threshold_t> Image_RhoStep_ThetaStep_Threshold;
10
11
PERF_TEST_P(Image_RhoStep_ThetaStep_Threshold, HoughLines,
12
testing::Combine(
13
testing::Values( "cv/shared/pic5.png", "stitching/a1.png" ),
14
testing::Values( 1, 10 ),
15
testing::Values( 0.01, 0.1 ),
16
testing::Values( 0.5, 1.1 )
17
)
18
)
19
{
20
string filename = getDataPath(get<0>(GetParam()));
21
double rhoStep = get<1>(GetParam());
22
double thetaStep = get<2>(GetParam());
23
double threshold_ratio = get<3>(GetParam());
24
25
Mat image = imread(filename, IMREAD_GRAYSCALE);
26
if (image.empty())
27
FAIL() << "Unable to load source image" << filename;
28
29
Canny(image, image, 32, 128);
30
31
// add some syntetic lines:
32
line(image, Point(0, 0), Point(image.cols, image.rows), Scalar::all(255), 3);
33
line(image, Point(image.cols, 0), Point(image.cols/2, image.rows), Scalar::all(255), 3);
34
35
vector<Vec2f> lines;
36
declare.time(60);
37
38
int hough_threshold = (int)(std::min(image.cols, image.rows) * threshold_ratio);
39
40
TEST_CYCLE() HoughLines(image, lines, rhoStep, thetaStep, hough_threshold);
41
42
printf("%dx%d: %d lines\n", image.cols, image.rows, (int)lines.size());
43
44
if (threshold_ratio < 1.0)
45
{
46
EXPECT_GE(lines.size(), 2u);
47
}
48
49
EXPECT_LT(lines.size(), 3000u);
50
51
#if 0
52
cv::cvtColor(image,image,cv::COLOR_GRAY2BGR);
53
for( size_t i = 0; i < lines.size(); i++ )
54
{
55
float rho = lines[i][0], theta = lines[i][1];
56
Point pt1, pt2;
57
double a = cos(theta), b = sin(theta);
58
double x0 = a*rho, y0 = b*rho;
59
pt1.x = cvRound(x0 + 1000*(-b));
60
pt1.y = cvRound(y0 + 1000*(a));
61
pt2.x = cvRound(x0 - 1000*(-b));
62
pt2.y = cvRound(y0 - 1000*(a));
63
line(image, pt1, pt2, Scalar(0,0,255), 1, cv::LINE_AA);
64
}
65
cv::imshow("result", image);
66
cv::waitKey();
67
#endif
68
69
SANITY_CHECK_NOTHING();
70
}
71
72
PERF_TEST_P(Image_RhoStep_ThetaStep_Threshold, HoughLines3f,
73
testing::Combine(
74
testing::Values( "cv/shared/pic5.png", "stitching/a1.png" ),
75
testing::Values( 1, 10 ),
76
testing::Values( 0.01, 0.1 ),
77
testing::Values( 0.5, 1.1 )
78
)
79
)
80
{
81
string filename = getDataPath(get<0>(GetParam()));
82
double rhoStep = get<1>(GetParam());
83
double thetaStep = get<2>(GetParam());
84
double threshold_ratio = get<3>(GetParam());
85
86
Mat image = imread(filename, IMREAD_GRAYSCALE);
87
if (image.empty())
88
FAIL() << "Unable to load source image" << filename;
89
90
Canny(image, image, 32, 128);
91
92
// add some syntetic lines:
93
line(image, Point(0, 0), Point(image.cols, image.rows), Scalar::all(255), 3);
94
line(image, Point(image.cols, 0), Point(image.cols/2, image.rows), Scalar::all(255), 3);
95
96
vector<Vec3f> lines;
97
declare.time(60);
98
99
int hough_threshold = (int)(std::min(image.cols, image.rows) * threshold_ratio);
100
101
TEST_CYCLE() HoughLines(image, lines, rhoStep, thetaStep, hough_threshold);
102
103
printf("%dx%d: %d lines\n", image.cols, image.rows, (int)lines.size());
104
105
if (threshold_ratio < 1.0)
106
{
107
EXPECT_GE(lines.size(), 2u);
108
}
109
110
EXPECT_LT(lines.size(), 3000u);
111
112
SANITY_CHECK_NOTHING();
113
}
114
115
} // namespace
116
117