Skip to content

Commit d8197c6

Browse files
authored
Merge pull request #2716 from tsukada-cs:feature/fld-is_edge-option
Added edge input feature to fast_line_detector * add is_edge option on fast_line_detector * Fixed function declarations * Added is_edge test * Add input_edge option to createFastLineDetector(). Deleted is_edge option from detect(). * Fixed the Docs issue (whitespace opencv_contrib). * Fixed Docs issue. * Added assertion check on canny_aperture_size = 0. Removed the input_edge option from createFastLineDetector(). * fixed Docs and coding style
1 parent 9b328cf commit d8197c6

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

+3-2
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 perfomred
7273
*/

modules/ximgproc/samples/fld_lines.cpp

+3-2
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 perfomred
4445
int length_threshold = 10;

modules/ximgproc/src/fast_line_detector.cpp

+15-8
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

+28
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();
@@ -47,6 +48,7 @@ void FLDBase::GenerateConstColor(Mat& image)
4748
image = Mat(img_size, CV_8UC1, Scalar::all(rng.uniform(0, 256)));
4849
}
4950

51+
5052
void FLDBase::GenerateLines(Mat& image, const unsigned int numLines)
5153
{
5254
image = Mat(img_size, CV_8UC1, Scalar::all(rng.uniform(0, 128)));
@@ -60,6 +62,19 @@ void FLDBase::GenerateLines(Mat& image, const unsigned int numLines)
6062
}
6163
}
6264

65+
void FLDBase::GenerateEdgeLines(Mat& image, const unsigned int numLines)
66+
{
67+
image = Mat(img_size, CV_8UC1, Scalar::all(0));
68+
69+
for(unsigned int i = 0; i < numLines; ++i)
70+
{
71+
int y = rng.uniform(10, img_size.width - 10);
72+
Point p1(y, 10);
73+
Point p2(y, img_size.height - 10);
74+
line(image, p1, p2, Scalar(255), 1);
75+
}
76+
}
77+
6378
void FLDBase::GenerateBrokenLines(Mat& image, const unsigned int numLines)
6479
{
6580
image = Mat(img_size, CV_8UC1, Scalar::all(rng.uniform(0, 128)));
@@ -145,6 +160,19 @@ TEST_F(ximgproc_FLD, lines)
145160
ASSERT_EQ(EPOCHS, passedtests);
146161
}
147162

163+
TEST_F(ximgproc_FLD, edgeLines)
164+
{
165+
for (int i = 0; i < EPOCHS; ++i)
166+
{
167+
const unsigned int numOfLines = 1;
168+
GenerateEdgeLines(test_image, numOfLines);
169+
Ptr<FastLineDetector> detector = createFastLineDetector(10, 1.414213562f, 50, 50, 0);
170+
detector->detect(test_image, lines);
171+
if(numOfLines == lines.size()) ++passedtests;
172+
}
173+
ASSERT_EQ(EPOCHS, passedtests);
174+
}
175+
148176
TEST_F(ximgproc_FLD, mergeLines)
149177
{
150178
for (int i = 0; i < EPOCHS; ++i)

0 commit comments

Comments
 (0)