12 #include <Eigen/Dense>    20     Eigen::MatrixXd obj_pts_, Eigen::MatrixXd img_pts_,
    21     Eigen::MatrixXd camera_intrinsic_, 
int n0)
    24     img_pts = img_pts_.block(0, 0, n0, 2);
    26     R = Eigen::MatrixXd::Identity(3, 3);
    27     t = Eigen::VectorXd::Zero(3);
    35     obj_vecs = Eigen::MatrixXd::Zero(n0, 3);
    37     for (
int i = 0; i < 
n; i++)
    40     img_vecs = Eigen::MatrixXd::Zero(n0, 2);
    48     Eigen::Vector3d I0, J0, r1, r2, r3;
    49     double I0_norm, J0_norm;
    54     for (i = 0; i < 3; i++)
    56         I0(i) = obj_matrix.row(i).dot(img_vecs.col(0));
    57         J0(i) = obj_matrix.row(i).dot(img_vecs.col(1));
    63     scale = (I0_norm + J0_norm) / 2;
    66     t(0) = img_pts(0, 0) / scale;
    67     t(1) = img_pts(0, 1) / scale;
    86     Eigen::Ref<Eigen::Matrix3d> R_, Eigen::Ref<Eigen::Vector3d> t_)
    88     Eigen::FullPivLU<Eigen::MatrixXd> lu(obj_pts);
    89     if (lu.rank() < 3) 
return false;
    92     long imageDiff = 1000;
    98             for (i = 0; i < img_vecs.rows(); i++)
    99                 img_vecs.row(i) = img_pts.row(i) - img_pts.row(0);
   106             for (i = 0; i < n; i++)
   108                 epsilons(i) += obj_vecs.row(i).dot(
R.row(2));
   113             for (i = 0; i < n; i++)
   116                     img_pts.row(i) * (1 + epsilons(i)) - img_pts.row(0);
   119             imageDiff = this->get_img_diff();
   122         img_vecs_old = img_vecs;
   126         if (iCount > 0 && imageDiff == 0) 
break;
   130             std::cout << 
"Solution Not converged" << std::endl << std::endl;
   142     double sumOfDiffs = 0;
   144     for (
int i = 0; i < n; i++)
   146         for (
int j = 0; j < 2; j++)
   148             sumOfDiffs += std::abs(
   149                 floor(0.5 + img_vecs(i, j)) - floor(0.5 + img_vecs_old(i, j)));
   152     return static_cast<long>(sumOfDiffs);
 
bool compute_pose(Eigen::Ref< Eigen::Matrix3d > R_, Eigen::Ref< Eigen::Vector3d > t_)
Computes pose using iterative computation of  POS() 
 
Eigen::VectorXd epsilons
Focal Length from camera intrinsic matrix. 
 
Eigen::MatrixXd obj_vecs
Translation Vector. 
 
Eigen::MatrixXd R
Number of 2d/3d correspondences. 
 
int n
Co-efficients used for scaling. 
 
Eigen::VectorXd t
Rotation Matrix. 
 
posit(Eigen::MatrixXd obj_pts_, Eigen::MatrixXd img_pts_, Eigen::MatrixXd camera_intrinsic_, int n)
Used to store img_vecs from previous iteration. 
 
Eigen::MatrixXd img_pts
Object Points in Camera Co-ordinate system. 
 
long get_img_diff()
Function to check for convergence. 
 
Eigen::MatrixXd img_vecs
Object Points relative to 1st object point. 
 
double f
Pseudo-Inverse of Object Points matrix. 
 
Pose from Orthogonality and Scaling (POSIT) - Eigen Implementation. 
 
Eigen::MatrixXd obj_matrix
Camera Intrinsic matrix. 
 
Eigen::MatrixXd cam_intrinsic
Image Points in pixels. 
 
Eigen::MatrixXd img_vecs_old
Image Points relative to 1st image point. 
 
void POS()
Function used to compute pose from orthogonality.