Pose estimation for augmented reality
|
The estimation of an homography from coplanar points can be easily and precisely achieved using a Direct Linear Transform algorithm [3] [5] based on the resolution of a linear system.
The following source code also available in homography-dlt.cpp allows to estimate the homography between matched coplanar points. At least 4 points are required.
First of all we inlude the header of the files that are requested to manipulate vectors and matrices.
Then we introduce the function that does the homography estimation.
From a vector of planar points in image
and a vector of matched points
in image
it allows to estimate the homography
:
The implementation of the Direct Linear Transform algorithm to estimate is done next. First, for each point we update the values of matrix A using equation (33). Then we solve the system
using a Singular Value Decomposition of
. Finaly, we determine the smallest eigen value that allows to identify the eigen vector that corresponds to the solution
.
From now the resulting eigen vector that corresponds to the minimal eigen value of matrix
is used to update the homography
.
Finally we define the main() function in which we will initialize the input data before calling the previous function.
First in the main() we create the data structures that will contain the 3D points coordinates wX in the world frame, their coordinates in the camera frame 1 c1X and 2 c2X and their coordinates in the image plane x1 and x2 obtained after perspective projection. Note here that at least 4 coplanar points are requested to estimate the 8 parameters of the homography.
For our simulation we then initialize the input data from a ground truth pose c1Tw_truth that corresponds to the pose of the camera in frame 1 with respect to the object frame. For each point, we compute their coordinates in the camera frame 1 (c1X, c1Y, c1Z). These values are then used to compute their coordinates in the image plane (x1, y1) using perspective projection.
Thanks to the ground truth transformation c2Tc1 between camera frame 2 and camera frame 1, we compute also the coordinates of the points in camera frame 2 (c2X, c2Y, c2Z) and their corresponding coordinates (x2, y2) in the image plane.
From here we have initialized and
. We are now ready to call the function that does the homography estimation.
If you run the previous code, it we produce the following result that shows that the estimated pose is equal to the ground truth one used to generate the input data: