From: <bl...@us...> - 2009-06-09 20:57:24
|
Revision: 3934 http://hugin.svn.sourceforge.net/hugin/?rev=3934&view=rev Author: blimbo Date: 2009-06-09 20:56:11 +0000 (Tue, 09 Jun 2009) Log Message: ----------- Corners removed from edge image 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-06-09 18:16:37 UTC (rev 3933) +++ hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/ProcessImage.cpp 2009-06-09 20:56:11 UTC (rev 3934) @@ -105,15 +105,15 @@ for (unsigned int il = 0; il < inliers.size(); il++){ //cout << il << ": " << inliers[il]->x << "," << inliers[il]->y << endl; - if (il == 0){ - vigra::initImage(srcIterRange(tmp.upperLeft() + vigra::Diff2D(inliers[il]->x-4, inliers[il]->y-4), - tmp.upperLeft() + vigra::Diff2D(inliers[il]->x+4, inliers[il]->y+4)), - RGB(255,0,0) ); - }else{ + //if (il == 0){ + //vigra::initImage(srcIterRange(tmp.upperLeft() + vigra::Diff2D(inliers[il]->x-4, inliers[il]->y-4), + // tmp.upperLeft() + vigra::Diff2D(inliers[il]->x+4, inliers[il]->y+4)), + // RGB(255,0,0) ); + //}else{ 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) ); - } + //} } @@ -299,6 +299,8 @@ unsigned int intital_coords_size = coords.size(); + cout << "Initial coords size:\t" << coords.size() << endl; + // Get 10 strongest lines // Stop when only 25% of coordinates are left unsigned int good_lines = 0; @@ -430,36 +432,47 @@ void nuke_corners(BImage& image, FImage& corners){ - //cout << "Searching for corners..." << endl; + cout << "Searching for corners..." << endl; - vigra::BRGBImage tmp(image.width(),image.height()); - vigra::initImage(srcIterRange(tmp.upperLeft(), - tmp.upperLeft() + vigra::Diff2D(image.width(),image.height())), - RGB(255,255,255) ); - - // Gather black pixels for (unsigned int h = 0; h < corners.height(); h++){ for (unsigned int w = 0; w < corners.width(); w++){ - RGBValue<int,0u,1u,2u> value = image(w,h); - if (value[0] != 0){ + RGBValue<int,0u,1u,2u> value = corners(w,h); + // Change this threshold to remove more corner pixels + if (value[0] > 250){ - vigra::initImage(srcIterRange(tmp.upperLeft() + vigra::Diff2D(w, h), - tmp.upperLeft() + vigra::Diff2D(w+1, h+1)), - RGB(0,0,0) ); + // Change the size of these boxes + int left = w-2; + int top = h-2; + int right = w+2; + int bottom = h+2; + + /* + 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; + if(bottom > image.height()) bottom = image.height(); - - //cout << "(" << w << "," << h << ")" << endl; + // Draw a white box around the corner pixel + // in the edge image + vigra::initImage(srcIterRange(image.upperLeft() + + vigra::Diff2D(left, top), + image.upperLeft() + vigra::Diff2D(right, bottom)), + 255 ); + //cout << value[0] << "\t(" << w << "," << h << ")" << endl; } } } - - - string output = path; - output.append("nuked_corners.jpg"); - //exportImage(srcImageRange(tmp), ImageExportInfo(output.c_str()).setPixelType("UINT8")); - //exit(1); - + if (generate_images){ + string output = path; + output.append("nuked_corners.jpg"); + exportImage(srcImageRange(image), ImageExportInfo(output.c_str()).setPixelType("UINT8")); + } } void detect_edge(BImage& image, FImage& corners, string& file, string& path, string& format){ @@ -510,7 +523,7 @@ // Slice image //sub_image(out); - nuke_corners(image, corners); + nuke_corners(out, corners); extract_coords(out,1); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bl...@us...> - 2009-06-11 15:12:05
|
Revision: 3939 http://hugin.svn.sourceforge.net/hugin/?rev=3939&view=rev Author: blimbo Date: 2009-06-11 15:11:57 +0000 (Thu, 11 Jun 2009) Log Message: ----------- Minimum line length bug fix 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-06-11 14:17:33 UTC (rev 3938) +++ hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/ProcessImage.cpp 2009-06-11 15:11:57 UTC (rev 3939) @@ -574,28 +574,23 @@ if (info.width() > resize_dimension || info.height() > resize_dimension){ if (info.width() >= info.height()){ - sizefactor = (double)resize_dimension/info.width(); // calculate new image size nw = resize_dimension; nh = static_cast<int>(0.5 + (sizefactor*info.height())); min_line_length_squared = (length_threshold*nw)*(length_threshold*nw); - }else{ sizefactor = (double)resize_dimension/info.height(); // calculate new image size nw = static_cast<int>(0.5 + (sizefactor*info.width())); nh = resize_dimension; min_line_length_squared = (length_threshold*nh)*(length_threshold*nh); - - } - + } cout << "Scaling by:\t\t" << sizefactor << endl; cout << "New dimensions:\t\t" << nw << " x " << nh << endl; - cout << "Minimum line length:\t" << (length_threshold*nw) << endl << endl; - - + cout << "Minimum line length:\t" << sqrt(min_line_length_squared) << endl << endl; + // create an image of appropriate size UInt16RGBImage out(nw, nh); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tks...@us...> - 2009-06-23 13:18:47
|
Revision: 3956 http://hugin.svn.sourceforge.net/hugin/?rev=3956&view=rev Author: tksharpless Date: 2009-06-23 13:18:44 +0000 (Tue, 23 Jun 2009) Log Message: ----------- Added an #include needed to compile with MSVC 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-06-23 05:34:34 UTC (rev 3955) +++ hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/ProcessImage.cpp 2009-06-23 13:18:44 UTC (rev 3956) @@ -34,6 +34,9 @@ //#include "LineParamEstimator.h" //#include "PolynomialEstimator.h" #include <ANN/ANN.h> +#ifdef _WIN32 +#include <time.h> +#endif using namespace vigra; using namespace std; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tks...@us...> - 2009-06-23 13:29:02
|
Revision: 3958 http://hugin.svn.sourceforge.net/hugin/?rev=3958&view=rev Author: tksharpless Date: 2009-06-23 13:28:43 +0000 (Tue, 23 Jun 2009) Log Message: ----------- Changed condition on the MSVC specific #include from #ifdef _WIN32 (which is not really MSVC specific) to #if _MSC_VER (which is) 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-06-23 13:27:26 UTC (rev 3957) +++ hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/ProcessImage.cpp 2009-06-23 13:28:43 UTC (rev 3958) @@ -34,7 +34,7 @@ //#include "LineParamEstimator.h" //#include "PolynomialEstimator.h" #include <ANN/ANN.h> -#ifdef _WIN32 +#if _MSC_VER //def _WIN32 #include <time.h> #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bl...@us...> - 2009-06-23 16:02:06
|
Revision: 3960 http://hugin.svn.sourceforge.net/hugin/?rev=3960&view=rev Author: blimbo Date: 2009-06-23 16:02:01 +0000 (Tue, 23 Jun 2009) Log Message: ----------- Moved annClose() 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-06-23 14:02:08 UTC (rev 3959) +++ hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/ProcessImage.cpp 2009-06-23 16:02:01 UTC (rev 3960) @@ -306,8 +306,10 @@ cont = 0; } } + + annClose(); } - annClose(); + double length = line_length_squared(first_line_end_x, first_line_end_y,inliers[inliers.size()-1]->x,inliers[inliers.size()-1]->y); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <bl...@us...> - 2009-08-03 18:23:52
|
Revision: 4160 http://hugin.svn.sourceforge.net/hugin/?rev=4160&view=rev Author: blimbo Date: 2009-08-03 18:23:44 +0000 (Mon, 03 Aug 2009) Log Message: ----------- Fucntion not working properly at them moment.. 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-03 18:16:18 UTC (rev 4159) +++ hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/ProcessImage.cpp 2009-08-03 18:23:44 UTC (rev 4160) @@ -508,7 +508,7 @@ if(verbose) cout << "Above theshold (" << min_line_length_squared << ")" << endl; }else{ // Collect shorter segments - if(length_sq >= min_line_length_squared/6){ + if(length_sq >= min_line_length_squared/10){ short_segments.push_back(inliers); } inliers.clear(); @@ -989,16 +989,17 @@ new_cropFactor = 0; } - if(focal_length && focal_length != new_focal_length){ - cout << "Warning! This image appears to have a different focal length from the previous one!" << endl << endl; + if(focal_length != 0 && focal_length != new_focal_length && new_focal_length){ + cout << "Warning: This image appears to have a different focal length from the previous one." << endl << endl; }else{ - focal_length = new_focal_length; + if(new_focal_length) focal_length = new_focal_length; } - if(cropFactor && cropFactor != new_cropFactor){ - cout << "Waring! This image appears to have a different crop factor from the previous one!" << endl << endl; + if(cropFactor && cropFactor != new_cropFactor && new_cropFactor){ + cout << "Warning: This image appears to have a different crop factor from the previous one." << endl << endl; + //cout << "cropFactor:\t" << cropFactor << " --- new_cropFactor:\t" << new_cropFactor<< endl; }else{ - cropFactor = new_cropFactor; + if(new_cropFactor) cropFactor = new_cropFactor; } /* @@ -1071,122 +1072,184 @@ 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); + double grad = d2/d1; + + //cout << a[0]->x << " - " << a[a.size()-1]->x << " = " << d1 << endl; + //cout << a[0]->y<< " - " << a[a.size()-1]->y <<" = " << d2 << endl; + //cout << "Gradient:\t" << grad << endl << endl; + + return(grad); } double point_line_length_squared(Point2D& a, Point2D& b){ int d1 = a->x - b->x; int d2 = a->y - b->y; + + + //cout << a->x << " - " << b->x << " = " << d1 << endl; + //cout << a->y<< " - " << b->y <<" = " << d2 << endl; + //cout << "Dist^2:\t" << (d1*d1+d2*d2) << endl << endl; + return(d1*d1+d2*d2); } +int smallest_x_value(vector<Point2D>& a){ + int smallest = 100000000; + for(int i = 0; i < a.size(); i++){ + if(a[i]->x < smallest) smallest = a[i]->x; + } + return(smallest); +} + +int largest_x_value(vector<Point2D>& a){ + int largest = -100000; + for(int i = 0; i < a.size(); i++){ + if(a[i]->x > largest) largest = a[i]->x; + } + return(largest); +} +int smallest_y_value(vector<Point2D>& a){ + int smallest = 100000000; + for(int i = 0; i < a.size(); i++){ + if(a[i]->y < smallest) smallest = a[i]->y; + } + return(smallest); +} + +int largest_y_value(vector<Point2D>& a){ + int largest = -100000; + for(int i = 0; i < a.size(); i++){ + if(a[i]->y > largest) largest = a[i]->y; + } + return(largest); +} + 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); - } + + //for(int i = 0; i < short_segments.size(); i++){ + // plot_inliers(seg, image, short_segments[i], i); + //} - int js = 0; - int limit = 40*40; + int tmp_i = 0; + int limit = 1000; for(int i = 0; i < short_segments.size(); i++){ - for(int j = i+1; j < short_segments.size(); j++){ + + int oi_x_max = largest_x_value(short_segments[i]); + int oi_x_min = smallest_x_value(short_segments[i]); + int oi_y_max = largest_y_value(short_segments[i]); + int oi_y_min = smallest_y_value(short_segments[i]); - //cout << i << " - " << j << ":\t" << gradients[i] << " - " << gradients[j] << " = " << abs(gradients[i] - gradients[j]) << endl; + for(int j = 0; j < short_segments.size(); j++){ + + cout << "Lines " << i << " vs " << j << endl; + double a = point_line_length_squared(short_segments[i][0],short_segments[j][0]); + double b = point_line_length_squared(short_segments[i][0],short_segments[j][short_segments[j].size()-1]); + double c = point_line_length_squared(short_segments[i][short_segments[i].size()-1],short_segments[j][0]); + double d = point_line_length_squared(short_segments[i][short_segments[i].size()-1],short_segments[j][short_segments[j].size()-1]); + + int i_x_max = largest_x_value(short_segments[i]); + int i_x_min = smallest_x_value(short_segments[i]); + int i_y_max = largest_y_value(short_segments[i]); + int i_y_min = smallest_y_value(short_segments[i]); + + int j_x_max = largest_x_value(short_segments[j]); + int j_x_min = smallest_x_value(short_segments[j]); + int j_y_max = largest_y_value(short_segments[j]); + int j_y_min = smallest_y_value(short_segments[j]); + + if(j_x_max==oi_x_max && j_y_max==oi_y_max && j_x_min==oi_x_min && j_y_min==oi_y_min){ + break; + }else{ + + //printf("ixmax: %d ixmin: %d iymax: %d iymin: %d\n",i_x_max,i_x_min,i_y_max,i_y_min); + //printf("jxmax: %d jxmin: %d jymax: %d jymin: %d\n",j_x_max,j_x_min,j_y_max,j_y_min); - if ( + if (a < limit || b < limit || c < limit || d < limit){ - - 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; + int overlaps = 0; + if(abs(i_x_max - i_x_min) > abs(i_y_max - i_x_min)){ + // Horizontal line + if (i_x_max > j_x_max){ + if(j_x_max > i_x_min) overlaps = 1; + if(i_x_min < j_x_min) overlaps = 1; + + }else{ + if(i_x_max > j_x_min) overlaps = 1; + if(j_x_min < i_x_min) overlaps = 1; + + } }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){ + // Vertical line + if (i_y_max > j_y_max){ + if(j_y_max > i_y_min) overlaps = 1; + if(i_y_min < j_y_min) overlaps = 1; + }else{ + if(i_y_max > j_y_min) overlaps = 1; + if(j_y_min < i_y_min) overlaps = 1; + } + } + + if(!overlaps){ + + double grad_i = gradient(short_segments[i]); + double grad_j = gradient(short_segments[j]); - double diff = abs(gradient(short_segments[i]) - gradient(short_segments[j])); + if(grad_j >= (grad_i*0.75) && grad_j <= (grad_i*1.25)){ - if(diff < 1){ + //printf("Segement i end points Y= %d and %d\n",largest_y_value(short_segments[i]),smallest_y_value(short_segments[i])); + //printf("Segement i end points X= %d and %d\n",largest_x_value(short_segments[i]),smallest_x_value(short_segments[i])); + cout << "Combining " << tmp_i << " with " << tmp_i+1 << endl; + //plot_inliers(seg, image, short_segments[i], tmp_i); + tmp_i++; + //plot_inliers(seg, image, short_segments[j], tmp_i); + tmp_i++; - cout << gradient(short_segments[i]) << " vs " << gradient(short_segments[j]) << endl; cout << "Diff:\t" << diff << endl; + cout << "J " << j << " size " << short_segments[j].size() << 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); + j = 0; + + //printf("--Segement i end points Y= %d and %d\n",largest_y_value(short_segments[i]),smallest_y_value(short_segments[i])); + //printf("--Segement i end points X= %d and %d\n",largest_x_value(short_segments[i]),smallest_x_value(short_segments[i])); + plot_inliers(jseg, image, short_segments[i], js); js++; }else{ - cout << "Diff too big:\t" << diff << endl; + cout << "Gradients differ by more than 25%" << endl << endl; } }else{ - cout << "Lines overlap:\t" << i << " vs " << j << endl; + cout << "Lines overlap." << endl << endl; } - - + }else{ + cout << "Lines too far away:\t" << i << " vs " << j << endl << endl; + //cout << a << endl << b << endl << c << endl << d << endl; + } + } - + } } + + for(int i = 0; i < short_segments.size(); i++){ + double length_sq = point_line_length_squared(short_segments[i][0],short_segments[i][short_segments[i].size()-1]); + if(length_sq >= min_line_length_squared){ + //plot_inliers(jseg, image, short_segments[i], js); + //js++; + } + //plot_inliers(jseg, image, short_segments[i], js); + //js++; + } } @@ -1204,7 +1267,7 @@ if(original_width && original_height && nw != original_width && nh != original_height){ // Allow for switching between portrait and landscape if (nh != original_width && nw != original_height){ - cout << "Warning! This image appears to have different dimensions from the previous one!" << endl << endl; + cout << "Warning: This image appears to have different dimensions from the previous one." << endl << endl; } } @@ -1278,9 +1341,8 @@ 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,image); + + //join_short_segments(short_segments,image); short_segments.clear(); // Sort lines by distance between first and last point or number of pixels This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bl...@us...> - 2009-08-06 15:28:18
|
Revision: 4178 http://hugin.svn.sourceforge.net/hugin/?rev=4178&view=rev Author: blimbo Date: 2009-08-06 15:28:09 +0000 (Thu, 06 Aug 2009) Log Message: ----------- Fixed sorting issue 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-06 15:00:12 UTC (rev 4177) +++ hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/ProcessImage.cpp 2009-08-06 15:28:09 UTC (rev 4178) @@ -59,6 +59,9 @@ } bool compare_yx (const vigra::Point2D i,const vigra::Point2D j){ + + //return (j->y<i->y); + if(j->x == i->x){ return (j->y>i->y); }else{ @@ -68,10 +71,12 @@ bool compare_xy (const vigra::Point2D i,const vigra::Point2D j){ - if(i->x == j->x){ - return (i->y>j->y); + //return (i->x<j->x); + + if(i->y == j->y){ + return (i->x>j->x); }else{ - return (i->x<j->x); + return (i->y<j->y); } } @@ -1336,8 +1341,10 @@ int i_y_min = min_y_index(joined_segs); if(abs(i_x_max - i_x_min) > abs(i_y_max - i_y_min)){ length_sq = point_line_length_squared(joined_segs[i_x_max],joined_segs[i_x_min]); + sort(joined_segs.begin(), joined_segs.end(), compare_yx); }else{ length_sq = point_line_length_squared(joined_segs[i_y_max],joined_segs[i_y_min]); + sort(joined_segs.begin(), joined_segs.end(), compare_yx); } if(length_sq >= min_line_length_squared){ //plot_inliers(jseg, image, joined_segs, js); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |