[810] | 1 | %=======================================================================
|
---|
| 2 | % Copyright 2008-2014, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France
|
---|
| 3 | % http://www.legi.grenoble-inp.fr
|
---|
| 4 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
|
---|
| 5 | %
|
---|
| 6 | % This file is part of the toolbox UVMAT.
|
---|
| 7 | %
|
---|
| 8 | % UVMAT is free software; you can redistribute it and/or modify
|
---|
| 9 | % it under the terms of the GNU General Public License as published
|
---|
| 10 | % by the Free Software Foundation; either version 2 of the license,
|
---|
| 11 | % or (at your option) any later version.
|
---|
| 12 | %
|
---|
| 13 | % UVMAT is distributed in the hope that it will be useful,
|
---|
| 14 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 15 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 16 | % GNU General Public License (see LICENSE.txt) for more details.
|
---|
| 17 | %=======================================================================
|
---|
| 18 |
|
---|
[725] | 19 | %go_calib_optim
|
---|
| 20 | %
|
---|
| 21 | %Main calibration function. Computes the intrinsic andextrinsic parameters.
|
---|
| 22 | %Runs as a script.
|
---|
| 23 | %
|
---|
| 24 | %INPUT: x_1,x_2,x_3,...: Feature locations on the images
|
---|
| 25 | % X_1,X_2,X_3,...: Corresponding grid coordinates
|
---|
| 26 | %
|
---|
| 27 | %OUTPUT: fc: Camera focal length
|
---|
| 28 | % cc: Principal point coordinates
|
---|
| 29 | % alpha_c: Skew coefficient
|
---|
| 30 | % kc: Distortion coefficients
|
---|
| 31 | % KK: The camera matrix (containing fc and cc)
|
---|
| 32 | % omc_1,omc_2,omc_3,...: 3D rotation vectors attached to the grid positions in space
|
---|
| 33 | % Tc_1,Tc_2,Tc_3,...: 3D translation vectors attached to the grid positions in space
|
---|
| 34 | % Rc_1,Rc_2,Rc_3,...: 3D rotation matrices corresponding to the omc vectors
|
---|
| 35 | %
|
---|
| 36 | %Method: Minimizes the pixel reprojection error in the least squares sense over the intrinsic
|
---|
| 37 | % camera parameters, and the extrinsic parameters (3D locations of the grids in space)
|
---|
| 38 | %
|
---|
| 39 | %Note: If the intrinsic camera parameters (fc, cc, kc) do not exist before, they are initialized through
|
---|
| 40 | % the function init_intrinsic_param.m. Otherwise, the variables in memory are used as initial guesses.
|
---|
| 41 | %
|
---|
| 42 | %Note: The row vector active_images consists of zeros and ones. To deactivate an image, set the
|
---|
| 43 | % corresponding entry in the active_images vector to zero.
|
---|
| 44 | %
|
---|
| 45 | %VERY IMPORTANT: This function works for 2D and 3D calibration rigs, except for init_intrinsic_param.m
|
---|
| 46 | %that is so far implemented to work only with 2D rigs.
|
---|
| 47 | %In the future, a more general function will be there.
|
---|
| 48 | %For now, if using a 3D calibration rig, set quick_init to 1 for an easy initialization of the focal length
|
---|
| 49 |
|
---|
| 50 | if ~exist('rosette_calibration','var')
|
---|
| 51 | rosette_calibration = 0;
|
---|
| 52 | end;
|
---|
| 53 |
|
---|
| 54 | if ~exist('n_ima'),
|
---|
| 55 | data_calib; % Load the images
|
---|
| 56 | click_calib; % Extract the corners
|
---|
| 57 | end;
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | check_active_images;
|
---|
| 61 |
|
---|
| 62 | check_extracted_images;
|
---|
| 63 |
|
---|
| 64 | check_active_images;
|
---|
| 65 |
|
---|
| 66 | desactivated_images = [];
|
---|
| 67 |
|
---|
| 68 | recompute_extrinsic = (length(ind_active) < 100); % if there are too many images, do not spend time recomputing the extrinsic parameters twice..
|
---|
| 69 |
|
---|
| 70 | if (rosette_calibration)
|
---|
| 71 | %%% Special Setting for the Rosette:
|
---|
| 72 | est_dist = ones(5,1);
|
---|
| 73 | end;
|
---|
| 74 |
|
---|
| 75 |
|
---|
| 76 | %%% MAIN OPTIMIZATION CALL!!!!! (look into this function for the details of implementation)
|
---|
| 77 | go_calib_optim_iter;
|
---|
| 78 |
|
---|
| 79 |
|
---|
| 80 | if ~isempty(desactivated_images),
|
---|
| 81 |
|
---|
| 82 | param_list_save = param_list;
|
---|
| 83 |
|
---|
| 84 | fprintf(1,'\nNew optimization including the images that have been deactivated during the previous optimization.\n');
|
---|
| 85 | active_images(desactivated_images) = ones(1,length(desactivated_images));
|
---|
| 86 | desactivated_images = [];
|
---|
| 87 |
|
---|
| 88 | go_calib_optim_iter;
|
---|
| 89 |
|
---|
| 90 | if ~isempty(desactivated_images),
|
---|
| 91 | fprintf(1,['List of images left desactivated: ' num2str(desactivated_images) '\n' ] );
|
---|
| 92 | end;
|
---|
| 93 |
|
---|
| 94 | param_list = [param_list_save(:,1:end-1) param_list];
|
---|
| 95 |
|
---|
| 96 | end;
|
---|
| 97 |
|
---|
| 98 |
|
---|
| 99 | %%%%%%%%%%%%%%%%%%%% GRAPHICAL OUTPUT %%%%%%%%%%%%%%%%%%%%%%%%
|
---|
| 100 |
|
---|
| 101 | %graphout_calib;
|
---|
| 102 |
|
---|