houghDetect.cpp
00001
00002
00003
00004
00005
00006
00007 #include "vutils.h"
00008 #include "mURGCtrl.h"
00009 #include <stdio.h>
00010 #include <stdlib.h>
00011
00012
00013 static void drawUrgCapture(std::vector<VXV::Grid3D>& points) {
00014 vmonitor::drawPoints(points, White);
00015 }
00016
00017
00018 static void drawLines(std::vector<CoordinateCtrl::line_t>& lines) {
00019 for (std::vector<CoordinateCtrl::line_t>::iterator it = lines.begin();
00020 it != lines.end(); ++it) {
00021 VXV::Grid from = VXV::Grid(it->position.x, it->position.y);
00022 VXV::Grid to;
00023 double rad = it->position.zt.to_rad();
00024 to.x = it->position.x + static_cast<int>(it->length * cos(rad));
00025 to.y = it->position.y + static_cast<int>(it->length * sin(rad));
00026 vmonitor::drawLine(from, to, Green);
00027 }
00028 }
00029
00030
00031 int main(int argc, char *argv[]) {
00032 try {
00033 mURGCtrl urg;
00034 if (initConnection(&urg, argc, argv, false) < 0) {
00035 exit(1);
00036 }
00037 vmonitor::show();
00038
00039 unsigned long firstTicks = vmonitor::getTicks();
00040 while (vmonitor::getTicks() - firstTicks < 1000*5) {
00041 urg.capture();
00042
00043 vmonitor::clear();
00044 std::vector<CoordinateCtrl::line_t> lines;
00045 urg.convert();
00046 detectLines(lines, urg.crd_points);
00047 drawLines(lines);
00048 drawUrgCapture(urg.crd_points);
00049
00050 VXV::Delay(100);
00051 }
00052 } catch (std::exception& e) {
00053 printf("exception: %s\n", e.what());
00054 }
00055 return 0;
00056 }
00057