Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <new>
00042
00043 #include "StereoCalibrationCV.h"
00044 #include "StereoCalibration.h"
00045 #include "Calibration.h"
00046 #include "Math/Math3d.h"
00047
00048 #include <stdio.h>
00049
00050
00051
00052 static void FillMatrix(float *pTargetMatrix, const Mat3d &sourceMatrix)
00053 {
00054 pTargetMatrix[0] = sourceMatrix.r1;
00055 pTargetMatrix[1] = sourceMatrix.r2;
00056 pTargetMatrix[2] = sourceMatrix.r3;
00057 pTargetMatrix[3] = sourceMatrix.r4;
00058 pTargetMatrix[4] = sourceMatrix.r5;
00059 pTargetMatrix[5] = sourceMatrix.r6;
00060 pTargetMatrix[6] = sourceMatrix.r7;
00061 pTargetMatrix[7] = sourceMatrix.r8;
00062 pTargetMatrix[8] = sourceMatrix.r9;
00063 }
00064
00065 static void FillMatrix(double *pTargetMatrix, const Mat3d &sourceMatrix)
00066 {
00067 pTargetMatrix[0] = sourceMatrix.r1;
00068 pTargetMatrix[1] = sourceMatrix.r2;
00069 pTargetMatrix[2] = sourceMatrix.r3;
00070 pTargetMatrix[3] = sourceMatrix.r4;
00071 pTargetMatrix[4] = sourceMatrix.r5;
00072 pTargetMatrix[5] = sourceMatrix.r6;
00073 pTargetMatrix[6] = sourceMatrix.r7;
00074 pTargetMatrix[7] = sourceMatrix.r8;
00075 pTargetMatrix[8] = sourceMatrix.r9;
00076 }
00077
00078 static void FillVector(float *pTargetVector, const Vec3d &sourceVector)
00079 {
00080 pTargetVector[0] = (float) sourceVector.x;
00081 pTargetVector[1] = (float) sourceVector.y;
00082 pTargetVector[2] = (float) sourceVector.z;
00083 }
00084
00085 static void FillCalibrationMatrix(float *pTargetMatrix, const CCalibration::CCameraParameters &cameraParameters)
00086 {
00087 pTargetMatrix[0] = (float) cameraParameters.focalLength.x;
00088 pTargetMatrix[1] = 0;
00089 pTargetMatrix[2] = (float) cameraParameters.principalPoint.x;
00090 pTargetMatrix[3] = 0;
00091 pTargetMatrix[4] = (float) cameraParameters.focalLength.y;
00092 pTargetMatrix[5] = (float) cameraParameters.principalPoint.y;
00093 pTargetMatrix[6] = 0;
00094 pTargetMatrix[7] = 0;
00095 pTargetMatrix[8] = 1;
00096 }
00097
00098
00099 void CalculateRectificationHomographies(CStereoCalibration *pStereoCalibration)
00100 {
00101 CvStereoCamera stereoParams;
00102 CvCamera leftCamera, rightCamera;
00103
00104 stereoParams.camera[0] = &leftCamera;
00105 stereoParams.camera[1] = &rightCamera;
00106
00107 stereoParams.camera[0]->imgSize[0] = (float) pStereoCalibration->width;
00108 stereoParams.camera[0]->imgSize[1] = (float) pStereoCalibration->height;
00109 stereoParams.camera[1]->imgSize[0] = (float) pStereoCalibration->width;
00110 stereoParams.camera[1]->imgSize[1] = (float) pStereoCalibration->height;
00111
00112 const CCalibration::CCameraParameters &leftCameraParameters = pStereoCalibration->GetLeftCalibration()->GetCameraParameters();
00113 const CCalibration::CCameraParameters &rightCameraParameters = pStereoCalibration->GetRightCalibration()->GetCameraParameters();
00114
00115 FillMatrix(stereoParams.rotMatrix, pStereoCalibration->GetRightCalibration()->m_rotation_inverse);
00116 FillVector(stereoParams.transVector, pStereoCalibration->GetRightCalibration()->m_translation_inverse);
00117
00118 int i;
00119
00120 leftCamera.imgSize[0] = (float) leftCameraParameters.width;
00121 leftCamera.imgSize[1] = (float) leftCameraParameters.height;
00122 FillCalibrationMatrix(leftCamera.matrix, leftCameraParameters);
00123 for (i = 0; i < 4; i++) leftCamera.distortion[i] = (float) leftCameraParameters.distortion[i];
00124 FillMatrix(leftCamera.rotMatr, leftCameraParameters.rotation);
00125 FillVector(leftCamera.transVect, leftCameraParameters.translation);
00126
00127 rightCamera.imgSize[0] = (float) rightCameraParameters.width;
00128 rightCamera.imgSize[1] = (float) rightCameraParameters.height;
00129 FillCalibrationMatrix(rightCamera.matrix, rightCameraParameters);
00130 for (i = 0; i < 4; i++) rightCamera.distortion[i] = (float) rightCameraParameters.distortion[i];
00131 FillMatrix(rightCamera.rotMatr, rightCameraParameters.rotation);
00132 FillVector(rightCamera.transVect, rightCameraParameters.translation);
00133
00134 icvComputeRestStereoParams(&stereoParams);
00135
00136 Math3d::SetMat(pStereoCalibration->rectificationHomographyLeft,
00137 float(stereoParams.coeffs[0][0][0]),
00138 float(stereoParams.coeffs[0][0][1]),
00139 float(stereoParams.coeffs[0][0][2]),
00140 float(stereoParams.coeffs[0][1][0]),
00141 float(stereoParams.coeffs[0][1][1]),
00142 float(stereoParams.coeffs[0][1][2]),
00143 float(stereoParams.coeffs[0][2][0]),
00144 float(stereoParams.coeffs[0][2][1]),
00145 float(stereoParams.coeffs[0][2][2])
00146 );
00147
00148 Math3d::SetMat(pStereoCalibration->rectificationHomographyRight,
00149 float(stereoParams.coeffs[1][0][0]),
00150 float(stereoParams.coeffs[1][0][1]),
00151 float(stereoParams.coeffs[1][0][2]),
00152 float(stereoParams.coeffs[1][1][0]),
00153 float(stereoParams.coeffs[1][1][1]),
00154 float(stereoParams.coeffs[1][1][2]),
00155 float(stereoParams.coeffs[1][2][0]),
00156 float(stereoParams.coeffs[1][2][1]),
00157 float(stereoParams.coeffs[1][2][2])
00158 );
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Thu Jun 6 2019 21:46:58