calibrationTools.h
Go to the documentation of this file.00001
00015 #ifndef DLR_COMPUTERVISION_CALIBRATIONTOOLS_H
00016 #define DLR_COMPUTERVISION_CALIBRATIONTOOLS_H
00017
00018 #include <dlrComputerVision/cameraIntrinsicsPinhole.h>
00019
00020 namespace dlr {
00021
00022 namespace computerVision {
00023
00024
00062 template <class Iter3D, class Iter2D>
00063 CameraIntrinsicsPinhole
00064 estimateCameraIntrinsicsPinhole(size_t numPixelsX, size_t numPixelsY,
00065 Iter3D points3DBegin, Iter3D points3DEnd,
00066 Iter2D points2DBegin);
00067
00068 }
00069
00070 }
00071
00072
00073
00074
00075
00076 #include <dlrNumeric/utilities.h>
00077 #include <dlrLinearAlgebra/linearAlgebra.h>
00078
00079 namespace dlr {
00080
00081 namespace computerVision {
00082
00083
00084
00085
00086 template <class Iter3D, class Iter2D>
00087 CameraIntrinsicsPinhole
00088 estimateCameraIntrinsicsPinhole(size_t numPixelsX, size_t numPixelsY,
00089 Iter3D points3DBegin, Iter3D points3DEnd,
00090 Iter2D points2DBegin)
00091 {
00092
00093
00094 size_t numberOfInputPoints = points3DEnd - points3DBegin;
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 numeric::Array2D<double> AMatrix(3 * numberOfInputPoints, 4);
00175 numeric::Array1D<double> bVector(3 * numberOfInputPoints);
00176 unsigned int rowIndex = 0;
00177 while(points3DBegin != points3DEnd) {
00178 AMatrix(rowIndex, 0) = 0.0;
00179 AMatrix(rowIndex, 1) = -(points3DBegin->y());
00180 AMatrix(rowIndex, 2) = 0.0;
00181 AMatrix(rowIndex, 3) = -(points3DBegin->z());
00182 AMatrix(rowIndex + 1, 0) = points3DBegin->x();
00183 AMatrix(rowIndex + 1, 1) = 0.0;
00184 AMatrix(rowIndex + 1, 2) = points3DBegin->z();
00185 AMatrix(rowIndex + 1, 3) = 0.0;
00186 AMatrix(rowIndex + 2, 0) = -(points2DBegin->y()) * points3DBegin->x();
00187 AMatrix(rowIndex + 2, 1) = points2DBegin->x() * points3DBegin->y();
00188 AMatrix(rowIndex + 2, 2) = -(points2DBegin->y()) * points3DBegin->z();
00189 AMatrix(rowIndex + 2, 3) = points2DBegin->x() * points3DBegin->z();
00190 bVector(rowIndex) = AMatrix(rowIndex + 2, 2);
00191 bVector(rowIndex + 1) = AMatrix(rowIndex + 2, 3);
00192 bVector(rowIndex + 2) = 0.0;
00193
00194 rowIndex += 3;
00195 ++points2DBegin;
00196 ++points3DBegin;
00197 }
00198
00199
00200 numeric::Array2D<double> ATranspose = AMatrix.transpose();
00201 numeric::Array2D<double> ATA = numeric::matrixMultiply(
00202 ATranspose, AMatrix);
00203 numeric::Array1D<double> ATb = numeric::matrixMultiply(
00204 ATranspose, bVector);
00205 linearAlgebra::linearSolveInPlace(ATA, ATb);
00206
00207
00208 double k_x = ATb[0];
00209 double k_y = ATb[1];
00210 double u_0 = ATb[2];
00211 double v_0 = ATb[3];
00212
00213 return CameraIntrinsicsPinhole(
00214 numPixelsX, numPixelsY, 1, 1.0 / k_x, 1.0 / k_y, u_0, v_0);
00215 }
00216
00217 }
00218
00219 }
00220
00221 #endif