Save Camera Calibration Parameters
조회 수: 37 (최근 30일)
이전 댓글 표시
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
Clive Fox
2016년 10월 27일
편집: Clive Fox
2016년 10월 27일
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.
채택된 답변
Dima Lisin
2014년 5월 1일
편집: Dima Lisin
2014년 5월 1일
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
Helia Sh
2018년 12월 12일
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
Matt J
2018년 12월 12일
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)
추가 답변 (2개)
Sean de Wolski
2014년 3월 13일
With MATLAB R2014a, you can generate equivalent code with the app.
댓글 수: 4
Matt J
2014년 3월 13일
편집: Matt J
2014년 3월 13일
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Support Package for USB Webcams에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!