]> rtime.felk.cvut.cz Git - eurobot/public.git/commitdiff
Shape_detect:
authorMartin Synek <synek.martin@gmail.com>
Mon, 25 Apr 2011 10:25:17 +0000 (12:25 +0200)
committerMartin Synek <synek.martin@gmail.com>
Mon, 25 Apr 2011 10:25:17 +0000 (12:25 +0200)
Constants for detecting arcs moved into the constructor.
Add documentation.

src/hokuyo/shape-detect/shape_detect.cc
src/hokuyo/shape-detect/shape_detect.h

index 34be3c70351b54db57042f78762132ae2de5fe28..f7d9bac11dc88880c74b7cce6426a238637f1f1d 100644 (file)
 
 #include "shape_detect.h"
 
-
 Shape_detect::Shape_detect()
 {
        Shape_detect::Line_min_points = 7;
        Shape_detect::Line_error_threshold = 20;
        Shape_detect::Max_distance_point = 300;
+
+       Shape_detect::Radius = 100;
+       Shape_detect::Scale = 10;
+       Shape_detect::Arc_min_points = 10;
+       Shape_detect::Arc_max_distance = 1000;
 }
 
-Shape_detect::Shape_detect(int line_min_points, int line_error_threshold, int max_distance_point)
+Shape_detect::Shape_detect(int line_min_points, int line_error_threshold, int max_distance_point,
+                       float radius, float scale, int arc_min_points, int arc_max_distance)
 {
        Shape_detect::Line_min_points = line_min_points;
        Shape_detect::Line_error_threshold = line_error_threshold;
        Shape_detect::Max_distance_point = max_distance_point;
+
+       Shape_detect::Radius = radius;
+       Shape_detect::Scale = scale;
+       Shape_detect::Arc_min_points = arc_min_points;
+       Shape_detect::Arc_max_distance = arc_max_distance;
 }
 
 inline Shape_detect::Point Shape_detect::intersection_line(const Shape_detect::Point point, const General_form gen)
@@ -69,11 +79,11 @@ std::vector<Shape_detect::Arc> Shape_detect::arcs_compare(std::vector<Shape_dete
        return result;
 }
 
