Main Content

toStruct

Convert a stereo parameters object into a struct

Description

example

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.

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 = generateCheckerboardPoints(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)

Visualize camera extrinsics.

figure
showExtrinsics(params)

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