I have calculated the projection matrix and verified the re-projection to confirm there are no issues. However, when I tried to add the calculated matrix using AddProjection, I encountered an error: WARNING: In D:\rtk\RTK-2.4.1\src\rtkThreeDCircularProjectionGeometry.cxx, line 357 DataObject (0000018E27CD88D0): Failed to AddProjection
Eigen::Matrix<double, 3, 4> getProjectionTransformMatrix3D(
const std::vector<double>& srcX,
const std::vector<double>& srcY,
const std::vector<double>& srcZ,
const std::vector<double>& dstU,
const std::vector<double>& dstV,
double detectorElementSize) {
size_t n = srcX.size();
Eigen::MatrixXd S(n * 2, 11);
S.setZero();
for (size_t i = 0; i < n; ++i) {
S(2 * i, 0) = -srcX[i];
S(2 * i, 1) = -srcY[i];
S(2 * i, 2) = -srcZ[i];
S(2 * i, 3) = -1;
S(2 * i, 8) = dstU[i] * srcX[i];
S(2 * i, 9) = dstU[i] * srcY[i];
S(2 * i, 10) = dstU[i] * srcZ[i];
S(2 * i + 1, 4) = -srcX[i];
S(2 * i + 1, 5) = -srcY[i];
S(2 * i + 1, 6) = -srcZ[i];
S(2 * i + 1, 7) = -1;
S(2 * i + 1, 8) = dstV[i] * srcX[i];
S(2 * i + 1, 9) = dstV[i] * srcY[i];
S(2 * i + 1, 10) = dstV[i] * srcZ[i];
}
Eigen::VectorXd C(n * 2);
for (size_t i = 0; i < n; ++i) {
C(2 * i) = -dstU[i];
C(2 * i + 1) = -dstV[i];
}
Eigen::VectorXd Unknown = (S.transpose() * S).inverse() * S.transpose() * C;
Eigen::Matrix<double, 3, 4> P;
P << Unknown(0), Unknown(1), Unknown(2), Unknown(3),
Unknown(4), Unknown(5), Unknown(6), Unknown(7),
Unknown(8), Unknown(9), Unknown(10), 1;
Eigen::Matrix3d A_inv = P.leftCols<3>();
Eigen::Matrix3d A = A_inv.inverse();
Eigen::Vector3d e_u = A.col(0);
double L_u_cal = e_u.norm();
double ratio = L_u_cal / detectorElementSize;
Eigen::Matrix<double, 3, 4> new_P = ratio * P;
return new_P;
}
This is my function for calculating the projection matrix
I even tried to generate a projection matrix from the projected points, but the generated matrix still couldn’t be added in
This question is maybe more appropriate for the RTK mailing list. But @simon.rit might answer it here, too.
I don’t have time to closely check code but the addition fails if it can’t decompose the projection matrix in parameters, see the code here. If you know the source and detector positions + the detector orientation, there is no need to compute the projection matrix yourself, just let RTK do it using this version.