Match a sparse set of points between the two images. There are multiple ways of finding point correspondences between two images. This example detects corners in the first image using the detectMinEigenFeatures function, and tracks them into the second image using vision.PointTracker. Alternatively you can use extractFeatures followed by matchFeatures.
Estimate the fundamental matrix using estimateFundamentalMatrix.
Compute the motion of the camera using the relativeCameraPose function.
Match a dense set of points between the two images. Re-detect the point using detectMinEigenFeatures with a reduced 'MinQuality' to get more points. Then track the dense points into the second image using vision.PointTracker.
Determine the 3-D locations of the matched points using triangulate.
Detect an object of a known size. In this scene there is a globe, whose radius is known to be 10cm. Use pcfitsphere to find the globe in the point cloud.
Recover the actual scale, resulting in a metric reconstruction.
Load a pair of images into the workspace.
This example uses the camera parameters calculated by the cameraCalibrator app. The parameters are stored in the cameraParams object, and include the camera intrinsics and lens distortion coefficients.
Lens distortion can affect the accuracy of the final reconstruction. You can remove the distortion from each of the images using the undistortImage function. This process straightens the lines that are bent by the radial distortion of the lens.
Detect good features to track. Reduce 'MinQuality' to detect fewer points, which would be more uniformly distributed throughout the image. If the motion of the camera is not very large, then tracking using the KLT algorithm is a good way to establish point correspondences.
Use the estimateEssentialMatrix function to compute the essential matrix and find the inlier points that meet the epipolar constraint.
Compute the location and orientation of the second camera relative to the first one. Note that t is a unit vector, because translation can only be computed up to scale.
Re-detect points in the first image using lower 'MinQuality' to get more points. Track the new points into the second image. Estimate the 3-D locations corresponding to the matched points using the triangulate function, which implements the Direct Linear Transformation (DLT) algorithm . Place the origin at the optical center of the camera corresponding to the first image.
% rotation matrix is identity, and its translation vector is 0.
Use the plotCamera function to visualize the locations and orientations of the camera, and the pcshow function to visualize the point cloud.
Find the globe in the point cloud by fitting a sphere to the 3-D points using the pcfitsphere function.
The actual radius of the globe is 10cm. You can now determine the coordinates of the 3-D points in centimeters.
This example showed how to recover camera motion and reconstruct the 3-D structure of a scene from two images taken with a calibrated camera.
 Hartley, Richard, and Andrew Zisserman. Multiple View Geometry in Computer Vision. Second Edition. Cambridge, 2000.