From eb800afd2f1a5ebe413e500e235518b2787ac3c0 Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Sun, 25 Nov 2012 03:07:16 +0100 Subject: =?UTF-8?q?erkennt=20nun=20sowas=20wie=20eine=20"ideallinie"=20kan?= =?UTF-8?q?n=20die=20ersten=20frames=20=C3=BCberspringen=20h=C3=A4sslich?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- detect_road_borders.cpp | 121 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 107 insertions(+), 14 deletions(-) diff --git a/detect_road_borders.cpp b/detect_road_borders.cpp index 5e10769..8a8e1e7 100644 --- a/detect_road_borders.cpp +++ b/detect_road_borders.cpp @@ -7,6 +7,39 @@ using namespace std; using namespace cv; + +int find_intersection_index(const vector& pts, int* i1, int* i2, int x0, int y0, int x1, int y1) // bresenham aus der dt. wikipedia +// returns: 0 if the only intersection is the last point, 1 if there are more intersections +// in the latter case, the first two indexes are stored in *i1 and *i2 +{ + int dx = abs(x1-x0), sx = x05) { *i2=i; return 1; } + } + } + + + if (x0==x1 && y0==y1) break; + e2 = 2*err; + if (e2 > dy) { err += dy; x0 += sx; } /* e_xy+e_x > 0 */ + if (e2 < dx) { err += dx; y0 += sy; } /* e_xy+e_y < 0 */ + } + + return 0; +} + + Mat circle_mat(int radius) { Mat result(radius*2+1, radius*2+1, CV_8U); @@ -126,9 +159,17 @@ int main(int argc, char* argv[]) int area_history_ptr=0; int area_history_sum=AREA_HISTORY; cout << endl<> frame; + + if (frameno<190) + { + frameno++; + continue; + } + cvtColor(frame, tmp, CV_RGB2GRAY); threshold(tmp, thres, 132, 255, THRESH_BINARY); dilate(thres,tmp,Mat()); @@ -337,11 +378,11 @@ int main(int argc, char* argv[]) double quality = ((double)ang_diff/ANG_SMOOTH) * linear(contours[i][j].y, highy, 1.0, highy+ (drawing.rows-highy)/10, 0.0, true) * linear( abs(drawing.cols/2 - contours[i][j].x), 0.8*drawing.cols/2, 1.0, drawing.cols/2, 0.6, true); - int y2=25+40+100-5*quality; + //int y2=25+40+100-5*quality; line(drawing, Point(x,y), Point(x,y), Scalar(255,255,255)); - line(drawing, Point(x,25+40+100), Point(x,25+40+100), Scalar(127,127,127)); - line(drawing, Point(x,y2), Point(x,y2), Scalar(255,255,255)); + //line(drawing, Point(x,25+40+100), Point(x,25+40+100), Scalar(127,127,127)); + //line(drawing, Point(x,y2), Point(x,y2), Scalar(255,255,255)); circle(drawing, contours[i][j], 2, col); } @@ -351,6 +392,7 @@ int main(int argc, char* argv[]) double lastmax=-999999; double bestquality=0.0; + double bestquality_max=0.0; int bestquality_j=-1; int bestquality_width=-1; @@ -368,7 +410,6 @@ int main(int argc, char* argv[]) if (lastmax > 5) { // the maximum area goes from j0 to j - cout << "max from "<bestquality) { bestquality=quality; + bestquality_max=lastmax; bestquality_j=(j+j0)/2; bestquality_width=j-j0; } @@ -388,16 +430,63 @@ int main(int argc, char* argv[]) } } - for (int j=0;j