7 * @brief Debug file for testing detection shape.
9 * More information about using introduced methods
10 * can be found in dokumentation of class Shape_detect (shape_detect.h)
20 #include <shape_detect.h>
25 ostream& operator << (ostream& os, Shape_detect::Point& point)
27 os << "(" << point.x << ", " << point.y << ")";
32 ostream& operator << (ostream& os, Shape_detect::Line& line)
34 os << line.a << "--" << line.b;
38 ostream& operator << (ostream& os, Shape_detect::Arc& arc)
40 os << arc.center << " r=" << arc.radius;
46 void gnuplot(std::vector<Shape_detect::Point> &cartes,
47 std::vector<Shape_detect::Line> &lines,
48 std::vector<Shape_detect::Arc> &arcs)
51 gnuplot = popen("gnuplot", "w");
52 fprintf(gnuplot, "set grid\n");
53 fprintf(gnuplot, "set nokey\n");
54 fprintf(gnuplot, "set size ratio -1\n"); //1.3333
55 fprintf(gnuplot, "set style line 1 pt 1 lc rgb \"green\"\n");
56 fprintf(gnuplot, "set style line 2 lt 2 lc rgb \"red\" lw 2\n");
57 fprintf(gnuplot, "set style line 3 pt 2 lc rgb \"blue\"\n");
58 fprintf(gnuplot, "set style fill transparent solid 0.2 noborder\n");
59 fprintf(gnuplot, "set palette model RGB functions .8-gray*2, .8-gray*2, .8-gray*2\n");
61 fprintf(gnuplot, "plot");
62 for (unsigned i=0; i < arcs.size(); i++) {
64 fprintf(gnuplot, "'-' matrix using ($1*%g+%g):($2*%g+%g):3 with image, ",
65 arcs[i].debug->acc_scale, arcs[i].debug->acc_origin.x,
66 arcs[i].debug->acc_scale, arcs[i].debug->acc_origin.y);
68 if (cartes.size() > 0)
69 fprintf(gnuplot, "'-' with points ls 1");
71 fprintf(gnuplot, ", '-' with linespoints ls 2");
73 fprintf(gnuplot, ", '-' with circles ls 2");
74 fprintf(gnuplot, "\n");
77 for (int i = 0; i < (int) arcs.size(); i++) {
78 Shape_detect::Arc &a = arcs[i];
81 for (int y=0; y < a.debug->acc_size; y++) {
82 for (int x=0; x < a.debug->acc_size; x++) {
83 fprintf(gnuplot, "%d ", a.debug->bitmap[y*a.debug->acc_size+x]);
85 fprintf(gnuplot, "\n");
87 fprintf(gnuplot, "e\ne\n");
90 if (cartes.size() > 0) {
91 for (int i = 0; i < (int) cartes.size(); i++) {
92 fprintf(gnuplot, "%g %g\n", cartes[i].x, cartes[i].y);
94 fprintf(gnuplot, "e\n");
97 if (lines.size() > 0) {
98 for (int i = 0; i < (int) lines.size(); i++) {
99 fprintf(gnuplot, "%f %f\n%f %f\n\n",
100 lines[i].a.x, lines[i].a.y, lines[i].b.x, lines[i].b.y);
102 fprintf(gnuplot, "e\n");
104 if (arcs.size() > 0) {
106 for (int i = 0; i < (int) arcs.size(); i++) {
107 fprintf(gnuplot, "%f %f %f\n",
108 arcs[i].center.x, arcs[i].center.y, arcs[i].radius);
110 fprintf(gnuplot, "e\n");
119 void get_laser_scan(unsigned short laser_scan[], const char *fname)
122 std::ifstream infile(fname, std::ios_base::in);
127 // number from input file
128 unsigned short number;
132 while (std::getline(infile, line, '\n')) {
133 std::stringstream strStream(line);
135 // Ignore out of range data (generated by simulator in robomon)
138 laser_scan[idx] = number;
144 * There are detected line segments in input file (laser scan data)
145 * @param argv name input file with measured data
148 int main(int argc, char** argv)
150 if (argc < 2 || strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
151 std::cout << "Help:" << std::endl;
152 std::cout << "Example: ./shape_detect_offline -g -f file_name -n seq_length" << std::endl;
153 std::cout << "-g: Gnuplot output." << std::endl;
154 std::cout << "-f file_name example: seq-scan-<NUMBER>." << std::endl;
155 std::cout << "-n seq_length: Maximal length sequence file <NUMBER>." << std::endl;
156 std::cout << std::endl;
166 unsigned short laser_scan[HOKUYO_ARRAY_SIZE];
168 for (int i = 1; i < argc; i++) {
169 if (strcmp(argv[i], "-g") == 0)
171 else if (strcmp(argv[i], "-f") == 0) {
173 strcpy(fname, argv[i]);
174 } else if (strcmp(argv[i], "-n") == 0) {
176 number_file = atoi(argv[i]);
178 std::cout << "Invalid input parameter: " << argv[i] << "." << std::endl;
183 std::vector<Shape_detect::Line> lines;
184 std::vector<Shape_detect::Arc> arcs;
185 std::vector<Shape_detect::Arc> result;
187 if (number_file == 0) {
188 std::cout << "Open file: " << fname << std::endl;
189 get_laser_scan(laser_scan, fname);
191 sd.prepare(laser_scan);
192 sd.line_detect(lines);
193 sd.arc_detect(result);
195 for (int i = 1; i <= number_file; i++) {
198 sprintf(name, "%s0%d", fname, i);
200 sprintf(name, "%s%d", fname, i);
202 std::cout << "Open file: " << name << std::endl;
204 get_laser_scan(laser_scan, name);
206 sd.prepare(laser_scan);
209 sd.line_detect(lines);
210 sd.arc_detect(result);
215 result = sd.arcs_compare(result, arcs, 8);
217 if (result.size() == 0)
222 std::cout << std::endl << "Result:" << std::endl;
224 for (unsigned i = 0; i < lines.size(); i++)
225 cout << "Line: " << lines[i] << endl;
227 for (unsigned i = 0; i < result.size(); i++)
228 cout << "Arc: " << result[i] << endl;
231 gnuplot(sd.getCartes(), lines, result);