7 * @brief Shape detection from laser scan data
15 \defgroup shapedet Shape detection
17 Library @a shape_detect is used for detection of line segments in data
18 measured by a laser scanner.
21 - \ref shapedet_general
22 - \ref shapedet_debug_mode
23 - \ref shapedet_example
26 \section shapedet_general Introduction
28 The input of the algorithm is represented by array laser_scan (type
29 unsigned short) which contains data expressed in polar coordinates.
30 The first step is data conversion from polar coordinates to vector
31 whose points are expressed in cartesian coordinates. The section
32 includes filtering of errors in the scanned data which are represented
33 by values lower then 20.
35 In the next is divided pointvector in dependence on parameter @a max_distance_point.
36 Some line segment is searched by recursion in the individual parts of pointvector
37 by perpendicular line regression.
38 The line segment is detected or set is divided to achievement of parametersize
41 The founded line is written into output vector lines. The method line_detect
42 is finished after research of all vectorparts.
44 \section shapedet_debug_mode Debug mode
46 The debug mode permits detection of segment lines with connected laser scanner
47 or from scanned data, which are saved in a file. GNUPLOT can be used for graphical
48 output in debug mode or output vector can be saved in a file for next processing
51 For setting above properties is used directives define GNUPLOT.
53 For debugging can be used methods introduced in file main.cc.
55 \section shapedet_example Example
57 In the file main.cc are introduced examples of using class Shape_detect.
58 The first step is creation of classinstance by constructor calling
59 (default setting for Hokuyo or with applicable parameters). After that it is possible
60 preparation of output vector for saving founded segment line and calling method
61 shape_detect with applicable parameters.
63 The first example is work illustration with connected laser scanner Hokuyo.
65 \include hokuyo/shape-detect/online.cc
67 \section shapedet_ref References
69 Fast line, arc/circle and leg detection from laser scan data in a Player driver,
70 http://w3.ualg.pt/~dcastro/a1738.pdf
72 Mathpages, Perpendicular regression of a line,
73 http://mathpages.com/home/kmath110.htm
91 #include <robottype.h>
92 #include <roboorte_robottype.h>
95 * Debug mode with GNUPLOT graph.
96 * True -> Detected lines are painted by GNUPLOT.
97 * False -> Lines isn't painted.
103 * There are detected line segments in input array of measured data (laser_scan)
104 * by using perpendicular line regression.
105 * The output is formed by vector of type Line (so detected segment line - coordinates endpoints).
112 * The constructor with default setting of detection properties (pro Hokuyo).
113 * Line_min_points = 7
114 * Line_error_threshold = 20
115 * Max_distance_point = 300
121 * The constructor for other setting than default setting of detection properties.
122 * @param line_min_points the minimal number of points which can create segment line.
123 * @param line_error_threshold the maximal pointerror from segment line of regression.
124 * @param max_distance_point the maximal Euclidean distance of point.
127 Shape_detect (int line_min_points, int line_error_threshold, int max_distance_point);
130 * General equation of line -> Ax + By + C = 0.
131 * Is used for calculation of lines intersection.
134 typedef struct {float a,b,c;} General_form;
137 * Point expressed in cartesian coordinates.
141 float x; /**< x coordinates point. */
142 float y; /**< y coordinates point. */
146 * Line defined by two points which are expressed in cartesian coordinates.
150 Point a; /**< start point from a line. */
151 Point b; /**< end point from a line. */
155 * Arc defined by TODO.
167 * @param [in] laser_scan contains laser scanned data.
170 void prepare(const unsigned short laser_scan[]);
173 * There are detected line segments in input array of measured
174 * data by using perpendicular line regression.
175 * @param [out] &lines vector which contains detected lines.
178 void line_detect(std::vector<Line> &lines);
181 * There are detected line segments in input array of measured
183 * @param [out] &arcs vector which contains detected arcs.
186 void arc_detect(std::vector<Arc> &arcs);
190 * The minimal number of points which can create segment line.
196 * The maximal pointerror from segment line of regression.
199 int Line_error_threshold;
202 * The maximal Euclidean distance of point.
205 int Max_distance_point;
207 std::vector<Point> cartes;//(HOKUYO_ARRAY_SIZE);
209 float Arc_max_aperture;
210 float Arc_min_aperture;
217 * Method paints detection lines in GNUPLOT.
218 * For debug mode. It must be defined global flag GNUPLOT.
219 * @param &lines is vector which contains detected lines.
220 * @param &cartes is vector whose points are expressed in cartesian coordinates.
223 void plot_line(std::vector<Line> &lines);
224 void plot_arc(std::vector<Arc> &arcs);
227 * Method for initialization GNUPLOT - opens pipe and performs basic settings.
228 * For debug mode. It must be defined global flag GNUPLOT.
235 * Calculation of lines intersection.
236 * @param point which pertains to line.
237 * @param gen is general equation of line.
238 * @return point of intersection.
241 inline Point intersection_line(const Point point, const General_form gen);
244 * Calculating perpendicular regression of a line in input range index points.
245 * @param [out] &r is minimal distance between point and found line.
246 * @param [in] begin is start point.
247 * @param [in] end is last point.
248 * @param [in] &cartes is vector whose points are expressed in cartesian coordinates.
249 * @param [out] &gen is general equation of found line.
250 * @return 0 for right course else 1.
253 int perpendicular_regression(float &r, const int begin, const int end, General_form &gen);
256 * In case the input range points does not line. Is range divided and to single parts is again applied line_fitting function.
257 * @param [in] begin is start point.
258 * @param [in] end is last point.
259 * @param [in] &cartes is vector whose points are expressed in cartesian coordinates.
260 * @param [out] &lines is vector with detecting lines.
263 void line_fitting(int begin, int end, std::vector<Line> &lines);
266 * Convert vector expressed in polar coordinates to vector expressed in cartesian coordinates.
267 * @param laser_scan laser scanned data expressed in polar coordinates.
268 * @param &cartes is vector whose points are expressed in cartesian coordinates.
271 void polar_to_cartes(const unsigned short laser_scan[]);
274 * Calculation of distance between points which are expressed in cartesian coordinates.
275 * @param a is first point.
276 * @param b is second point.
277 * @return distance between points.
280 inline float point_distance(Point a, Point b);
282 inline Point rotate(Point input_point, float rad);
284 bool fit_arc(int begin, int end, std::vector<Arc> &arcs);
287 #endif // SHAPE_DETECT