00001
00011 #include "ImageCalibrator.hpp"
00012 #include "GslVector.hpp"
00013 #include "GslMatrix.hpp"
00014
00015
00016 void ImageCalibrator::printHomography()
00017 {
00018 homography.print("ImageCalibrator homography");
00019 }
00020
00021
00022
00023 void ImageCalibrator::printPoints()
00024 {
00025 for (unsigned int i = 0; i < points.size(); i++)
00026 printf("x=%.3lf, y=%.3lf, u=%.3lf, v=%.3lf\n",
00027 points[i].x, points[i].y, points[i].u, points[i].v);
00028 }
00029
00030
00031
00032 void ImageCalibrator::recalculateHomography()
00033 {
00034
00035
00036
00037
00038
00039 GslMatrix table (points.size()*2, 9);
00040
00041 GslVector vec(9);
00042
00043 for (unsigned int pointIndex = 0; pointIndex < points.size(); pointIndex++)
00044 {
00045 PointCorrespondence p = points[pointIndex];
00046
00047 vec(0) = p.x;
00048 vec(1) = p.y;
00049 vec(2) = 1;
00050
00051 vec(3) = 0;
00052 vec(4) = 0;
00053 vec(5) = 0;
00054
00055 vec(6) = p.x * -p.u;
00056 vec(7) = p.y * -p.u;
00057 vec(8) = -p.u;
00058
00059 table.setRow (pointIndex*2, vec);
00060
00061 vec(0) = 0;
00062 vec(1) = 0;
00063 vec(2) = 0;
00064
00065 vec(3) = p.x;
00066 vec(4) = p.y;
00067 vec(5) = 1;
00068
00069 vec(6) = p.x * -p.v;
00070 vec(7) = p.y * -p.v;
00071 vec(8) = -p.v;
00072
00073 table.setRow (1+pointIndex*2, vec);
00074 }
00075
00076 GslVector nullspaceVector = getNullspaceVector(table);
00077
00078
00079
00080
00081
00082
00083 for (int rows = 0; rows < 3; rows++)
00084 for (int cols = 0; cols < 3; cols++)
00085 homography(rows,cols) = nullspaceVector(cols+rows*3);
00086 }
00087
00088
00089
00097 GslVector getNullspaceVector (GslMatrix matrix)
00098 {
00099 int matrixRows = matrix.getNumRows();
00100 int matrixCols = matrix.getNumCols();
00101
00102 GslMatrix U = matrix;
00103 GslMatrix V(matrixCols, matrixCols);
00104 GslVector S(matrixCols);
00105
00106 matrix.SingularValueDecomposition(U, S, V);
00107
00108
00109
00110 GslVector result(matrixCols);
00111 for (int i = 0; i < matrixCols; i++)
00112 result(i) = V(i, matrixCols-1);
00113
00114 return result;
00115 }