91 m_pP =
new Vec3d[m_nPoints];
93 m_tPbar = pObjectPoints[0];
94 for (i = 1; i < m_nPoints; i++)
99 for (i = 0; i < m_nPoints; i++)
103 m_pQ =
new Vec3d[m_nPoints];
106 m_pF =
new Mat3d[m_nPoints];
122 Mat3d &rotationMatrix,
Vec3d &translationVector,
127 printf(
"error: too few points for object pose estimation.\n");
137 for (i = 0; i < m_nPoints; i++)
139 m_pQ[i].
x = (pImagePoints[i].
x - principalPoint.
x) / focalLength.
x;
140 m_pQ[i].
y = (pImagePoints[i].
y - principalPoint.
y) / focalLength.
y;
145 for (i = 0; i < m_nPoints; i++)
157 for (i = 1; i < m_nPoints; i++)
168 float old_error, new_error;
171 AbsKernel(rotationMatrix, translationVector, old_error);
173 AbsKernel(rotationMatrix, translationVector, new_error);
176 while (fabsf((old_error - new_error) / old_error) >
TOL && new_error >
EPSILON && it < nMaxIterations)
178 old_error = new_error;
179 AbsKernel(rotationMatrix, translationVector, new_error);
197 void CObjectPose::AbsKernel(
Mat3d &R,
Vec3d &t,
float &error)
202 for (i = 0; i < m_nPoints; i++)
208 for (i = 1; i < m_nPoints; i++)
211 for (i = 0; i < m_nPoints; i++)
217 for (i = 0; i < 9; i++)
219 for (i = 0; i < m_nPoints; i++)
222 fM.data[0] = fM.data[0] + temp.
r1; fM.data[1] = fM.data[1] + temp.
r2; fM.data[2] = fM.data[2] + temp.
r3;
223 fM.data[3] = fM.data[3] + temp.
r4; fM.data[4] = fM.data[4] + temp.
r5; fM.data[5] = fM.data[5] + temp.
r6;
224 fM.data[6] = fM.data[6] + temp.
r7; fM.data[7] = fM.data[7] + temp.
r8; fM.data[8] = fM.data[8] + temp.
r9;
236 transU.
r1 = float(fU.data[0]); transU.
r2 = float(fU.data[1]); transU.
r3 = float(fU.data[2]);
237 transU.
r4 = float(fU.data[3]); transU.
r5 = float(fU.data[4]); transU.
r6 = float(fU.data[5]);
238 transU.
r7 = float(fU.data[6]); transU.
r8 = float(fU.data[7]); transU.
r9 = float(fU.data[8]);
241 temp.
r1 = float(fV.data[0]); temp.
r2 = float(fV.data[1]); temp.
r3 = float(fV.data[2]);
242 temp.
r4 = float(fV.data[3]); temp.
r5 = float(fV.data[4]); temp.
r6 = float(fV.data[5]);
243 temp.
r7 = float(fV.data[6]); temp.
r8 = float(fV.data[7]); temp.
r9 = float(fV.data[8]);
255 temp.
r1 = float(-fV.data[0]); temp.
r2 = float(-fV.data[1]); temp.
r3 = float(fV.data[2]);
256 temp.
r4 = float(-fV.data[3]); temp.
r5 = float(-fV.data[4]); temp.
r6 = float(fV.data[5]);
257 temp.
r7 = float(-fV.data[6]); temp.
r8 = float(-fV.data[7]); temp.
r9 = float(fV.data[8]);
266 temp.
r1 = float(fV.data[0]); temp.
r2 = float(fV.data[1]); temp.
r3 = float(-fV.data[2]);
267 temp.
r4 = float(fV.data[3]); temp.
r5 = float(fV.data[4]); temp.
r6 = float(-fV.data[5]);
268 temp.
r7 = float(fV.data[6]); temp.
r8 = float(fV.data[7]); temp.
r9 = float(-fV.data[8]);
276 temp.
r1 = float(-fV.data[0]); temp.
r2 = float(-fV.data[1]); temp.
r3 = float(-fV.data[2]);
277 temp.
r4 = float(-fV.data[3]); temp.
r5 = float(-fV.data[4]); temp.
r6 = float(-fV.data[5]);
278 temp.
r7 = float(-fV.data[6]); temp.
r8 = float(-fV.data[7]); temp.
r9 = float(-fV.data[8]);
286 for (i = 0; i < m_nPoints; i++)
297 for (i = 0; i < m_nPoints; i++)
313 for (
int i = 0; i < m_nPoints; i++)
void SVD(const CFloatMatrix *A, CFloatMatrix *W, CFloatMatrix *U=0, CFloatMatrix *V=0, bool bAllowModifyA=false, bool bReturnUTransposed=false, bool bReturnVTransposed=false)
void Invert(const Mat3d &matrix, Mat3d &result)
Data structure for the representation of a 2D vector.
Data structure for the representation of a matrix of values of the data type double.
Vec3d m_translation_inverse
Translation vector of the inverted extrinsic transformation.
void AddToMat(Mat3d &matrix, const Mat3d &matrixToAdd)
float Det(const Mat3d &matrix)
const CCameraParameters & GetCameraParameters() const
Gives access to the camera parameters.
void MulVecTransposedVec(const Vec3d &vector1, const Vec3d &vector2, Mat3d &result)
CObjectPose(const Vec3d *pObjectPoints, int nPoints)
void SubtractVecVec(const Vec3d &vector1, const Vec3d &vector2, Vec3d &result)
void MulMatMat(const Mat3d &matrix1, const Mat3d &matrix2, Mat3d &result)
void Transpose(const CFloatMatrix *pMatrix, CFloatMatrix *pResultMatrix)
Data structure for the representation of a 3D vector.
void MulMatVec(const Mat3d &matrix, const Vec3d &vec, Vec3d &result)
Camera model parameters and functions for a single camera.
float SquaredLength(const Vec3d &vec)
bool EstimatePose(const Vec2d *pImagePoints, Mat3d &rotationMatrix, Vec3d &translationVector, const CCalibration *pCalibration, int nMaxIterations=350)
void AddVecVec(const Vec3d &vector1, const Vec3d &vector2, Vec3d &result)
Mat3d m_rotation_inverse
Rotation matrix of the inverted extrinsic transformation.
void AddToVec(Vec3d &vec, const Vec3d &vectorToAdd)
void SubtractMatMat(const Mat3d &matrix1, const Mat3d &matrix2, Mat3d &result)
Data structure for the representation of a 3x3 matrix.
void MulMatScalar(const Mat3d &matrix, float scalar, Mat3d &result)
void MulVecScalar(const Vec3d &vec, float scalar, Vec3d &result)