Home > 12-Single-View-Geometry > Demo_Projection > demo_KRZ.m

demo_KRZ

PURPOSE ^

% Demo partitioning of P into K, R, and Z

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

% Demo partitioning of P into K, R, and Z
 
 PCV, Algorithm 18, p. 500 

 The result should not change if the sign of P changes.
 The sign of the focal length c should be the required one

 vary:
 - sign of K(3,3), changing sign of P
 - sign of c

 check the correctnes of the decomposition for all four cases
 diag(K) = [+1,+1,+1] : require c = +1
 diag(K) = [-1,-1,+1] : require c = -1
 diag(K) = [+1,+1,-1] : require c = -1
 diag(K) = [-1,-1,-1] : require c = +1

 Wolfgang Förstner
 wfoerstn@uni-bonn.de

 last changes: Susanne Wenzel 04/18
 wenzel@igg.uni-bonn.de

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %% Demo partitioning of P into K, R, and Z
0002 %
0003 % PCV, Algorithm 18, p. 500
0004 %
0005 % The result should not change if the sign of P changes.
0006 % The sign of the focal length c should be the required one
0007 %
0008 % vary:
0009 % - sign of K(3,3), changing sign of P
0010 % - sign of c
0011 %
0012 % check the correctnes of the decomposition for all four cases
0013 % diag(K) = [+1,+1,+1] : require c = +1
0014 % diag(K) = [-1,-1,+1] : require c = -1
0015 % diag(K) = [+1,+1,-1] : require c = -1
0016 % diag(K) = [-1,-1,-1] : require c = +1
0017 %
0018 % Wolfgang Förstner
0019 % wfoerstn@uni-bonn.de
0020 %
0021 % last changes: Susanne Wenzel 04/18
0022 % wenzel@igg.uni-bonn.de
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 % R = eye(3);
0036 disp('Common rotation matrix')
0037 R = calc_Rot_q([1,.0,0.0,2])                                               %#ok<NOPTS>
0038 
0039 %% 1. camera
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); %zeros(3,1);
0046 P = calc_P_from_KRZ(K,R,Z)                                                 %#ok<NOPTS>
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_                                                                         %#ok<NOPTS>
0054 R_                                                                         %#ok<NOPTS>
0055 Z_'                                                                        %#ok<NOPTS>
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 %% 2. camera
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); % zeros(3,1);
0072 P = calc_P_from_KRZ(K,R,Z)                                                 %#ok<NOPTS>
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_                                                                         %#ok<NOPTS>
0080 R_                                                                         %#ok<NOPTS>
0081 Z_'                                                                        %#ok<NOPTS>
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 %% 3. camera
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); % zeros(3,1);
0099 P = calc_P_from_KRZ(K,R,Z)                                                 %#ok<NOPTS>
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_                                                                         %#ok<NOPTS>
0107 R_                                                                         %#ok<NOPTS>
0108 Z_'                                                                        %#ok<NOPTS>
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 %% 4. camera
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); % zeros(3,1);
0125 P = calc_P_from_KRZ(K,R,Z)                                                 %#ok<NOPTS>
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_                                                                         %#ok<NOPTS>
0133 R_                                                                         %#ok<NOPTS>
0134 Z_'                                                                        %#ok<NOPTS>
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)]);

Generated on Sat 21-Jul-2018 20:56:10 by m2html © 2005