@@ -21,46 +21,14 @@ namespace ximgproc{
21
21
class FastLineDetectorImpl : public FastLineDetector
22
22
{
23
23
public:
24
- /* *
25
- * @param _length_threshold 10 - Segment shorter than this will be discarded
26
- * @param _distance_threshold 1.41421356 - A point placed from a hypothesis line segment
27
- * farther than this will be regarded as an outlier
28
- * @param _canny_th1 50 - First threshold for
29
- * _ hysteresis procedure in Canny()
30
- * @param _canny_th2 50 - Second threshold for
31
- * _ hysteresis procedure 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.
35
- * @param _do_merge false - If true, incremental merging of segments
36
- * will be performed
37
- */
24
+
38
25
FastLineDetectorImpl (int _length_threshold = 10 , float _distance_threshold = 1 .414213562f ,
39
26
double _canny_th1 = 50.0 , double _canny_th2 = 50.0 , int _canny_aperture_size = 3 ,
40
27
bool _do_merge = false );
41
28
42
- /* *
43
- * Detect lines in the input image.
44
- *
45
- * @param _image A grayscale(CV_8UC1) input image.
46
- * If only a roi needs to be selected, use
47
- * lsd_ptr->detect(image(roi), ..., lines);
48
- * lines += Scalar(roi.x, roi.y, roi.x, roi.y);
49
- * @param _lines Return: A vector of Vec4f elements specifying the beginning and ending point of
50
- * a line. Where Vec4f is (x1, y1, x2, y2), point 1 is the start, point 2 is the end.
51
- * Returned lines are directed so that the brighter side is placed on left.
52
- */
53
- void detect (InputArray _image, OutputArray _lines) CV_OVERRIDE;
54
-
55
- /* *
56
- * Draw lines on the given canvas.
57
- *
58
- * @param image The image, where lines will be drawn
59
- * Should have the size of the image, where the lines were found
60
- * @param lines The lines that need to be drawn
61
- * @param draw_arrow If true, arrow heads will be drawn
62
- */
63
- void drawSegments (InputOutputArray _image, InputArray lines, bool draw_arrow = false ) CV_OVERRIDE;
29
+ void detect (InputArray image, OutputArray lines) CV_OVERRIDE;
30
+
31
+ void drawSegments (InputOutputArray image, InputArray lines, bool draw_arrow = false , Scalar linecolor = Scalar(0 , 0 , 255 ), int linethickness = 1) CV_OVERRIDE;
64
32
65
33
private:
66
34
int imagewidth, imageheight, threshold_length;
@@ -85,25 +53,24 @@ class FastLineDetectorImpl : public FastLineDetector
85
53
86
54
void lineDetection (const Mat& src, std::vector<SEGMENT>& segments_all);
87
55
88
- void pointInboardTest (const Mat& src , Point2i& pt);
56
+ void pointInboardTest (const Size srcSize , Point2i& pt);
89
57
90
58
inline void getAngle (SEGMENT& seg);
91
59
92
60
void additionalOperationsOnSegment (const Mat& src, SEGMENT& seg);
93
61
94
- void drawSegment (Mat& mat, const SEGMENT& seg, Scalar bgr = Scalar(0 ,255 ,0 ),
95
- int thickness = 1, bool directed = true);
62
+ void drawSegment (InputOutputArray image, const SEGMENT& seg, Scalar bgr = Scalar(0 ,255 ,0 ), int thickness = 1, bool directed = true);
96
63
};
97
64
98
65
// ///////////////////////////////////////////////////////////////////////////////////////
99
66
100
67
CV_EXPORTS Ptr <FastLineDetector> createFastLineDetector (
101
- int _length_threshold , float _distance_threshold ,
102
- double _canny_th1 , double _canny_th2 , int _canny_aperture_size , bool _do_merge )
68
+ int length_threshold , float distance_threshold ,
69
+ double canny_th1 , double canny_th2 , int canny_aperture_size , bool do_merge )
103
70
{
104
71
return makePtr<FastLineDetectorImpl>(
105
- _length_threshold, _distance_threshold ,
106
- _canny_th1, _canny_th2, _canny_aperture_size, _do_merge );
72
+ length_threshold, distance_threshold ,
73
+ canny_th1, canny_th2, canny_aperture_size, do_merge );
107
74
}
108
75
109
76
// ///////////////////////////////////////////////////////////////////////////////////////
@@ -136,30 +103,23 @@ void FastLineDetectorImpl::detect(InputArray _image, OutputArray _lines)
136
103
Mat (lines).copyTo (_lines);
137
104
}
138
105
139
- void FastLineDetectorImpl::drawSegments (InputOutputArray _image , InputArray lines, bool draw_arrow)
106
+ void FastLineDetectorImpl::drawSegments (InputOutputArray image , InputArray lines, bool draw_arrow, Scalar linecolor, int linethickness )
140
107
{
141
108
CV_INSTRUMENT_REGION ();
142
109
143
- CV_Assert (!_image.empty () && (_image.channels () == 1 || _image.channels () == 3 ));
110
+ int cn = image.channels ();
111
+ CV_Assert (!image.empty () && ( cn == 1 || cn == 3 || cn == 4 ));
144
112
145
- Mat gray;
146
- if (_image.channels () == 1 )
113
+ if (cn == 1 )
147
114
{
148
- gray = _image. getMatRef ( );
115
+ cvtColor (image, image, COLOR_GRAY2BGR );
149
116
}
150
- else if (_image. channels () == 3 )
117
+ else
151
118
{
152
- cvtColor (_image, gray, COLOR_BGR2GRAY);
119
+ cvtColor (image, image, COLOR_BGRA2GRAY);
120
+ cvtColor (image, image, cn == 3 ? COLOR_GRAY2BGR : COLOR_GRAY2BGRA);
153
121
}
154
122
155
- // Create a 3 channel image in order to draw colored lines
156
- std::vector<Mat> planes;
157
- planes.push_back (gray);
158
- planes.push_back (gray);
159
- planes.push_back (gray);
160
-
161
- merge (planes, _image);
162
-
163
123
double gap = 10.0 ;
164
124
double arrow_angle = 30.0 ;
165
125
@@ -172,7 +132,7 @@ void FastLineDetectorImpl::drawSegments(InputOutputArray _image, InputArray line
172
132
const Vec4f& v = _lines.at <Vec4f>(i);
173
133
Point2f b (v[0 ], v[1 ]);
174
134
Point2f e (v[2 ], v[3 ]);
175
- line (_image. getMatRef () , b, e, Scalar ( 0 , 0 , 255 ), 1 );
135
+ line (image , b, e, linecolor, linethickness );
176
136
if (draw_arrow)
177
137
{
178
138
SEGMENT seg;
@@ -185,8 +145,8 @@ void FastLineDetectorImpl::drawSegments(InputOutputArray _image, InputArray line
185
145
Point2i p1;
186
146
p1.x = cvRound (seg.x2 - gap*cos (arrow_angle * CV_PI / 180.0 + ang));
187
147
p1.y = cvRound (seg.y2 - gap*sin (arrow_angle * CV_PI / 180.0 + ang));
188
- pointInboardTest (_image. getMatRef (), p1);
189
- line (_image. getMatRef () , Point (cvRound (seg.x2 ), cvRound (seg.y2 )), p1, Scalar ( 0 , 0 , 255 ), 1 );
148
+ pointInboardTest (image. size (), p1);
149
+ line (image , Point (cvRound (seg.x2 ), cvRound (seg.y2 )), p1, linecolor, linethickness );
190
150
}
191
151
}
192
152
}
@@ -477,10 +437,10 @@ void FastLineDetectorImpl::extractSegments(const std::vector<Point2i>& points, s
477
437
}
478
438
}
479
439
480
- void FastLineDetectorImpl::pointInboardTest (const Mat& src , Point2i& pt)
440
+ void FastLineDetectorImpl::pointInboardTest (const Size srcSize , Point2i& pt)
481
441
{
482
- pt.x = pt.x <= 5 ? 5 : pt.x >= src. cols - 5 ? src. cols - 5 : pt.x ;
483
- pt.y = pt.y <= 5 ? 5 : pt.y >= src. rows - 5 ? src. rows - 5 : pt.y ;
442
+ pt.x = pt.x <= 5 ? 5 : pt.x >= srcSize. width - 5 ? srcSize. width - 5 : pt.x ;
443
+ pt.y = pt.y <= 5 ? 5 : pt.y >= srcSize. height - 5 ? srcSize. height - 5 : pt.y ;
484
444
}
485
445
486
446
bool FastLineDetectorImpl::getPointChain (const Mat& img, Point pt,
@@ -692,8 +652,8 @@ void FastLineDetectorImpl::additionalOperationsOnSegment(const Mat& src, SEGMENT
692
652
points_right[i].y = cvRound (points[i].y + gap*sin (90.0 * CV_PI / 180.0 + ang));
693
653
points_left[i].x = cvRound (points[i].x - gap*cos (90.0 * CV_PI / 180.0 + ang));
694
654
points_left[i].y = cvRound (points[i].y - gap*sin (90.0 * CV_PI / 180.0 + ang));
695
- pointInboardTest (src, points_right[i]);
696
- pointInboardTest (src, points_left[i]);
655
+ pointInboardTest (src. size () , points_right[i]);
656
+ pointInboardTest (src. size () , points_left[i]);
697
657
}
698
658
699
659
int iR = 0 , iL = 0 ;
@@ -717,21 +677,5 @@ void FastLineDetectorImpl::additionalOperationsOnSegment(const Mat& src, SEGMENT
717
677
return ;
718
678
}
719
679
720
- void FastLineDetectorImpl::drawSegment (Mat& mat, const SEGMENT& seg, Scalar bgr, int thickness, bool directed)
721
- {
722
- double gap = 10.0 ;
723
- double ang = (double )seg.angle ;
724
- double arrow_angle = 30.0 ;
725
-
726
- Point2i p1;
727
- p1.x = cvRound (seg.x2 - gap*cos (arrow_angle * CV_PI / 180.0 + ang));
728
- p1.y = cvRound (seg.y2 - gap*sin (arrow_angle * CV_PI / 180.0 + ang));
729
- pointInboardTest (mat, p1);
730
-
731
- line (mat, Point (cvRound (seg.x1 ), cvRound (seg.y1 )),
732
- Point (cvRound (seg.x2 ), cvRound (seg.y2 )), bgr, thickness, 1 );
733
- if (directed)
734
- line (mat, Point (cvRound (seg.x2 ), cvRound (seg.y2 )), p1, bgr, thickness, 1 );
735
- }
736
680
} // namespace cv
737
681
} // namespace ximgproc
0 commit comments