Revision: 4106
http://hugin.svn.sourceforge.net/hugin/?rev=4106&view=rev
Author: blimbo
Date: 2009-07-26 23:47:54 +0000 (Sun, 26 Jul 2009)
Log Message:
-----------
Appied Tom's patch, cleaned up ProcessImages.cpp a lot, no longer optimise focal length
Modified Paths:
--------------
hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/Globals.cpp
hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/Globals.h
hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/Main.cpp
hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/MapPoints.cpp
hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/ProcessImage.cpp
hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/ProcessImage.h
Modified: hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/Globals.cpp
===================================================================
--- hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/Globals.cpp 2009-07-26 15:56:01 UTC (rev 4105)
+++ hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/Globals.cpp 2009-07-26 23:47:54 UTC (rev 4106)
@@ -52,7 +52,6 @@
unsigned int vertical_slices = 12;
unsigned int horizontal_slices = 8;
unsigned int generate_images = 1;
-std::vector<vigra::Point2D> inliers;
std::vector<std::vector<vigra::Point2D> > lines;
double sigma = 1.4;
double r = 140;
Modified: hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/Globals.h
===================================================================
--- hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/Globals.h 2009-07-26 15:56:01 UTC (rev 4105)
+++ hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/Globals.h 2009-07-26 23:47:54 UTC (rev 4106)
@@ -35,7 +35,6 @@
extern unsigned int vertical_slices;
extern unsigned int generate_images;
extern unsigned int generate_images;
-extern std::vector<vigra::Point2D> inliers;
extern std::vector<std::vector<vigra::Point2D> > lines;
extern double sigma;
extern double r;
Modified: hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/Main.cpp
===================================================================
--- hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/Main.cpp 2009-07-26 15:56:01 UTC (rev 4105)
+++ hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/Main.cpp 2009-07-26 23:47:54 UTC (rev 4106)
@@ -25,6 +25,8 @@
#include "Globals.h"
#include "ProcessImage.h"
+#include "MapPoints.h"
+
using namespace std;
#define VERSION 0.1
@@ -413,9 +415,21 @@
}
cout << "Processing image " << images[i].c_str() << endl << endl;
process_image(images[i]);
-
}
+ cout << "Found "<< lines.size() <<" lines"<<endl;
+
+ int n_params = 2;
+ if (lens_type == 2) ++n_params;
+ if(optimise_centre) n_params += 2;
+
+ if (lines.size() >= n_params ) map_points();
+ else{
+ cout << "Not enough lines to fit "<< n_params <<" parameters."<<endl;
+ return 3;
+ }
+
+
if (pto_file != ("")){
write_pto(output_pto,pto_file_top,pto_file_cps,pto_file_end,pto_image,cps_per_line);
cout << "Written file " << output_pto << endl;
Modified: hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/MapPoints.cpp
===================================================================
--- hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/MapPoints.cpp 2009-07-26 15:56:01 UTC (rev 4105)
+++ hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/MapPoints.cpp 2009-07-26 23:47:54 UTC (rev 4106)
@@ -27,10 +27,23 @@
using namespace std;
-typedef struct {
+class XYZPoint {
+public:
double x, y, z;
-} XYZPoint;
+ XYZPoint( double X, double Y, double Z )
+ : x(X), y(Y), z(Z) {}
+ XYZPoint() : x(0), y(0), z(0) {}
+};
+XYZPoint XYZdifference( XYZPoint & a, XYZPoint & b ){
+ return XYZPoint( b.x - a.x, b.y - a.y, b.z - a.z );
+}
+
+double XYZdistance( XYZPoint & a, XYZPoint & b ){
+ XYZPoint d = XYZdifference( a, b );
+ return sqrt( d.x * d.x + d.y * d.y + d.z * d.z );
+}
+
XYZPoint CrossProduct (XYZPoint v1, XYZPoint v2){
XYZPoint cp;
cp.x = v1.y * v2.z - v1.z * v2.y;
@@ -58,25 +71,26 @@
double y_centre = 0;
if (lens_type == 2){
if(optimise_centre){
- x_centre = p[4];
- y_centre = p[5];
+ x_centre = p[3];
+ y_centre = p[4];
}
}else{
if(optimise_centre){
- x_centre = p[3];
- y_centre = p[4];
+ x_centre = p[2];
+ y_centre = p[3];
}
}
for (unsigned int l = 0; l < lines.size(); l++){
//cout << "Optimising line " << l+1 << "..." << endl;
+ int npnts = lines[l].size();
//XYZPoint mapped_point[lines[current_line].size()];
- XYZPoint * mapped_point = new XYZPoint[lines[l].size()];
+ XYZPoint * mapped_point = new XYZPoint[npnts];
// Map points to 3D and fill the above array with XYZPoints
- for(unsigned int i = 0; i < lines[l].size(); i++){
+ for(unsigned int i = 0; i < npnts; i++){
double x_point = invert_size_factor * lines[l][i]->x;
double y_point = invert_size_factor * lines[l][i]->y;
@@ -99,13 +113,13 @@
double r = sqrt(x_point * x_point + y_point * y_point);
// u = r / f;
- double u = r / p[0];
+ double u = r / focal_length_pixels;
// R - distance of a point from the center of projection,
// corrected for barrel distortion, unitless, or radians
// (1 - p2 - p4) is for normalisation
- // p2 = p[3], p4 = [4]
- double R = (1 - p[1] - p[2]) * u + p[1] * (u*u) + p[2] * (u*u*u*u);
+ // p2 = p[0], p4 = [1]
+ double R = (1 - p[0] - p[1]) * u + p[0] * (u*u) + p[1] * (u*u*u*u);
// a - angular distance of a point from the center of projection, in radians
double a;
@@ -154,8 +168,8 @@
}
// Vector cross product of the end points - this is the normal to the estimated plane
- XYZPoint norm = CrossProduct(mapped_point[0],mapped_point[n-1]);
-
+ XYZPoint norm = CrossProduct(mapped_point[0],mapped_point[npnts - 1]);
+
/*
cout << endl << "Cross product of end points:" << endl;
cout << norm.x << endl;
@@ -165,15 +179,15 @@
// Comput straigthness error
double ssq = 0;
- for(unsigned int i = 1; i < n - 1; i++){
+ for(unsigned int i = 1; i < npnts - 1; i++){
// Add square of dot product of that point with norm
double d = DotProduct(norm,mapped_point[i]);
ssq += d * d;
}
- // Add to optimizer's error vector
- x[l] = sqrt((n - 2) * ssq );
+ // normalize, weight, add to optimizer's error vecto
+ x[l] = sqrt((npnts - 2) * ssq ) / XYZdistance(mapped_point[0],mapped_point[npnts - 1]);
//cout << "Error:\t" << x[l] << endl;
- line_errors[l] = x[l];
+ line_errors[l] = x[l] / npnts; // save error per data point
delete [] mapped_point;
}
@@ -189,28 +203,28 @@
double info[LM_INFO_SZ];
// Set up initial parameters
- int m = 6;
+ int m = 5;
double * p = new double[m];
- p[0] = focal_length_pixels;
- p[1] = 0; // p2
- p[2] = 0; // p4
+ //p[0] = focal_length_pixels;
+ p[0] = 0; // p2
+ p[1] = 0; // p4
if (lens_type == 2){
- p[3] = 2; // k
+ p[2] = 2; // k
if(optimise_centre){
- p[4] = 0; // x_center;
- p[5] = 0; // y_center;
+ p[3] = 0; // x_center;
+ p[4] = 0; // y_center;
}else{
- m = 4;
+ m = 3;
}
}else{
if(optimise_centre){
- m = 5;
- p[3] = 0; // x_center;
- p[4] = 0; // y_center;
+ m = 4;
+ p[2] = 0; // x_center;
+ p[3] = 0; // y_center;
}else{
- m = 3;
+ m = 2;
}
}
@@ -224,20 +238,20 @@
int ret = dlevmar_dif(&Mapto3d, &visf, p, x, m, n, iterations, NULL, info, NULL, NULL, NULL);
printf("\nLevenberg-Marquardt returned in %g iter, reason %g\nSolution:\n", info[5], info[6]);
- cout << "Focal length:\t\t" << p[0] << endl;
- cout << "p2:\t\t\t" << p[1] << endl;
- cout << "p4:\t\t\t" << p[2] << endl;
+ //cout << "Focal length:\t\t" << p[0] << endl;
+ cout << "p2:\t\t\t" << p[0] << endl;
+ cout << "p4:\t\t\t" << p[1] << endl;
if (lens_type == 2){
- cout << "k:\t\t\t" << p[3] << endl;
+ cout << "k:\t\t\t" << p[2] << endl;
if(optimise_centre){
- cout << "x centre:\t\t" << p[4] << endl;
- cout << "y centre\t\t" << p[5] << endl;
+ cout << "x centre:\t\t" << p[3] << endl;
+ cout << "y centre\t\t" << p[4] << endl;
}
}else{
if(optimise_centre){
- cout << "x centre:\t\t" << p[3] << endl;
- cout << "y centre\t\t" << p[4] << endl;
+ cout << "x centre:\t\t" << p[2] << endl;
+ cout << "y centre\t\t" << p[3] << endl;
}
}
for (unsigned int i = 0; i < n; i++){
Modified: hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/ProcessImage.cpp
===================================================================
--- hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/ProcessImage.cpp 2009-07-26 15:56:01 UTC (rev 4105)
+++ hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/ProcessImage.cpp 2009-07-26 23:47:54 UTC (rev 4106)
@@ -47,7 +47,6 @@
#include <time.h>
#endif
-//using namespace hugin_utils;
using namespace vigra;
using namespace std;
@@ -61,31 +60,6 @@
}
-/*
-void ransac(vector<Point2D>& coords){
-
- cout << coords.size() << " 'edge' coordinates found." << endl;
-
- vector<double> curveParameters;
- double desiredProbabilityForNoOutliers = 0.9;
- double maximalOutlierPercentage = 0.8;
- // Use 4 points
- // Point must be within 10 units of curve to agree
- //ParameterEstimator curveEstimator(3, 0.1);
- //ParameterEstimator curveEstimator(4, 2);
- LineParamEstimator curveEstimator(2,10);
-
- cout << endl << "Computing RANSAC..." << endl;
- double usedData = Ransac::compute(curveParameters, &curveEstimator, coords, desiredProbabilityForNoOutliers, maximalOutlierPercentage);
- //for (int i = 0; i < curveParameters.size(); i++){
- // cout << "Parameter " << i << ":\t" << curveParameters[i] << endl;
- //}
-
- cout << "Percentage of points which were used for final estimate: "<< usedData/coords.size() << " % (" << usedData << ")" << endl << endl;
-
-}
-*/
-
bool compare_yx (const vigra::Point2D i,const vigra::Point2D j){
return (j->x<i->x);
}
@@ -94,26 +68,44 @@
return (i->x<j->x);
}
-void plot_inliers(BImage& image, int i){
+void sort_inliers(vector<Point2D>& inliers){
- vigra::BRGBImage tmp(image.width(),image.height());
- vigra::initImage(srcIterRange(tmp.upperLeft(),
- tmp.upperLeft() + vigra::Diff2D(image.width(),image.height())),
- RGB(255,255,255) );
-
unsigned int top = 0;
unsigned int bottom = 100000;
unsigned int left = 100000;
unsigned int right = 0;
- cout << "Plotting line " << i << ". Pixels:\t" << inliers.size() << endl << endl;
for (unsigned int il = 0; il < inliers.size(); il++){
if(inliers[il]->x < left) left = inliers[il]->x;
if(inliers[il]->x > right) right = inliers[il]->x;
if(inliers[il]->y < bottom) bottom = inliers[il]->y;
if(inliers[il]->y > top) top = inliers[il]->y;
+
+ }
+
+ // Sort pixels for adding CPs to PTO file
+ int d1 = abs(top-bottom);
+ int d2 = abs(right-left);
+ if(d2 > d1){
+ sort(inliers.begin(), inliers.end(), compare_xy);
+ }else{
+ sort(inliers.begin(), inliers.end(), compare_yx);
+ }
+}
+void plot_inliers(BImage& image, vector<Point2D>& inliers, int i){
+
+ vigra::BRGBImage tmp(image.width(),image.height());
+ vigra::initImage(srcIterRange(tmp.upperLeft(),
+ tmp.upperLeft() + vigra::Diff2D(image.width(),image.height())),
+ RGB(255,255,255) );
+
+ cout << "Plotting line " << i << ". Pixels:\t" << inliers.size() << endl << endl;
+ for (unsigned int il = 0; il < inliers.size(); il++){
+
+ /*
+ // Careful, this might segfault if the box goes off the image..
if(il == 0 )vigra::initImage(srcIterRange(tmp.upperLeft() +
vigra::Diff2D(inliers[il]->x-3, inliers[il]->y-3),
tmp.upperLeft() + vigra::Diff2D(inliers[il]->x+3, inliers[il]->y+3)),
@@ -123,22 +115,12 @@
vigra::Diff2D(inliers[il]->x-3, inliers[il]->y-3),
tmp.upperLeft() + vigra::Diff2D(inliers[il]->x+3, inliers[il]->y+3)),
RGB(0,255,0) );
-
+ */
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) );
}
-
- // Sort pixels for adding CPs to PTO file
- int d1 = abs(top-bottom);
- int d2 = abs(right-left);
- if(d2 > d1){
- sort(inliers.begin(), inliers.end(), compare_xy);
- }else{
- sort(inliers.begin(), inliers.end(), compare_yx);
- }
- lines.push_back(inliers);
if (generate_images){
// Export slice to file
@@ -152,12 +134,10 @@
exportImage(srcImageRange(tmp), ImageExportInfo(output.c_str()).setPixelType("UINT8"));
//exportImage(srcImageRange(tmp), output.c_str().setPixelType("UINT8"));
}
-
}
-void find_ann(vector<Point2D>& coords, FVector2Image& edgeness, unsigned int& good_lines){
+void find_ann(vector<Point2D>& coords, FVector2Image& edgeness, vector<Point2D>& inliers, unsigned int& good_lines){
-
int k = 1; // Number of nearest neighbours
int dim = 3; // Dimensions
double eps = 0.0; // Error bound
@@ -340,17 +320,8 @@
}
annDeallocPts(dataPts);
}
- //annDeallocPt(queryPt);
annClose();
-/*
-export MALLOC_CHECK=0
-
-Program received signal SIGSEGV, Segmentation fault.
-[Switching to Thread 0xb714c6d0 (LWP 7191)]
-0xb720958d in free () from /lib/tls/i686/cmov/libc.so.6
-*/
-
double length = line_length_squared(first_line_end_x, first_line_end_y,inliers[inliers.size()-1]->x,inliers[inliers.size()-1]->y);
if(verbose) cout << endl << "Measuring distance from " << first_line_end_x << "," << first_line_end_y << " to " << inliers[inliers.size()-1]->x << "," <<
@@ -369,169 +340,19 @@
}
-void extract_coords(BImage& image, FVector2Image& edgeness, int i){
+void extract_coords(BImage& image, vector<Point2D>& coords){
- vector<Point2D> coords;
-
// Gather black pixels
for (unsigned int h = 0; h < image.height(); h++){
for (unsigned int w = 0; w < image.width(); w++){
-
RGBValue<int,0u,1u,2u> value = image(w,h);
- if (value[0] != 255){
-
+ if (value[0] != 255){
coords.push_back(Point2D(w,h));
-
- //cout << "(" << w << "," << h << ")" << endl;
}
}
}
-
- //ransac(coords);
- //plot_inliers(image,i);
-
- unsigned int intital_coords_size = coords.size();
-
- if(verbose) cout << "Initial 'edge' pixel count:\t" << coords.size() << endl << endl;
-
- // Get 10 strongest lines
- // Stop when only 35% of coordinates are left
- unsigned int good_lines = 0;
- //while (good_lines < 10 && coords.size() && 100*((double)coords.size()/intital_coords_size) >= 25){
- while (good_lines < 10 && coords.size() > 1){
- if(verbose) cout << "Searching for line " << good_lines+1 << ":" << endl;
- if(verbose) cout << "=====================" << endl << endl;
-
- find_ann(coords, edgeness, good_lines);
- //ransac(coords);
-
- if(inliers.size())plot_inliers(image,good_lines);
- if(verbose) cout << "Remaining coords:\t" << coords.size() << "\t(" << 100*((double)coords.size()/intital_coords_size) << " %)" << endl << endl;
-
- inliers.clear();
- }
- if (good_lines == 0){
- cout << "No lines found!" << endl;
- }else{
- //cout << endl;
- }
-
}
-/*
-void sub_image(BImage& image){
-
- unsigned int vertical_slice_width = image.width()/vertical_slices;
- unsigned int horizontal_slice_height = image.height()/horizontal_slices;
-
- //cout << "vertical_slice_width: " << vertical_slice_width << endl;
- //cout << "horizontal_slice_height: " << horizontal_slice_height << endl;
-
- try{
-
- cout << "Generate vertical slices..." << endl;
-
- unsigned int sub_y0 = 0;
- unsigned int sub_y1 = image.height();
-
- for (unsigned int i = 0; i <= vertical_slices; i++){
-
- int sub_x0 = i * vertical_slice_width;
- int sub_x1 = (i+1) * vertical_slice_width;
- // Make the slices overlap by 50%
- if (i){
- sub_x0 -= vertical_slice_width/2;
- sub_x1 -= vertical_slice_width/2;
- }
- if (sub_x1 > image.width()) sub_x1 = image.width();
-
- if (i){
- cout << "Vertical slice " << i << "\t: (" << sub_x0 << "," << sub_y0 << ")\t--->\t(";
- cout << sub_x1 << "," << sub_y1 << ")" << endl;
- }else{
- cout << "Vertical slice " << i << "\t: (" << sub_x0 << "," << sub_y0 << ")\t\t--->\t(";
- cout << sub_x1 << "," << sub_y1 << ")" << endl;
- }
-
- BImage out(sub_x1 - sub_x0, sub_y1 - sub_y0);
- // Copy region of interest by moving the input
- // iterators to the appropriate positions
- copyImage(srcIterRange(image.upperLeft() + Diff2D(sub_x0, sub_y0),
- image.upperLeft() + Diff2D(sub_x1, sub_y1)),
- destImage(out));
-
- // Get line coordinates
- extract_coords(out,i);
-
- if (generate_images){
- // Export slice to file
- string output = path;
- output.append("vertical_slice_");
- stringstream ii;
- ii << i;
- output.append(ii.str());
- output.append(".jpg");
- exportImage(srcImageRange(out), output.c_str());
- }
-
- }
-
- exit(1);
-
- unsigned int sub_x0 = 0;
- unsigned int sub_x1 = image.width();
-
- cout << endl << "Generate horiztonal slices..." << endl;
-
- for (unsigned int i = 0; i <= horizontal_slices; i++){
-
- int sub_y0 = i * horizontal_slice_height;
- int sub_y1 = (i+1) * horizontal_slice_height;
- // Make the slices overlap by 50%
- if (i){
- sub_y0 -= horizontal_slice_height/2;
- sub_y1 -= horizontal_slice_height/2;
- }
- if (sub_y1 > image.height()) sub_y1 = image.height();
-
- if (i){
- cout << "Horizontal slice " << i << "\t: (" << sub_x0 << "," << sub_y0 << ")\t--->\t(";
- cout << sub_x1 << "," << sub_y1 << ")" << endl;
- }else{
- cout << "Horizontal slice " << i << "\t: (" << sub_x0 << "," << sub_y0 << ")\t\t--->\t(";
- cout << sub_x1 << "," << sub_y1 << ")" << endl;
- }
-
- BImage out(sub_x1 - sub_x0, sub_y1 - sub_y0);
- // Copy region of interest by moving the input
- // iterators to the appropriate positions
- copyImage(srcIterRange(image.upperLeft() + Diff2D(sub_x0, sub_y0),
- image.upperLeft() + Diff2D(sub_x1, sub_y1)),
- destImage(out));
-
- // Get line coordinates
- extract_coords(out,i);
-
- if (generate_images){
- //Export slice to file
- string output = path;
- output.append("horizontal_slice_");
- stringstream ii;
- ii << i;
- output.append(ii.str());
- output.append(".jpg");
- exportImage(srcImageRange(out), output.c_str());
- }
- }
- }
-
- catch (StdException & e){
- cout << e.what() << endl;
- }
-
-}
-*/
-
void nuke_corners(BImage& image, FImage& corners, string& file){
for (unsigned int h = 0; h < corners.height(); h++){
@@ -612,31 +433,25 @@
}
}
-void detect_edge(BImage& image, FImage& corners, FVector2Image& edgeness, string& file, string& path, string& format){
+void detect_edge(BImage& image, string& file, string& path, string& format, BImage& edge_image){
- try{
-
+ try{
// Paint output image white
- BImage out(image.width(), image.height());
- //cout << image.width() << " x " << image.height() << endl;
- out = 255;
+ edge_image = 255;
cout << "Detecting edges..." << endl << endl;
- if(detector){
-
+ if(detector){
// Call Shen-Castan detector algorithm
- differenceOfExponentialEdgeImage(srcImageRange(image), destImage(out),
+ differenceOfExponentialEdgeImage(srcImageRange(image), destImage(edge_image),
scale, threshold, 0);
- }else{
-
+ }else{
// Call Canny detector algorithm
- cannyEdgeImage(srcImageRange(image), destImage(out),
+ cannyEdgeImage(srcImageRange(image), destImage(edge_image),
scale, threshold, 0);
}
if (generate_images){
-
// Create output file name
string output = path;
@@ -658,32 +473,25 @@
output.append(format);
cout << "Writing " << output << endl;
- exportImage(srcImageRange(out), output.c_str());
+ exportImage(srcImageRange(edge_image), output.c_str());
}
+ }
+ catch (StdException & e){
+ cout << e.what() << endl;
+ }
+}
+void generate_boundary_tensor(BImage& image, FVector2Image& edgeness, FImage& cornerness){
- // Get cornerness from edge detection output
- // Create image of appropriate size for boundary tensor
- FVector3Image boundarytensor(image.width(), image.height());
+ // Get cornerness from edge detection output
+ // Create image of appropriate size for boundary tensor
+ FVector3Image boundarytensor(image.width(), image.height());
- // Calculate the boundary tensor
- cout << "Calculating boundary tensor..." << endl;
- boundaryTensor(srcImageRange(out), destImage(boundarytensor), tscale);
+ // Calculate the boundary tensor
+ cout << "Calculating boundary tensor..." << endl;
+ boundaryTensor(srcImageRange(image), destImage(boundarytensor), tscale);
- FImage boundarystrength(image.width(), image.height()), cornerness(image.width(), image.height());
- FVector2Image edgeness(image.width(), image.height());
-
- tensorTrace(srcImageRange(boundarytensor), destImage(boundarystrength));
- tensorToEdgeCorner(srcImageRange(boundarytensor), destImage(edgeness), destImage(cornerness));
-
- nuke_corners(out, cornerness, file);
- extract_coords(out, edgeness, 1);
-
- }
-
- catch (StdException & e){
- cout << e.what() << endl;
- }
+ tensorToEdgeCorner(srcImageRange(boundarytensor), destImage(edgeness), destImage(cornerness));
}
#ifdef HUGIN_USE_EXIV2
@@ -948,44 +756,21 @@
}
-void process_image(string& filename){
-
- ImageImportInfo info(filename.c_str());
-
- UInt16RGBImage in(info.width(), info.height());
-
- importImage(info, destImage(in));
-
- int nw = info.width(), nh = info.height();
+void resize_image(UInt16RGBImage& in, int& nw, int& nh){
- original_width = info.width();
- original_height = info.height();
-
- if (focal_length && cropFactor){
- calculate_focal_length_pixels();
- }else{
- int exif_ok = get_exif_data(filename);
- }
-
- if (nw > nh){
- min_line_length_squared = (length_threshold*nw)*(length_threshold*nw);
- }else{
- min_line_length_squared = (length_threshold*nh)*(length_threshold*nh);
- }
-
// Re-size to max dimension
- if (info.width() > resize_dimension || info.height() > resize_dimension){
+ if (in.width() > resize_dimension || in.height() > resize_dimension){
- if (info.width() >= info.height()){
- sizefactor = (double)resize_dimension/info.width();
+ if (in.width() >= in.height()){
+ sizefactor = (double)resize_dimension/in.width();
// calculate new image size
nw = resize_dimension;
- nh = static_cast<int>(0.5 + (sizefactor*info.height()));
+ nh = static_cast<int>(0.5 + (sizefactor*in.height()));
min_line_length_squared = (length_threshold*nw)*(length_threshold*nw);
}else{
- sizefactor = (double)resize_dimension/info.height();
+ sizefactor = (double)resize_dimension/in.height();
// calculate new image size
- nw = static_cast<int>(0.5 + (sizefactor*info.width()));
+ nw = static_cast<int>(0.5 + (sizefactor*in.width()));
nh = resize_dimension;
min_line_length_squared = (length_threshold*nh)*(length_threshold*nh);
}
@@ -1001,63 +786,79 @@
resizeImageNoInterpolation(srcImageRange(in),destImageRange(out));
in = out;
-
- //exportImage(srcImageRange(in), ImageExportInfo("resized.jpg").setPixelType("UINT8"));
- //exportImage(srcImageRange(in), ImageExportInfo("resized.tif").setPixelType("UINT16"));
+ }
+}
+void process_image(string& filename){
+
+ ImageImportInfo info(filename.c_str());
+
+ UInt16RGBImage in(info.width(), info.height());
+
+ importImage(info, destImage(in));
+
+ int nw = info.width(), nh = info.height();
+
+ original_width = info.width();
+ original_height = info.height();
+
+ if (focal_length && cropFactor){
+ calculate_focal_length_pixels();
+ }else{
+ int exif_ok = get_exif_data(filename);
}
+
+ if (nw > nh){
+ min_line_length_squared = (length_threshold*nw)*(length_threshold*nw);
+ }else{
+ min_line_length_squared = (length_threshold*nh)*(length_threshold*nh);
+ }
+ // Resize image
+ resize_image(in, nw, nh);
+
// Convert to greyscale
BImage grey(nw, nh);
copyImage(srcImageRange(in, RGBToGrayAccessor<RGBValue<UInt16> >()), destImage(grey));
- //exportImage(srcImageRange(grey), ImageExportInfo("resized.jpg").setPixelType("UINT8"));
- // Uncomment this block to generate images at different scales/thresholds
- /*
+ BImage image(nw, nh);
+ FVector2Image edgeness(nw,nh);
+ FImage cornerness(nw, nh);
+ vector<Point2D> coords, inliers;
+
+ // Run Canny edge detector
+ detect_edge(grey, filename, path, format, image);
- double scale_start = 0.1 ,scale_stop = 25;
- double threshold_start = 0, threshold_stop = 10;
- double scale_increment = 2, threshold_increment = 1;
+ // Generate boundary tensor
+ generate_boundary_tensor(image, edgeness, cornerness);
- for (double threshold_test = threshold_start; threshold_test <= threshold_stop; threshold_test += threshold_increment){
+ // Remove corners
+ nuke_corners(image, cornerness, filename);
- for (double scale_test = scale_start;scale_test <= scale_stop; scale_test += scale_increment){
-
- detect_edge(grey, filename, path, format);
+ // Get coordinates
+ extract_coords(image, coords);
- }
+ unsigned int intital_coords_size = coords.size();
+
+ if(verbose) cout << "Initial 'edge' pixel count:\t" << coords.size() << endl << endl;
+
+ // Get 10 strongest lines
+ unsigned int good_lines = 0;
+ while (good_lines < 10 && coords.size() > 1){
+ if(verbose) cout << "Searching for line " << good_lines+1 << ":" << endl;
+ if(verbose) cout << "=====================" << endl << endl;
+ find_ann(coords, edgeness, inliers, good_lines);
+ if(inliers.size()){
+ sort_inliers(inliers);
+ plot_inliers(image,inliers,good_lines);
+ lines.push_back(inliers);
+ inliers.clear();
+ }
+ if(verbose) cout << "Remaining coords:\t" << coords.size() << "\t(" << 100*((double)coords.size()/intital_coords_size) << " %)" << endl << endl;
+
}
- */
+ if (good_lines == 0){
+ cout << "No lines found!" << endl;
+ }
- // Create image of appropriate size for boundary tensor
- FVector3Image boundarytensor(nw, nh);
-
- // Calculate the boundary tensor
- //cout << "Calculating boundary tensor using original image..." << endl;
- boundaryTensor(srcImageRange(grey), destImage(boundarytensor), tscale);
-
- FImage boundarystrength(nw, nh), cornerness(nw, nh);
- FVector2Image edgeness(nw,nh);
-
- tensorTrace(srcImageRange(boundarytensor), destImage(boundarystrength));
- tensorToEdgeCorner(srcImageRange(boundarytensor), destImage(edgeness), destImage(cornerness));
-
- //for(int h = 0; h < nh; h++){
- // for(int w = 0; w < nw; w++){
- // TinyVector<float, 2> value = edgeness(w,h);
- // cout << w << "," << h << ":\t" << value[0] << " " << value[1] << endl;
- // }
- //}
-
- string output = path;
- output.append("boundarystrength.jpg");
- exportImage(srcImageRange(boundarystrength), ImageExportInfo(output.c_str()).setPixelType("UINT8"));
- output = path;
- output.append("cornerstrength.jpg");
- exportImage(srcImageRange(cornerness), ImageExportInfo(output.c_str()).setPixelType("UINT8"));
-
- detect_edge(grey, cornerness, edgeness, filename, path, format);
-
- if (lines.size()) map_points();
-
}
Modified: hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/ProcessImage.h
===================================================================
--- hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/ProcessImage.h 2009-07-26 15:56:01 UTC (rev 4105)
+++ hugin/branches/gsoc2009_lenscalibration/src/lens_calibrate/ProcessImage.h 2009-07-26 23:47:54 UTC (rev 4106)
@@ -7,13 +7,13 @@
double line_length_squared(int, int, int, int);
bool compare_xy (const vigra::Point2D,const vigra::Point2D);
bool compare_yx (const vigra::Point2D,const vigra::Point2D);
-//void ransac(std::vector<vigra::Point2D>&);
+void resize_image(vigra::UInt16RGBImage&, int&, int&);
void find_ann(std::vector<vigra::Point2D>&, vigra::FVector2Image&, unsigned int&);
-void plot_inliers(vigra::BImage& image, int);
-void extract_coords(vigra::BImage&, vigra::FVector2Image&, int);
+void sort_inliers(std::vector<vigra::Point2D>&);
+void plot_inliers(vigra::BImage& image, std::vector<vigra::Point2D>&, int);
+void extract_coords(vigra::BImage&, std::vector<vigra::Point2D>&);
void nuke_corners(vigra::BImage&, vigra::FImage&, std::string&);
-//void sub_image(vigra::BImage& image);
-void detect_edge(vigra::BImage&, vigra::FImage&, vigra::FVector2Image&, std::string&, std::string&, std::string&);
+void detect_edge(vigra::BImage&, std::string&, std::string&, std::string&, vigra::BImage&);
void process_image(std::string&);
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|