#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)
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;
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;
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;
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];
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];
center.x = 0;
center.y = 0;
- arc.radius = radius; //radius [mm]
+ arc.radius = Shape_detect::Radius; //radius [mm]
int max = 0;
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;
}
}
}
int end, start = 0;
- int radius = 100.0;
-
while (start < cartes_size) {
Shape_detect::Point tmp_start = cartes[start];
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;
}
{
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);
* @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.
*/
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);
/**
*/
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