Skip to content

Commit cc36f58

Browse files
committed
Merge pull request #2915 from alalek:backport_2716
2 parents 746acb9 + 930eca1 commit cc36f58

File tree

4 files changed

+49
-12
lines changed

4 files changed

+49
-12
lines changed

modules/ximgproc/include/opencv2/ximgproc/fast_line_detector.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ class CV_EXPORTS_W FastLineDetector : public Algorithm
6565
hysteresis procedure in Canny()
6666
@param _canny_th2 50 - Second threshold for
6767
hysteresis procedure in Canny()
68-
@param _canny_aperture_size 3 - Aperturesize for the sobel
69-
operator in Canny()
68+
@param _canny_aperture_size 3 - Aperturesize for the sobel operator in Canny().
69+
If zero, Canny() is not applied and the input
70+
image is taken as an edge image.
7071
@param _do_merge false - If true, incremental merging of segments
7172
will be performed
7273
*/

modules/ximgproc/samples/fld_lines.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ int main(int argc, char** argv)
3737
// hysteresis procedure in Canny()
3838
// canny_th2 50 - Second threshold for
3939
// hysteresis procedure in Canny()
40-
// canny_aperture_size 3 - Aperturesize for the sobel
41-
// operator in Canny()
40+
// canny_aperture_size 3 - Aperturesize for the sobel operator in Canny().
41+
// If zero, Canny() is not applied and the input
42+
// image is taken as an edge image.
4243
// do_merge false - If true, incremental merging of segments
4344
// will be performed
4445
int length_threshold = 10;

modules/ximgproc/src/fast_line_detector.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ class FastLineDetectorImpl : public FastLineDetector
2929
* _ hysteresis procedure in Canny()
3030
* @param _canny_th2 50 - Second threshold for
3131
* _ hysteresis procedure in Canny()
32-
* @param _canny_aperture_size 3 - Aperturesize for the sobel
33-
* _ operator in Canny()
32+
* @param _canny_aperture_size 3 - Aperturesize for the sobel operator in Canny().
33+
* If zero, Canny() is not applied and the input
34+
* image is taken as an edge image.
3435
* @param _do_merge false - If true, incremental merging of segments
35-
will be perfomred
36+
* will be performed
3637
*/
3738
FastLineDetectorImpl(int _length_threshold = 10, float _distance_threshold = 1.414213562f,
3839
double _canny_th1 = 50.0, double _canny_th2 = 50.0, int _canny_aperture_size = 3,
@@ -80,7 +81,7 @@ class FastLineDetectorImpl : public FastLineDetector
8081

8182
double distPointLine(const Mat& p, Mat& l);
8283

83-
void extractSegments(const std::vector<Point2i>& points, std::vector<SEGMENT>& segments );
84+
void extractSegments(const std::vector<Point2i>& points, std::vector<SEGMENT>& segments);
8485

8586
void lineDetection(const Mat& src, std::vector<SEGMENT>& segments_all);
8687

@@ -113,7 +114,7 @@ FastLineDetectorImpl::FastLineDetectorImpl(int _length_threshold, float _distanc
113114
canny_th1(_canny_th1), canny_th2(_canny_th2), canny_aperture_size(_canny_aperture_size), do_merge(_do_merge)
114115
{
115116
CV_Assert(_length_threshold > 0 && _distance_threshold > 0 &&
116-
_canny_th1 > 0 && _canny_th2 > 0 && _canny_aperture_size > 0);
117+
_canny_th1 > 0 && _canny_th2 > 0 && _canny_aperture_size >= 0);
117118
}
118119

119120
void FastLineDetectorImpl::detect(InputArray _image, OutputArray _lines)
@@ -344,7 +345,7 @@ template<class T>
344345
pt = T(pt_tmp);
345346
}
346347

347-
void FastLineDetectorImpl::extractSegments(const std::vector<Point2i>& points, std::vector<SEGMENT>& segments )
348+
void FastLineDetectorImpl::extractSegments(const std::vector<Point2i>& points, std::vector<SEGMENT>& segments)
348349
{
349350
bool is_line;
350351

@@ -544,8 +545,14 @@ void FastLineDetectorImpl::lineDetection(const Mat& src, std::vector<SEGMENT>& s
544545
std::vector<Point2i> points;
545546
std::vector<SEGMENT> segments, segments_tmp;
546547
Mat canny;
547-
Canny(src, canny, canny_th1, canny_th2, canny_aperture_size);
548-
548+
if (canny_aperture_size == 0)
549+
{
550+
canny = src;
551+
}
552+
else
553+
{
554+
Canny(src, canny, canny_th1, canny_th2, canny_aperture_size);
555+
}
549556
canny.colRange(0,6).rowRange(0,6) = 0;
550557
canny.colRange(src.cols-5,src.cols).rowRange(src.rows-5,src.rows) = 0;
551558

modules/ximgproc/test/test_fld.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class FLDBase : public testing::Test
2323
void GenerateWhiteNoise(Mat& image);
2424
void GenerateConstColor(Mat& image);
2525
void GenerateLines(Mat& image, const unsigned int numLines);
26+
void GenerateEdgeLines(Mat& image, const unsigned int numLines);
2627
void GenerateBrokenLines(Mat& image, const unsigned int numLines);
2728
void GenerateRotatedRect(Mat& image);
2829
virtual void SetUp();
@@ -55,6 +56,7 @@ void FLDBase::GenerateConstColor(Mat& image)
5556
image = Mat(img_size, CV_8UC1, Scalar::all(rng.uniform(0, 256)));
5657
}
5758

59+
5860
void FLDBase::GenerateLines(Mat& image, const unsigned int numLines)
5961
{
6062
image = Mat(img_size, CV_8UC1, Scalar::all(rng.uniform(0, 128)));
@@ -68,6 +70,19 @@ void FLDBase::GenerateLines(Mat& image, const unsigned int numLines)
6870
}
6971
}
7072

73+
void FLDBase::GenerateEdgeLines(Mat& image, const unsigned int numLines)
74+
{
75+
image = Mat(img_size, CV_8UC1, Scalar::all(0));
76+
77+
for(unsigned int i = 0; i < numLines; ++i)
78+
{
79+
int y = rng.uniform(10, img_size.width - 10);
80+
Point p1(y, 10);
81+
Point p2(y, img_size.height - 10);
82+
line(image, p1, p2, Scalar(255), 1);
83+
}
84+
}
85+
7186
void FLDBase::GenerateBrokenLines(Mat& image, const unsigned int numLines)
7287
{
7388
image = Mat(img_size, CV_8UC1, Scalar::all(rng.uniform(0, 128)));
@@ -153,6 +168,19 @@ TEST_F(ximgproc_FLD, lines)
153168
ASSERT_EQ(EPOCHS, passedtests);
154169
}
155170

171+
TEST_F(ximgproc_FLD, edgeLines)
172+
{
173+
for (int i = 0; i < EPOCHS; ++i)
174+
{
175+
const unsigned int numOfLines = 1;
176+
GenerateEdgeLines(test_image, numOfLines);
177+
Ptr<FastLineDetector> detector = createFastLineDetector(10, 1.414213562f, 50, 50, 0);
178+
detector->detect(test_image, lines);
179+
if(numOfLines == lines.size()) ++passedtests;
180+
}
181+
ASSERT_EQ(EPOCHS, passedtests);
182+
}
183+
156184
TEST_F(ximgproc_FLD, mergeLines)
157185
{
158186
for (int i = 0; i < EPOCHS; ++i)

0 commit comments

Comments
 (0)