Changeset 1000
- Timestamp:
- Feb 17, 2017, 2:51:46 PM (8 years ago)
- Location:
- trunk/src/toolbox_calib
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/toolbox_calib/compute_extrinsic.m
r926 r1000 34 34 %project_points.m: Computes the 2D image projections of a set of 3D points 35 35 36 37 38 36 if nargin < 8, 39 37 thresh_cond = inf; 40 38 end; 41 42 39 43 40 if nargin < 7, … … 45 42 end; 46 43 47 48 44 if nargin < 6, 49 alpha_c = 0;50 51 52 53 54 55 56 57 58 59 60 61 62 45 alpha_c = 0; 46 if nargin < 5, 47 kc = zeros(5,1); 48 if nargin < 4, 49 cc = zeros(2,1); 50 if nargin < 3, 51 fc = ones(2,1); 52 if nargin < 2, 53 error('Need 2D projections and 3D points (in compute_extrinsic.m)'); 54 return; 55 end; 56 end; 57 end; 58 end; 63 59 end; 64 60 … … 69 65 % Refinement: 70 66 [omckk,Tckk,Rckk,JJ] = compute_extrinsic_refine(omckk,Tckk,x_kk,X_kk,fc,cc,kc,alpha_c,MaxIter,thresh_cond); 71 72 67 73 68 % computation of the homography (not useful in the end) … … 81 76 ex = x_kk - x; 82 77 83 84 78 % Converts the homography in pixel units: 85 79 … … 87 81 88 82 H = KK*H; 89 90 91 92 83 93 84 return; -
trunk/src/toolbox_calib/compute_homography.m
r926 r1000 34 34 35 35 36 37 38 36 Np = size(m,2); 39 37 40 38 if size(m,1)<3, 41 m = [m;ones(1,Np)];39 m = [m;ones(1,Np)]; 42 40 end; 43 41 44 42 if size(M,1)<3, 45 M = [M;ones(1,Np)];43 M = [M;ones(1,Np)]; 46 44 end; 47 45 … … 82 80 83 81 if Np > 4, 84 82 L = L'*L; 85 83 end; 86 84 … … 99 97 100 98 if 0, 101 m2 = H*M;102 m2 = [m2(1,:)./m2(3,:) ; m2(2,:)./m2(3,:)];103 merr = m(1:2,:) - m2;99 m2 = H*M; 100 m2 = [m2(1,:)./m2(3,:) ; m2(2,:)./m2(3,:)]; 101 merr = m(1:2,:) - m2; 104 102 end; 105 103 106 104 %keyboard; 107 105 108 106 %%% Homography refinement if there are more than 4 points: 109 107 110 108 if Np > 4, 111 112 % Final refinement:113 hhv = reshape(H',9,1);114 hhv = hhv(1:8);115 116 for iter=1:10,117 118 109 119 120 mrep = H * M; 110 % Final refinement: 111 hhv = reshape(H',9,1); 112 hhv = hhv(1:8); 121 113 122 J = zeros(2*Np,8); 114 for iter=1:10, 123 115 124 MMM = (M ./ (ones(3,1)*mrep(3,:)));116 mrep = H * M; 125 117 126 J(1:2:2*Np,1:3) = -MMM'; 127 J(2:2:2*Np,4:6) = -MMM'; 128 129 mrep = mrep ./ (ones(3,1)*mrep(3,:)); 118 J = zeros(2*Np,8); 130 119 131 m_err = m(1:2,:) - mrep(1:2,:); 132 m_err = m_err(:); 120 MMM = (M ./ (ones(3,1)*mrep(3,:))); 133 121 134 MMM2 = (ones(3,1)*mrep(1,:)) .* MMM;135 MMM3 = (ones(3,1)*mrep(2,:)) .* MMM;122 J(1:2:2*Np,1:3) = -MMM'; 123 J(2:2:2*Np,4:6) = -MMM'; 136 124 137 J(1:2:2*Np,7:8) = MMM2(1:2,:)'; 138 J(2:2:2*Np,7:8) = MMM3(1:2,:)'; 125 mrep = mrep ./ (ones(3,1)*mrep(3,:)); 139 126 140 MMM = (M ./ (ones(3,1)*mrep(3,:)))'; 127 m_err = m(1:2,:) - mrep(1:2,:); 128 m_err = m_err(:); 141 129 142 hh_innov = inv(J'*J)*J'*m_err; 130 MMM2 = (ones(3,1)*mrep(1,:)) .* MMM; 131 MMM3 = (ones(3,1)*mrep(2,:)) .* MMM; 143 132 144 hhv_up = hhv - hh_innov; 133 J(1:2:2*Np,7:8) = MMM2(1:2,:)'; 134 J(2:2:2*Np,7:8) = MMM3(1:2,:)'; 145 135 146 H_up = reshape([hhv_up;1],3,3)';136 MMM = (M ./ (ones(3,1)*mrep(3,:)))'; 147 137 148 %norm(m_err) 149 %norm(hh_innov) 138 hh_innov = inv(J'*J)*J'*m_err; 150 139 151 hhv = hhv_up; 152 H = H_up; 153 154 end; 155 140 hhv_up = hhv - hh_innov; 156 141 142 H_up = reshape([hhv_up;1],3,3)'; 143 144 %norm(m_err) 145 %norm(hh_innov) 146 147 hhv = hhv_up; 148 H = H_up; 149 150 end; 157 151 end; 158 152 159 153 if 0, 160 m2 = H*M;161 m2 = [m2(1,:)./m2(3,:) ; m2(2,:)./m2(3,:)];162 merr = m(1:2,:) - m2;154 m2 = H*M; 155 m2 = [m2(1,:)./m2(3,:) ; m2(2,:)./m2(3,:)]; 156 merr = m(1:2,:) - m2; 163 157 end; 164 158 -
trunk/src/toolbox_calib/extract_parameters.m
r926 r1000 5 5 6 6 if ~exist('solution_error') 7 solution_error = zeros(6*n_ima + 15,1);7 solution_error = zeros(6*n_ima + 15,1); 8 8 end; 9 9 … … 19 19 20 20 % Calibration matrix: 21 21 22 22 KK = [fc(1) fc(1)*alpha_c cc(1);0 fc(2) cc(2); 0 0 1]; 23 23 inv_KK = inv(KK); … … 26 26 27 27 for kk = 1:n_ima, 28 29 if active_images(kk), 30 31 omckk = solution(15+6*(kk-1) + 1:15+6*(kk-1) + 3);%*** 32 Tckk = solution(15+6*(kk-1) + 4:15+6*(kk-1) + 6);%*** 33 34 omckk_error = solution_error(15+6*(kk-1) + 1:15+6*(kk-1) + 3); 35 Tckk_error = solution_error(15+6*(kk-1) + 4:15+6*(kk-1) + 6); 36 37 Rckk = rodrigues(omckk); 38 39 Hkk = KK * [Rckk(:,1) Rckk(:,2) Tckk]; 40 41 Hkk = Hkk / Hkk(3,3); 42 43 else 44 45 omckk = NaN*ones(3,1); 46 Tckk = NaN*ones(3,1); 47 Rckk = NaN*ones(3,3); 48 Hkk = NaN*ones(3,3); 49 omckk_error = NaN*ones(3,1); 50 Tckk_error = NaN*ones(3,1); 51 52 end; 53 54 eval(['omc_' num2str(kk) ' = omckk;']); 55 eval(['Rc_' num2str(kk) ' = Rckk;']); 56 eval(['Tc_' num2str(kk) ' = Tckk;']); 57 eval(['H_' num2str(kk) '= Hkk;']); 58 eval(['omc_error_' num2str(kk) ' = omckk_error;']); 59 eval(['Tc_error_' num2str(kk) ' = Tckk_error;']); 60 28 29 if active_images(kk), 30 omckk = solution(15+6*(kk-1) + 1:15+6*(kk-1) + 3);%*** 31 Tckk = solution(15+6*(kk-1) + 4:15+6*(kk-1) + 6);%*** 32 33 omckk_error = solution_error(15+6*(kk-1) + 1:15+6*(kk-1) + 3); 34 Tckk_error = solution_error(15+6*(kk-1) + 4:15+6*(kk-1) + 6); 35 36 Rckk = rodrigues(omckk); 37 38 Hkk = KK * [Rckk(:,1) Rckk(:,2) Tckk]; 39 40 Hkk = Hkk / Hkk(3,3); 41 42 else 43 omckk = NaN*ones(3,1); 44 Tckk = NaN*ones(3,1); 45 Rckk = NaN*ones(3,3); 46 Hkk = NaN*ones(3,3); 47 omckk_error = NaN*ones(3,1); 48 Tckk_error = NaN*ones(3,1); 49 end; 50 51 eval(['omc_' num2str(kk) ' = omckk;']); 52 eval(['Rc_' num2str(kk) ' = Rckk;']); 53 eval(['Tc_' num2str(kk) ' = Tckk;']); 54 eval(['H_' num2str(kk) '= Hkk;']); 55 eval(['omc_error_' num2str(kk) ' = omckk_error;']); 56 eval(['Tc_error_' num2str(kk) ' = Tckk_error;']); 61 57 end; -
trunk/src/toolbox_calib/ima_read_calib.m
r926 r1000 1 1 2 2 if ~exist('calib_name')|~exist('format_image'), 3 data_calib;4 return;3 data_calib; 4 return; 5 5 end; 6 6 … … 8 8 9 9 if ~exist('n_ima'), 10 data_calib;11 return;10 data_calib; 11 return; 12 12 end; 13 13 14 14 check_active_images; 15 16 15 17 16 images_read = active_images; … … 19 18 20 19 if exist('image_numbers'), 21 first_num = image_numbers(1);20 first_num = image_numbers(1); 22 21 end; 23 24 22 25 23 % Just to fix a minor bug: 26 24 if ~exist('first_num'), 27 first_num = image_numbers(1);25 first_num = image_numbers(1); 28 26 end; 29 30 27 31 28 image_numbers = first_num:n_ima-1+first_num; … … 36 33 37 34 while (i <= n_ima), % & (~no_image_file), 38 39 if active_images(i), 40 41 %fprintf(1,'Loading image %d...\n',i); 42 43 if ~type_numbering, 44 number_ext = num2str(image_numbers(i)); 45 else 46 number_ext = sprintf(['%.' num2str(N_slots) 'd'],image_numbers(i)); 47 end; 48 49 ima_name = [calib_name number_ext '.' format_image]; 50 51 if i == ind_active(1), 52 fprintf(1,'Loading image '); 53 end; 54 55 if exist(ima_name), 56 57 fprintf(1,'%d...',i); 58 59 if format_image(1) == 'p', 60 if format_image(2) == 'p', 61 Ii = double(loadppm(ima_name)); 35 36 if active_images(i), 37 38 %fprintf(1,'Loading image %d...\n',i); 39 40 if ~type_numbering, 41 number_ext = num2str(image_numbers(i)); 42 else 43 number_ext = sprintf(['%.' num2str(N_slots) 'd'],image_numbers(i)); 44 end; 45 46 ima_name = [calib_name number_ext '.' format_image]; 47 48 if i == ind_active(1), 49 fprintf(1,'Loading image '); 50 end; 51 52 if exist(ima_name), 53 54 fprintf(1,'%d...',i); 55 56 if format_image(1) == 'p', 57 if format_image(2) == 'p', 58 Ii = double(loadppm(ima_name)); 59 else 60 Ii = double(loadpgm(ima_name)); 61 end; 62 62 else 63 Ii = double(loadpgm(ima_name)); 63 if format_image(1) == 'r', 64 Ii = readras(ima_name); 65 else 66 Ii = double(imread(ima_name)); 67 end; 64 68 end; 65 else 66 if format_image(1) == 'r', 67 Ii = readras(ima_name); 68 else 69 Ii = double(imread(ima_name)); 69 70 if size(Ii,3)>1, 71 Ii = 0.299 * Ii(:,:,1) + 0.5870 * Ii(:,:,2) + 0.114 * Ii(:,:,3); 70 72 end; 71 end;72 73 73 74 if size(Ii,3)>1, 75 Ii = 0.299 * Ii(:,:,1) + 0.5870 * Ii(:,:,2) + 0.114 * Ii(:,:,3); 76 end; 77 78 eval(['I_' num2str(i) ' = Ii;']); 79 80 else 81 82 %fprintf(1,'%d...no image...',i); 83 84 images_read(i) = 0; 85 86 %no_image_file = 1; 87 88 end; 89 90 end; 91 92 i = i+1; 93 74 eval(['I_' num2str(i) ' = Ii;']); 75 76 else 77 78 %fprintf(1,'%d...no image...',i); 79 80 images_read(i) = 0; 81 82 %no_image_file = 1; 83 84 end; 85 86 end; 87 88 i = i+1; 89 94 90 end; 95 91 … … 98 94 99 95 96 if isempty(ind_read), 97 98 fprintf(1,'\nWARNING! No image were read\n'); 99 100 no_image_file = 1; 101 102 else 103 %fprintf(1,'\nWARNING! Every exsisting image in the directory is set active.\n'); 104 105 if no_image_file, 106 107 %fprintf(1,'WARNING! Some images were not read properly\n'); 108 end; 100 109 101 110 102 if isempty(ind_read), 103 104 fprintf(1,'\nWARNING! No image were read\n'); 105 106 no_image_file = 1; 107 108 109 else 110 111 fprintf(1,'\n'); 111 112 112 %fprintf(1,'\nWARNING! Every exsisting image in the directory is set active.\n'); 113 if size(I_1,1)~=480, 114 small_calib_image = 1; 115 else 116 small_calib_image = 0; 117 end; 113 118 114 115 if no_image_file, 116 117 %fprintf(1,'WARNING! Some images were not read properly\n'); 118 119 end; 120 121 122 fprintf(1,'\n'); 119 [Hcal,Wcal] = size(I_1); % size of the calibration image 123 120 124 if size(I_1,1)~=480, 125 small_calib_image = 1; 126 else 127 small_calib_image = 0; 128 end; 129 130 [Hcal,Wcal] = size(I_1); % size of the calibration image 131 132 [ny,nx] = size(I_1); 133 134 clickname = []; 135 136 map = gray(256); 137 138 %string_save = 'save calib_data n_ima type_numbering N_slots image_numbers format_image calib_name Hcal Wcal nx ny map small_calib_image'; 121 [ny,nx] = size(I_1); 139 122 140 %eval(string_save);123 clickname = []; 141 124 142 disp('done'); 143 %click_calib; 125 map = gray(256); 126 127 %string_save = 'save calib_data n_ima type_numbering N_slots image_numbers format_image calib_name Hcal Wcal nx ny map small_calib_image'; 128 129 %eval(string_save); 130 131 disp('done'); 132 %click_calib; 144 133 145 134 end;
Note: See TracChangeset
for help on using the changeset viewer.