Main Content

bundleAdjustment

Adjust collection of 3-D points and camera poses

Description

example

[xyzRefinedPoints,refinedPoses] = bundleAdjustment(xyzPoints,pointTracks,cameraPoses,intrinsics)refines 3-D points and camera poses to minimize reprojection errors. The refinement procedure is a variant of the Levenberg-Marquardt algorithm. The function uses the same global reference coordinate system to return both the 3-D points and camera poses.

[wpSetRefined,vSetRefined,pointIndex] = bundleAdjustment(wpSet,vSet,viewIDs,intrinsics)refines 3-D points from the world point set,wpSet, and refines camera poses from the image view set,vSetviewIDsspecify the camera poses invSetto refine.

[___,reprojectionErrors] = bundleAdjustment(___)returns the mean reprojection error for each 3-D world point, in addition to the arguments from the previous syntax.

[___] = bundleAdjustment(___,Name=Value)specifies options using one or more name-value arguments in addition to any combination of arguments from previous syntaxes. For example,MaxIterations=50sets the number of iterations to50。Unspecified arguments have default values.

Examples

collapse all

Load data for initialization.

data = load("globeBA.mat");

Refine the camera poses and points.

[xyzRefinedPoints,refinedPoses] =。..bundleAdjustment(data.xyzPoints,data.pointTracks,data.cameraPoses,data.intrinsics);

Display the 3-D points and camera poses before and after the refinement.

pcshowpair(pointCloud(data.xyzPoints), pointCloud(xyzRefinedPoints),。..AxesVisibility="on", VerticalAxis="y", VerticalAxisDir="down", MarkerSize=40); holdonplotCamera(data.cameraPoses, Size=0.1, Color="m"); plotCamera(refinedPoses, Size=0.1, Color="g"); legend("Before refinement","After refinement", color="w");

Figure contains an axes object. The axes object contains 102 objects of type line, text, patch, scatter. These objects represent Before refinement, After refinement.

Input Arguments

collapse all

Unrefined 3-D points, specified as anM3矩阵of [xyz] locations.

Matching points across multiple images, specified as anN-element array ofpointTrackobjects. Each element contains two or more matching points across multiple images.

Camera pose information, specified as a two-column table with columnsViewIdandAbsolutePose。The view IDs relate to the IDs of the objects in thepointTracksargument. You can use theposesobject function to obtain thecameraPosestable.

Camera intrinsics, specified as acameraIntrinsicsobject or anN-element array ofcameraIntrinsicsobjects.Nis the number of camera poses or the number of IDs inviewIDs。Use a singlecameraIntrinsicsobject when images are captured using the same camera. Use a vectorcameraIntrinsicsobjects when images are captured by different cameras.

3-D world points, specified as aworldpointsetobject.

Camera poses, specified as animageviewsetobject.

View identifiers, specified as anN-element array. TheviewIDsrepresent which camera poses to refine specifying their related views inimageviewset

Name-Value Arguments

Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN, whereNameis the argument name and价值is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example:MaxIterations=50sets the number of iterations to50

Before R2021a, use commas to separate each name and value, and encloseNamein quotes.

Maximum number of iterations before the Levenberg-Marquardt algorithm stops, specified as a positive integer.

Absolute termination tolerance of the mean squared reprojection error in pixels, specified as positive scalar.

Relative termination tolerance of the reduction in reprojection error between iterations, specified as positive scalar.

Flag to indicate lens distortion, specified asfalseor真正的。当you setPointsUndistortedtofalse, the 2-D points inpointTracksor invSetmust be from images with lens distortion. To use undistorted points, first use theundistortImagefunction to remove distortions from the images, then setPointsUndistorted

View IDs for fixed camera pose, specified as a vector of nonnegative integers. Each ID corresponds to theViewId的一个固定相机pose incameraPoses。An empty value forFixedViewIDsmeans that all camera poses are optimized.

Solver, specified as"sparse-linear-algebra"or"preconditioned-conjugate-gradient"。Use the"sparse-linear-algebra"solver for low sparsity images. Low sparsity indicates that many camera views observe some of the same world points. Use the"preconditioned-conjugate-gradient"(PCG) solver, from the general graphic optimization (g2o) library, for high sparsity images. High sparsity indicates that each camera view observes, only a small portion of the world points, specified byxyzPoints

Display progress information, specified asfalseor真正的

Output Arguments

collapse all

3-D locations of refined world points, returned as anM3矩阵of [xyz] locations.

Data Types:single|double

Refined camera poses, returned as a two-column table. The table contains columns forViewIdandAbsolutePose

Refined 3-D world points, returned as aworldpointsetobject.

Refined camera poses, specified as animageviewsetobject.

Indices towpSetRefinedof refined 3-D world points, returned as anM-element array.

Reprojection errors, returned as anM-element 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. ThereprojectionErrorsvector contains the average reprojection error for each world point.

Detected point and reprojected point next to each other, with reprojection error as the distance between them

References

[1]Lourakis, Manolis I. A., and Antonis A. Argyros. "SBA: A Software Package for Generic Sparse Bundle Adjustment."ACM Transactions on Mathematical Software 36, no. 1 (March 2009): 2:1–2:30.

[2]Hartley, Richard, and Andrew Zisserman.Multiple View Geometry in Computer Vision。2nd ed. Cambridge, UK ; New York: Cambridge University Press, 2003.

[3]Triggs, Bill, Philip F. McLauchlan, Richard I. Hartley, and Andrew W. Fitzgibbon. "Bundle Adjustment — A Modern Synthesis." InProceedings of the International Workshop on Vision Algorithms, 298–372. Springer-Verlag, 1999.

Extended Capabilities

Version History

Introduced in R2016a

expand all