Main Content

toStruct

Convert a stereo parameters object into a struct

Description

paramStruct = toStruct(stereoParams) returns a struct containing the stereo parameters in the stereoParams input object. You can use the struct to create an identical stereoParameters object. Use the struct for C code generation. You can call toStruct, and then pass the resulting structure into the generated code, which recreates the stereoParameters object.

example

Examples

collapse all

Specify calibration images.

leftImages = imageDatastore(fullfile(toolboxdir("vision"),"visiondata", ...
    "calibration","stereo","left"));
rightImages = imageDatastore(fullfile(toolboxdir("vision"),"visiondata", ...
    "calibration","stereo","right"));

Detect the checkerboards.

[imagePoints,boardSize] = ...
  detectCheckerboardPoints(leftImages.Files,rightImages.Files);

Specify the world coordinates of the checkerboard keypoints. Square size is in millimeters.

squareSize = 108;
worldPoints = patternWorldPoints("checkerboard",boardSize,squareSize);

Calibrate the stereo camera system. Both cameras have the same resolution.

I = readimage(leftImages,1); 
imageSize = [size(I,1) size(I,2)];
params = estimateCameraParameters(imagePoints,worldPoints, ...
    "ImageSize",imageSize);

Visualize the calibration accuracy.

showReprojectionErrors(params)

Figure contains an axes object. The axes object with title Mean Reprojection Error per Image, xlabel Image Pairs, ylabel Mean Error in Pixels contains 5 objects of type bar, line. These objects represent Camera 1, Camera 2, Overall Mean Error: 0.06 pixels.

Visualize camera extrinsics.

figure
showExtrinsics(params)

Figure contains an axes object. The axes object with title Extrinsic Parameters Visualization, xlabel X (mm), ylabel Z (mm) contains 28 objects of type patch, text, line.

Convert to structure.

paramsStruct = toStruct(params)
paramsStruct = struct with fields:
       CameraParameters1: [1x1 struct]
       CameraParameters2: [1x1 struct]
       RotationOfCamera2: [3x3 double]
    TranslationOfCamera2: [-119.8720 -0.4005 -0.0258]
                 Version: [1x1 struct]
     RectificationParams: [1x1 struct]

Input Arguments

collapse all

Stereo parameters, specified as a stereoParameters object. The object contains the parameters of the stereo camera system.

Output Arguments

collapse all

Stereo parameters, returned as a stereo parameters struct.

Version History

Introduced in R2015a