Main Content


Refine camera poses and 3-D points



[xyzRefinedPoints,refinedPoses] = bundleAdjustment(xyzPoints,pointTracks,cameraPoses,intrinsics) returns the refined 3-D points and camera poses that minimize reprojection errors. The refinement procedure is a variant of the Levenberg-Marquardt algorithm. 3-D points and camera poses are placed in the same global reference coordinate system.

[___,reprojectionErrors] = bundleAdjustment(___) additionally returns an N-element vector containing the mean reprojection error for each 3-D world point using the arguments from the previous syntax.

[___] = bundleAdjustment(___,Name,Value) uses additional options specified by one or more Name,Value pair arguments. Unspecified properties have default values.


collapse all

Load data for initialization.

data = load('sfmGlobe');

Refine the camera poses and points.

[xyzRefinedPoints,refinedPoses] = ...

Display the refined camera poses and 3-D world points.

hold on
hold off
grid on

Figure contains an axes. The axes contains 51 objects of type line, text, patch, scatter.

Input Arguments

collapse all

Unrefined 3-D points, specified as an M-by-3 matrix of [x,y,z] locations.

Matching points across multiple images, specified as an N-element array of pointTrack objects. Each element contains two or more matching points across multiple images.

Camera pose ViewId, Orientation, and Location information, specified as a three-column table. The view IDs relate to the IDs in the pointTracks object. The orientations are specified as 3-by-3 rotation matrices. The locations are specified as a three-element vectors.

Camera intrinsics, specified as a scalar or an M-element array of cameraIntrinsics objects. M is the number of camera poses. Use a scalar value when images are captured using the same camera. Use a vector when images are captured by different cameras.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'MaxIterations', '50'

Maximum number of iterations before the Levenberg-Marquardt algorithm stops, specified as the comma-separated pair consisting of 'MaxIterations' and a positive integer.

Absolute termination tolerance of the mean squared reprojection error in pixels, specified as the comma-separated pair consisting of 'AbsoluteTolerance' and a positive scalar.

Relative termination tolerance of the reduction in reprojection error between iterations, specified as the comma-separated pair consisting of 'RelativeTolerance' and a positive scalar.

Flag to indicate lens distortion, specified as the comma-separated pair consisting of 'PointsUndistorted' and either false or true. When you set PointsUndistorted to false, the 2-D points in pointTracks must be from images with lens distortion. To use undistorted points, use the undistortImage function first, then set PointsUndistorted to true.

View IDs for fixed camera pose, specified as the comma-separated pair consisting of 'FixedViewIDs' and a vector of nonnegative integers. Each ID corresponds to the ViewId of a fixed camera pose in cameraPoses. An empty value for FixedViewIDs means that all camera poses are optimized.

Display progress information, specified as the comma-separated pair consisting of 'Verbose' and either false or true.

Output Arguments

collapse all

3-D locations of refined world points, returned as an M-by-3 matrix of [x,y, z] locations.

Data Types: single | double

Refined camera poses, returned as a table. The table contains three columns for 'ViewId', 'Orientation', and 'Location'.

Reprojection errors, returned as an M-by-1 vector. The function projects each world point back into each camera. Then in each image, the function calculates the reprojection error as the distance between the detected and the reprojected point. The reprojectionErrors vector contains the average reprojection error for each world point.


[1] Lourakis, M.I.A., and A.A. Argyros. "SBA: A Software Package for Generic Sparse Bundle Adjustment." ACM Transactions on Mathematical Software. 2009.

[2] Hartley, R., and A. Zisserman. Multiple View Geometry in Computer Vision. Cambridge University Press, 2003.

[3] Triggs, B., P. McLauchlan, R. Hartley, and A. Fitzgibbon. "Bundle Adjustment: A Modern Synthesis." Proceedings of the International Workshop on Vision Algorithms. Springer-Verlag. 1999, pp. 298-372.

Introduced in R2016a