This repo is for the conversion of a MATLAB style .mat
calibration parameter to a OpenCV style numpy .npz
file.
Note: OpenCV, by default, uses 3 parameters for radial disotrtion and 2 parameters for tangencial distortion. Make sure that during the MATLAB calibration, 3 coefficients setting for Radial Distortion is chosen and also compute tangential distortion is chosen.
-
Calibrate the camera as usual using MATLAB and save the parameters. Here teh saved file will be referred as
camera_parameters
. -
Save as the
camera_parameters
as a struct :camera_parameters_struct = struct(camera_parameters)
-
Clone this repository to the folder where the
.mat
file is saved togit clone https://github.com/yusufguleray/CalibrationParameters-Matlab2NumPy.git
-
Run the script with first argument as the name of the name of the
.mat
file, second argument for the name of the numpy file to be created.python .\CalibrationParameters-Matlab2NumPy\mat2np.py <camera_parameters_struct.mat> <name_of_output.npz>
import utils
calib_file_name = "output.npz" # name of the .npz file that the camera parameters are saved in
calib_mtx, dist_coef = utils.getCalibData(calib_file_name)