Save Camera Calibration Parameters

The export of camera parameters from the Camera Calibration toolbox creates its own type of variable that cannot be saved as a .mat. How can I save these so that I can load it when I want to use that camera instead of calibrating it every time? Is xml the only way?
Thanks, Erin

4 Kommentare

Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh am 13 Mär. 2014
Erin can you tell me what's the type of the variables? Struct? Cell? Char? Double? or ... ?
Erin
Erin am 13 Mär. 2014
It's a 1x1 vision.CameraParameters object
Clive Fox
Clive Fox am 27 Okt. 2016
Bearbeitet: Clive Fox am 27 Okt. 2016
There is a command toStruct(cameraParams) which seems to work,so if you have created a cameraParameters object in your workspace
mycamParams = toStruct(cameraParams)
save mycamParams.mat mycamParams %Saves as a mat file
clear %clear variables in workspace
load('mycamParams.mat') %loads it back in and Matlab recognises it is a structure
mycamParams=cameraParameters(parameterStruct) % recreates the camera parameters object which you can then use to undistort images etc.
Aditi Singh
Aditi Singh am 8 Okt. 2019
I have an image how can I find camera calibration for that.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Dima Lisin
Dima Lisin am 1 Mai 2014
Bearbeitet: Dima Lisin am 1 Mai 2014

1 Stimme

You certainly can save the camera parameters object into a mat file, just like any other variable. Export the variable to workspace. Let's call it myParams. Then do
>> save myParams.mat myParams
That should work.

2 Kommentare

I kept getting an error: ""Argument must contain a character vector". I slightly modified Dima's suggestion to make it work for me:
>> save 'myParams' myParams
Hard to see why the modification was necessary or made any difference. Maybe you were originally using the functional form of save as follows,
save('myParams',myParams)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Sean de Wolski
Sean de Wolski am 13 Mär. 2014

0 Stimmen

With MATLAB R2014a, you can generate equivalent code with the app.

4 Kommentare

Sean de Wolski
Sean de Wolski am 13 Mär. 2014
See the "Generate MATLAB Script" option.
Erin
Erin am 13 Mär. 2014
I unfortunately have 2013b not 2014a.
Image Analyst
Image Analyst am 13 Mär. 2014
You can probably get a free upgrade if you purchased R2013b.
Erin
Erin am 13 Mär. 2014
It's a company license so I can't.
Basically I am trying to save the object of the type vision.CameraParameters class. I would like to be able to save it out of my workspace so that I can just reload it to use it for undistortImage instead of rerunning the calibration each time my workspace gets cleared.

Melden Sie sich an, um zu kommentieren.

Matt J
Matt J am 13 Mär. 2014
Bearbeitet: Matt J am 13 Mär. 2014

0 Stimmen

You could write a customized save routine that exports the CameraParameters properties and saves them in a structure
function save_cameraParams(cpObject,fileName)
fields={'IntrinsicMatrix', 'RadialDistortion',etc...}
for ii=1:length(fields)
S.(fields{ii})=cpObject.(fields{ii});
end
save(fileName, 'S');
end
Then a similar one to reload and rebuild the vision.CameraParameters object,
function cpObject=load_cameraParams(fileName)
S=load(fileName); S=S.S
pairs=[fieldnames(S), struct2cell(S)].';
cpObject=vision.CameraParameters(pairs{:});
end

Kategorien

Mehr zu MATLAB Support Package for USB Webcams finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 13 Mär. 2014

Kommentiert:

am 8 Okt. 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by