Main Content


Convert a camera parameters object into a struct



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.


collapse all

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

Create a cameraParameters object manually.

k = [715.2699 0 565.6995; 0 711.5281 355.3466; 0 0 1];
radialDistortion = [-0.3361 0.0921]; 
cameraParams = cameraParameters("K",k,"RadialDistortion",radialDistortion)
cameraParams = 
  cameraParameters with properties:

   Camera Intrinsics
                         Intrinsics: [0x0 cameraIntrinsics]

   Camera Extrinsics
                  PatternExtrinsics: [0x1 rigidtform3d]

   Accuracy of Estimation
              MeanReprojectionError: NaN
                 ReprojectionErrors: [0x2 double]
                  ReprojectedPoints: [0x2x0 double]

   Calibration Settings
                        NumPatterns: 0
                  DetectedKeypoints: [0x2 double]
                        WorldPoints: [0x2 double]
                         WorldUnits: 'mm'
                       EstimateSkew: 0
    NumRadialDistortionCoefficients: 2
       EstimateTangentialDistortion: 0

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.

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