0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 clc
0025 close all
0026 clearvars
0027
0028 addpath(genpath('../../General-Functions'))
0029
0030 fprintf('\n------ Demo partitioning of P into K, R, and Z ------\n')
0031
0032 fprintf('\nIn order to shorten the output, we display transposed vectors\n')
0033
0034 disp(' ')
0035
0036 disp('Common rotation matrix')
0037 R = calc_Rot_q([1,.0,0.0,2])
0038
0039
0040 fprintf('\n-------- camera 1: K(3,3) > 0, c > 0 --------\n')
0041 disp('create P with random Z and')
0042 K = [+1,0.01,0.01;0,+1,0.1;0,0,1];
0043 disp(['diag(K) = [', num2str(diag(K)'),']'])
0044
0045 Z = rand(3,1);
0046 P = calc_P_from_KRZ(K,R,Z)
0047 d = calc_viewing_direction(P);
0048 disp(['Viewing direction d = [', num2str(d'),']'])
0049
0050 disp(' ')
0051 disp('Get K, R, Z from P with positive c')
0052 [K_,R_,Z_,~] = calc_KRZ_from_P(P,1);
0053 K_
0054 R_
0055 Z_'
0056
0057 disp('Check calculated values')
0058 dK1 = K/K(3,3)-K_;
0059 disp(['norm(dK) = [', num2str(norm(dK1)),']'])
0060 dR1 = R-R_;
0061 disp(['norm(dR) = [', num2str(norm(dR1)),']'])
0062 dZ1 = Z-Z_;
0063 disp(['norm(dZ) = [', num2str(norm(dZ1)),']'])
0064
0065
0066 fprintf('\n-------- camera 2: K(3,3) > 0, c < 0 --------\n')
0067 disp('Again, create P with random Z and')
0068 K=[-1,0.01,0.01;0,-1,0.1;0,0,1];
0069 disp(['diag(K) = [', num2str(diag(K)'),']'])
0070
0071 Z = rand(3,1);
0072 P = calc_P_from_KRZ(K,R,Z)
0073 d = calc_viewing_direction(P);
0074 disp(['Viewing direction d = [', num2str(d'),']'])
0075
0076 disp(' ')
0077 disp('Get K, R, Z from P with negative c')
0078 [K_,R_,Z_,~] = calc_KRZ_from_P(P,-1);
0079 K_
0080 R_
0081 Z_'
0082
0083 disp('Check calculated values')
0084 dK2 = K/K(3,3)-K_;
0085 disp(['norm(dK) = [', num2str(norm(dK2)),']'])
0086 dR2 = R-R_;
0087 disp(['norm(dR) = [', num2str(norm(dR2)),']'])
0088 dZ2 = Z-Z_;
0089 disp(['norm(dZ) = [', num2str(norm(dZ2)),']'])
0090
0091
0092
0093 fprintf('\n-------- camera 3: K(3,3) < 0, c < 0 --------\n')
0094 disp('Again, create P with random Z and')
0095 K=[+1,0.01,0.01;0,+1,0.1;0,0,-1];
0096 disp(['diag(K) = [', num2str(diag(K)'),']'])
0097
0098 Z = rand(3,1);
0099 P = calc_P_from_KRZ(K,R,Z)
0100 d = calc_viewing_direction(P);
0101 disp(['Viewing direction d = [', num2str(d'),']'])
0102
0103 disp(' ')
0104 disp('Get K, R, Z from P with negative c')
0105 [K_,R_,Z_,~] = calc_KRZ_from_P(P,-1);
0106 K_
0107 R_
0108 Z_'
0109
0110 disp('Check calculated values')
0111 dK3 = K/K(3,3)-K_;
0112 disp(['norm(dK) = [', num2str(norm(dK3)),']'])
0113 dR3 = R-R_;
0114 disp(['norm(dR) = [', num2str(norm(dR3)),']'])
0115 dZ3 = Z-Z_;
0116 disp(['norm(dZ) = [', num2str(norm(dZ3)),']'])
0117
0118
0119 fprintf('\n-------- camera 4: K(3,3) < 0, c > 0 --------\n')
0120 disp('Again, create P with random Z and')
0121 K=[-1,0.01,0.01;0,-1,0.1;0,0,-1];
0122 disp(['diag(K) = [', num2str(diag(K)'),']'])
0123
0124 Z = rand(3,1);
0125 P = calc_P_from_KRZ(K,R,Z)
0126 d = calc_viewing_direction(P);
0127 disp(['Viewing direction d = [', num2str(d'),']'])
0128
0129 disp(' ')
0130 disp('Get K, R, Z from P with positive c')
0131 [K_,R_,Z_,~] = calc_KRZ_from_P(P,1);
0132 K_
0133 R_
0134 Z_'
0135
0136 disp('Check calculated values')
0137 dK4 = K/K(3,3)-K_;
0138 disp(['norm(dK) = [', num2str(norm(dK4)),']'])
0139 dR4 = R-R_;
0140 disp(['norm(dR) = [', num2str(norm(dR4)),']'])
0141 dZ4 = Z-Z_;
0142 disp(['norm(dZ) = [', num2str(norm(dZ4)),']'])
0143
0144 sum_check=...
0145 norm(dK1(:))+norm(dK2(:))+norm(dK3(:))+norm(dK4(:))+...
0146 norm(dR1(:))+norm(dR2(:))+norm(dR3(:))+norm(dR4(:))+...
0147 norm(dZ1(:))+norm(dZ2(:))+norm(dZ3(:))+norm(dZ4(:));
0148
0149 disp(' ')
0150 display(['Total sum of absolute differences =',num2str(sum_check)]);