Main Content

toStruct

Convert a camera parameters object into a struct

Description

example

paramStruct = toStruct(cameraParams) returns a struct containing the camera parameters in the cameraParams input object. You can use the struct to create an identical cameraParameters object. Use the struct for C code generation. You can call toStruct, and then pass the resulting structure into the generated code, which re-creates the cameraParameters object.

Examples

collapse all

Use the camera calibration functions to remove distortion from an image. This example creates a vision.cameraParameters object manually, but in practice, you would use the estimateCameraParameters or the Camera Calibrator app to derive the object.

Create a vision.cameraParameters object manually.

IntrinsicMatrix = [715.2699 0 0; 0 711.5281 0; 565.6995 355.3466 1];
radialDistortion = [-0.3361 0.0921]; 
cameraParams = cameraParameters('IntrinsicMatrix',IntrinsicMatrix,'RadialDistortion',radialDistortion); 

Remove distortion from the images.

I = imread(fullfile(matlabroot,'toolbox','vision','visiondata','calibration','mono','image01.jpg'));
J = undistortImage(I,cameraParams);

Display the original and the undistorted images.

figure; imshowpair(imresize(I,0.5),imresize(J,0.5),'montage');
title('Original Image (left) vs. Corrected Image (right)');

Figure contains an axes object. The axes object with title Original Image (left) vs. Corrected Image (right) contains an object of type image.

Input Arguments

collapse all

Camera parameters, specified as a cameraParameters object. The object contains the parameters for the camera.

Output Arguments

collapse all

Camera parameters, returned as a camera parameters struct.

Version History

Introduced in R2015a