-void Shape_detect::bresenham_circle(const float &radius, const float &scale, std::vector<Shape_detect::Point> &circle)
+void Shape_detect::bresenham_circle(std::vector<Shape_detect::Point> &circle)
 {
        int d;
 
-       int scale_radius = abs(radius / scale);
+       int scale_radius = abs(Shape_detect::Radius / Shape_detect::Scale);
 
        int x = 0;
        int y = scale_radius;
@@ -105,7 +115,7 @@ void Shape_detect::bresenham_circle(const float &radius, const float &scale, std
        return;
 }
 
-void Shape_detect::hough_transform_arc(int begin, int end, std::vector<Arc> &arcs, float radius, float scale)
+void Shape_detect::hough_transform_arc(int begin, int end, std::vector<Arc> &arcs)
 {
        float max_x, max_y, min_x, min_y;
 
@@ -128,10 +138,10 @@ void Shape_detect::hough_transform_arc(int begin, int end, std::vector<Arc> &arc
                        min_y = cartes[i].y;
        }
 
-       const float center_x = (max_x - min_x)/2 + min_x;
-       const float center_y = (max_y - min_y)/2 + min_y;
+       const float center_x = (max_x - min_x) / 2 + min_x;
+       const float center_y = (max_y - min_y) / 2 + min_y;
 
-       const int asize = 600 / scale;
+       const int asize = 600 / Shape_detect::Scale;
        const int amid = asize / 2;
 
        Shape_detect::Arc arc;
@@ -139,11 +149,11 @@ void Shape_detect::hough_transform_arc(int begin, int end, std::vector<Arc> &arc
        arc.debug = new (struct arc_debug);
 
        if (arc.debug) {
-               arc.debug->bitmap = new int[asize*asize];
+               arc.debug->bitmap = new int[asize * asize];
                arc.debug->acc_size = asize;
-               arc.debug->acc_origin.x = center_x - amid*scale;
-               arc.debug->acc_origin.y = center_y - amid*scale;
-               arc.debug->acc_scale = scale;
+               arc.debug->acc_origin.x = center_x - amid * Shape_detect::Scale;
+               arc.debug->acc_origin.y = center_y - amid * Shape_detect::Scale;
+               arc.debug->acc_scale = Shape_detect::Scale;
        }
        
        int accumulator[asize][asize];
@@ -152,11 +162,11 @@ void Shape_detect::hough_transform_arc(int begin, int end, std::vector<Arc> &arc
 
        std::vector<Shape_detect::Point> circle;
 
-       bresenham_circle(radius, scale, circle);
+       bresenham_circle(circle);
 
        for (int i = begin; i <= end; i++) {
-               int xc = floor((cartes[i].x - center_x) / scale);
-               int yc = floor((cartes[i].y - center_y) / scale);
+               int xc = floor((cartes[i].x - center_x) / Shape_detect::Scale);
+               int yc = floor((cartes[i].y - center_y) / Shape_detect::Scale);
 
                for (unsigned int i = 0; i < circle.size(); i++) {
                        int par[8];
@@ -201,7 +211,7 @@ void Shape_detect::hough_transform_arc(int begin, int end, std::vector<Arc> &arc
        center.x = 0;
        center.y = 0;
 
-       arc.radius = radius; //radius [mm]
+       arc.radius = Shape_detect::Radius; //radius [mm]
 
        int max = 0;
 
@@ -211,8 +221,8 @@ void Shape_detect::hough_transform_arc(int begin, int end, std::vector<Arc> &arc
 
                                max = accumulator[i][j];
 
-                               center.x = (j-amid) * scale + center_x;
-                               center.y = (i-amid) * scale + center_y;
+                               center.x = (j - amid) * Shape_detect::Scale + center_x;
+                               center.y = (i - amid) * Shape_detect::Scale + center_y;
                        }
                }
        }
@@ -401,8 +411,6 @@ void Shape_detect::arc_detect(std::vector<Shape_detect::Arc> &arcs)
 
        int end, start = 0;
 
-       int radius = 100.0;
-
        while (start < cartes_size) {
                Shape_detect::Point tmp_start = cartes[start];
 
@@ -410,16 +418,15 @@ void Shape_detect::arc_detect(std::vector<Shape_detect::Arc> &arcs)
                
                while (point_distance(cartes[end-1], cartes[end]) < 100
                        && end < cartes_size
-                       && cartes[end].x < 1000
-                       && cartes[end].y < 1000) {
+                       && cartes[end].x < Shape_detect::Arc_max_distance 
+                       && cartes[end].y < Shape_detect::Arc_max_distance) {
                        end++;
                }
 
                end --;
 
-               if (point_distance(tmp_start, cartes[end]) < (2 * radius) && (end - start > 10)) {
-                       hough_transform_arc(start, end, arcs, radius, 10); // radius [mm], scale[mm]
-               }
+               if (point_distance(tmp_start, cartes[end]) < (2 * Shape_detect::Radius) && (end - start > Shape_detect::Arc_min_points))
+                       hough_transform_arc(start, end, arcs);
 
                start = end + 1;
        }
index 5988e6489523a14361d33f6be7a40be53f48716f..c65c2bc5cced44220d2040f72b66dc1e2c895190 100644 (file)
@@ -99,10 +99,14 @@ class Shape_detect
 {
        public:
                /**
-                * The constructor with default setting of detection properties (pro Hokuyo).
+                * The constructor with default setting of detection properties (for Hokuyo).
                 * Line_min_points = 7
                 * Line_error_threshold = 20
                 * Max_distance_point = 300
+                * Radius = 100
+                * Scale = 10
+                * Arc_min_points = 10
+                * Arc_max_distance = 1000
                 * @ingroup shapedet
                 */
                Shape_detect (void);
@@ -112,9 +116,14 @@ class Shape_detect
                 * @param line_min_points the minimal number of points which can create segment line.
                 * @param line_error_threshold the maximal pointerror from segment line of regression.
                 * @param max_distance_point the maximal Euclidean distance of point.
+                * @param radius the radius detected arc.
+                * @param scale is precision detected center of arc.
+                * @param arc_min_points the minimal number of points which can create arc.
+                * @param arc_max_distance the maximal distance detected arc from origin coordinates [0; 0]
                 * @ingroup shapedet
                 */
-               Shape_detect (int line_min_points, int line_error_threshold, int max_distance_point);
+               Shape_detect (int line_min_points, int line_error_threshold, int max_distance_point,
+                               float radius, float scale, int arc_min_points, int arc_max_distance);
 
                /**
                 * General equation of line -> Ax + By + C = 0.
@@ -219,6 +228,30 @@ class Shape_detect
                 */
                int Max_distance_point;
 
+               /**
+                * The radius detected arc.
+                * @ingroup shapedet
+                */
+               float Radius // [mm]
+
+               /**
+                * The precision detected center of arc.
+                * @ingroup shapedet
+                */
+               float Scale;  // [mm]
+       
+               /**
+                * The minimal number of points which can create arc.
+                * @ingroup shapedet
+                */
+               int Arc_max_distance; //[mm]
+       
+               /**
+                * The maximal distance detected arc from origin coordinates [0; 0]
+                * @ingroup shapedet
+                */
+               int Arc_min_points;
+
                std::vector<Point> cartes;//(HOKUYO_ARRAY_SIZE);
 
                /**
@@ -269,10 +302,10 @@ class Shape_detect
                 */
                inline float point_distance(Point a, Point b);
 
-               void bresenham_circle(const float &radius,const float &scale, std::vector<Point> &circle);
+               void bresenham_circle(std::vector<Point> &circle);
 
                // radius [mm], scale [mm]
-               void hough_transform_arc(int begin, int end, std::vector<Arc> &arcs, float radius, float scale);
+               void hough_transform_arc(int begin, int end, std::vector<Arc> &arcs);
 };
 
 #endif // SHAPE_DETECT