From: <bl...@us...> - 2009-08-02 23:39:12
|
Revision: 4150 http://hugin.svn.sourceforge.net/hugin/?rev=4150&view=rev Author: blimbo Date: 2009-08-02 23:39:03 +0000 (Sun, 02 Aug 2009) Log Message: ----------- Segment joining function, not finished yet though Modified Paths: -------------- hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/ProcessImage.cpp Modified: hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/ProcessImage.cpp =================================================================== --- hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/ProcessImage.cpp 2009-08-02 22:06:30 UTC (rev 4149) +++ hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/ProcessImage.cpp 2009-08-02 23:39:03 UTC (rev 4150) @@ -172,6 +172,13 @@ vigra::initImage(srcIterRange(tmp.upperLeft() + vigra::Diff2D(inliers[il]->x, inliers[il]->y), tmp.upperLeft() + vigra::Diff2D(inliers[il]->x+1, inliers[il]->y+1)), RGB(255,0,0) ); + + // Make end point green + if(il == 0 || il == inliers.size()-1)vigra::initImage(srcIterRange(tmp.upperLeft() + + vigra::Diff2D(inliers[il]->x, inliers[il]->y), + tmp.upperLeft() + vigra::Diff2D(inliers[il]->x+1, inliers[il]->y+1)), + RGB(0,255,0) ); + } if (generate_images){ @@ -248,6 +255,7 @@ //int first_line_end_x = first_x, first_line_end_y = first_y; int first_line_end_x = -1, first_line_end_y = -1; int second_line_end_x = -1, second_line_end_y = -1; + int first_line_end_index; if(verbose) cout << "Query Pixel\tNN Pixel\tIndex\tDistance\tOrientation diff" << endl; @@ -343,6 +351,7 @@ if (first_line_end_x == -1 && first_line_end_y == -1){ first_line_end_x = close_neighbors[nnIdx[0]]->x; first_line_end_y = close_neighbors[nnIdx[0]]->y; + first_line_end_index = inliers.size()-1; }else{ second_line_end_x = close_neighbors[nnIdx[0]]->x; second_line_end_y = close_neighbors[nnIdx[0]]->y; @@ -417,6 +426,7 @@ if (first_line_end_x == -1 && first_line_end_y == -1){ first_line_end_x = inliers[inliers.size()-1]->x; first_line_end_y = inliers[inliers.size()-1]->y; + first_line_end_index = inliers.size()-1; }else{ second_line_end_x = inliers[inliers.size()-1]->x; second_line_end_y = inliers[inliers.size()-1]->y; @@ -439,6 +449,7 @@ if (first_line_end_x == -1 && first_line_end_y == -1){ first_line_end_x = (int)queryPt[0]; first_line_end_y = (int)queryPt[1]; + first_line_end_index = inliers.size()-1; }else{ second_line_end_x = (int)queryPt[0]; second_line_end_y = (int)queryPt[1]; @@ -454,6 +465,7 @@ if (first_line_end_x == -1 && first_line_end_y == -1){ first_line_end_x = (int)queryPt[0]; first_line_end_y = (int)queryPt[1]; + first_line_end_index = inliers.size()-1; }else{ second_line_end_x = (int)queryPt[0]; second_line_end_y = (int)queryPt[1]; @@ -467,6 +479,17 @@ } annClose(); + + // Sort points + vector<Point2D> tmp; + for(int i = first_line_end_index; i >= 0; i--){ + tmp.push_back(inliers[i]);; + } + for(int i = first_line_end_index+1; i < inliers.size(); i++){ + tmp.push_back(inliers[i]);; + } + inliers = tmp; + //int x2 = inliers[inliers.size()-1]->x; //int y2 = inliers[inliers.size()-1]->y; //double length_sq = line_length_squared(first_line_end_x, first_line_end_y,x2,y2); @@ -485,7 +508,7 @@ if(verbose) cout << "Above theshold (" << min_line_length_squared << ")" << endl; }else{ // Collect shorter segments - if(length_sq >= min_line_length_squared/2){ + if(length_sq >= min_line_length_squared/6){ short_segments.push_back(inliers); } inliers.clear(); @@ -525,13 +548,7 @@ int top = h-size; int right = w+size; int bottom = h+size; - - /* - size = 2 = 10305 pixels remain - size = 3 = 9449 pixels remain - without removing edges = 13188 pixels - */ - + if(left<0) left = 0; if(right>image.width()) right = image.width(); if(top<0) top = 0; @@ -1051,33 +1068,126 @@ sort(lines.begin(), lines.end(), compare_line_length); } -void join_short_segments(vector<vector<Point2D> >& short_segments){ +double gradient(vector<Point2D>& a){ + double d1 = a[0]->x - a[a.size()-1]->x; + double d2 = a[0]->y - a[a.size()-1]->y; + return(d2/d1); +} - for(int i = 0; i < short_segments.size(); i++){ - - unsigned int top = 0; - unsigned int bottom = 100000; - unsigned int left = 100000; - unsigned int right = 0; +double point_line_length_squared(Point2D& a, Point2D& b){ + int d1 = a->x - b->x; + int d2 = a->y - b->y; + return(d1*d1+d2*d2); +} - for (unsigned int il = 0; il < short_segments[i].size(); il++){ +void join_short_segments(vector<vector<Point2D> >& short_segments, BImage& image){ + + string seg("segment_"); + string jseg("joined_segment_"); + for(int i = 0; i < short_segments.size(); i++){ + //plot_inliers(seg, image, short_segments[i], i); + } - if(short_segments[i][il]->x < left) left = short_segments[i][il]->x; - if(short_segments[i][il]->x > right) right = short_segments[i][il]->x; - if(short_segments[i][il]->y < bottom) bottom = short_segments[i][il]->y; - if(short_segments[i][il]->y > top) top = short_segments[i][il]->y; + + int js = 0; + int limit = 40*40; + for(int i = 0; i < short_segments.size(); i++){ + for(int j = i+1; j < short_segments.size(); j++){ + + //cout << i << " - " << j << ":\t" << gradients[i] << " - " << gradients[j] << " = " << abs(gradients[i] - gradients[j]) << endl; + + + if ( - cout << short_segments[i][il]->x << "," << short_segments[i][il]->y << endl; - - } - - cout << "Gradient = " << (right-left)/(top-bottom) << endl; - - } + + point_line_length_squared(short_segments[i][0],short_segments[j][0]) < limit + || point_line_length_squared(short_segments[i][0],short_segments[j][short_segments[j].size()-1]) < limit + || point_line_length_squared(short_segments[i][short_segments[i].size()-1],short_segments[j][0]) < limit + || + point_line_length_squared(short_segments[i][short_segments[i].size()-1],short_segments[j][short_segments[j].size()-1]) < limit){ + + + int i_x_max,j_x_max,i_x_min,j_x_min; + int i_y_max,j_y_max,i_y_min,j_y_min; + + if(short_segments[i][0]->x > short_segments[i][short_segments[i].size()-1]->x){ + i_x_max = short_segments[i][0]->x; + i_x_min = short_segments[i][short_segments[i].size()-1]->x; + }else{ + i_x_min = short_segments[i][0]->x; + i_x_max = short_segments[i][short_segments[i].size()-1]->x; + } + if(short_segments[i][0]->y > short_segments[i][short_segments[i].size()-1]->y){ + i_y_max = short_segments[i][0]->y; + i_y_min = short_segments[i][short_segments[i].size()-1]->y; + }else{ + i_y_min = short_segments[i][0]->y; + i_y_max = short_segments[i][short_segments[i].size()-1]->y; + } + if(short_segments[j][0]->x > short_segments[j][short_segments[j].size()-1]->x){ + j_x_max = short_segments[j][0]->x; + j_x_min = short_segments[j][short_segments[j].size()-1]->x; + }else{ + j_x_min = short_segments[j][0]->x; + j_x_max = short_segments[j][short_segments[j].size()-1]->x; + } + if(short_segments[j][0]->y > short_segments[j][short_segments[j].size()-1]->y){ + j_y_max = short_segments[j][0]->y; + j_y_min = short_segments[j][short_segments[j].size()-1]->y; + }else{ + j_y_min = short_segments[j][0]->y; + j_y_max = short_segments[j][short_segments[j].size()-1]->y; + } + + int overlaps = 0; + if (i_x_max > j_x_max && j_x_max > i_x_min){ + overlaps = 1; + } + + if (j_x_max > i_x_max && i_x_max > j_x_min){ + overlaps = 1; + } + if (i_y_max > j_y_max && j_y_max > i_y_min){ + overlaps = 1; + } + + if (j_y_max > i_y_max && i_y_max > j_y_min){ + overlaps = 1; + } + + overlaps = 0; + + if(overlaps == 0){ + double diff = abs(gradient(short_segments[i]) - gradient(short_segments[j])); + + if(diff < 1){ + + + cout << gradient(short_segments[i]) << " vs " << gradient(short_segments[j]) << endl; cout << "Diff:\t" << diff << endl; + + for(int k = 0; k < short_segments[j].size(); k++){ + short_segments[i].push_back(short_segments[j][k]); + } + short_segments.erase(short_segments.begin()+j); + plot_inliers(jseg, image, short_segments[i], js); + js++; + }else{ + cout << "Diff too big:\t" << diff << endl; + } + }else{ + cout << "Lines overlap:\t" << i << " vs " << j << endl; + } + + + } + + } + } + } void process_image(string& filename, int& plotted){ @@ -1161,25 +1271,22 @@ if(verbose) cout << "=====================" << endl << endl; find_ann(coords, edgeness, inliers, good_lines, short_segments); if(inliers.size()){ - sort_inliers(inliers); + //sort_inliers(inliers); lines.push_back(inliers); inliers.clear(); } if(verbose) cout << "Remaining coords:\t" << coords.size() << "\t(" << 100*((double)coords.size()/intital_coords_size) << " %)" << endl << endl; - } - + } //cout << "Size of short segments:\t" << short_segments.size() << endl << endl; - //join_short_segments(short_segments); + join_short_segments(short_segments,image); short_segments.clear(); // Sort lines by distance between first and last point or number of pixels // Problem if we're doing multiple images // Sort_lines_by_length(); - - if (good_lines == 0){ cout << "No lines found!" << endl << endl; }else{ @@ -1191,5 +1298,4 @@ } cout << endl; } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |