# Revision history [back]

### constructing camera matrix out of euler angle and translation vector

Hi , Can anyone of you please find out whats wrong with my simple matlab code to construct camera matrix out of euler angles and translation vector. Thanks stethorsh

% % solves the camera model [ p ]=[F][P3]

% [P3] = [-306.8843; -263.0437; 0] a point world coordinate % [p] = [ 447.3374 ; 487.9971 ] corresponding image point

% Aim : construct a matrix ' F ' , so that [ p ]=[F][P3]

%pos1(1:3)=x, y, z -coordinates (actually, the position % of the calibration coordinate frame origin with % respect to the camera coordinate frame) %pos1(4:6)=w, p, r euler rotation angles around x, y, z axes.

%par(1)=scale factor ~1 %par(2)=effective focal length %par(3:4)=principal point %par(5:6)=radial distortion coefficients %par(7:8)=tangential distortion coefficients

clc clear all close all

% %

%-------------- Result of caldemo.m -------------------- par=[1.0281;16.5621;285.7615;249.037;0.0005;0.000;0.0002;-0.0001]; % result of caldemo.m for 1st image pos1=[-28.3;-10.4;1794.3;149.2;-53.6;-56.2]; % result of caldemo.m s=1;

%---------------------------------------------------

%one of the calibration point in data1 % Known Pi=[-306.8843;-263.0437; 0;] pi=[447.3374 ; 487.9971;]

%-------- constructing P matrix ---------- P(1,1)=s*par(2); P(1,2)=0; P(1,3)=par(3);P(1,4)=0; P(2,1)=0; P(2,2)=par(2); P(2,3)=par(4);P(2,4)=0; P(3,1)=0; P(3,2)=0; P(3,3)=1;P(3,4)=0; %------------------------------------------

%---- % --- constructing rotation & Tranltn matrix--------- T=pos1(1:3); w=pos1(4);phi=pos1(5);k=pos1(6); ang=[w;phi;k]; r11=cosd(phi)cosd(k); r12=(sind(w)sind(phi)cosd(k))-(cosd(w)sind(k)); r13=(cosd(w)sind(phi)cosd(k))+(sind(w)sind(k)); r21=cosd(phi)sind(k); r22=(sind(w)sind(phi)sind(k))+(cosd(w)cosd(k)); r23=cosd(w)sind(phi)sind(k)-(sind(w)cosd(k)); r31=-sind(phi); r32=sind(w)cosd(phi); r33=cosd(w)cosd(phi); R1=[r11 r12 r13; r21 r22 r23; r31 r32 r33]; %R2=ang2orth(ang); %R3=; R=R1; %--------------------------------------------------------------

% --- % ---- constructing M matrix M(1:3,1:3)=R;M(1:3,4)=T;M(4,:)=[0 0 0 1]; %------------------------------------------------------------------

F=P*M; p=[447.3374 ;487.9971 ;1];

P3 = F\p

% % % x = A\B solves the system of linear equations A*x = B

% R=R1; % RT=cat(2,R,T); %Rotation translation matrix % ART=A*RT; % Camera matrix %
% p=[447.3374 ;487.9971 ;1]; % P3=(ART)\p %p(1,1)=p(1,1)+par(3);p(2,1)=p(2,1)+par(4);

% % % % --- % ---- constructing M matrix % m11=r11;m12=r12;m13=r13;m14=T(1); % m21=r21;m22=r22;m23=r23;m24=T(2); % m31=r31;m32=r32;m33=r33;m34=T(3); % m41=0;m42=0;m43=0;m44=1; % %M=[m11 m12 m13 m14;m21 m22 m23 m24; m31 m32 m33 m34;m41 m42 m43 m44]; %
% M(1:3,1:3)=R;M(1:3,4)=T;M(4,:)=[0 0 0 1]; % %------------------------------------------------------------------

% % rotation matrix % r11=cos(phi)cos(k); % r12=(sin(w)sin(phi)cos(k))-(cos(w)sin(k)); % r13=(cos(w)sin(phi)cos(k))+(sin(w)sin(k)); % r21=cos(phi)sin(k); % r22=(sin(w)sin(phi)sin(k))+(cos(w)cos(k)); % r23=cos(w)sin(phi)sin(k)-(sin(w)cos(k)); % r31=-sin(phi); % r32=sin(w)cos(phi); % r33=cos(w)cos(phi); % R1=[r11 r12 r13; r21 r22 r23; r31 r32 r33]; % %--------------------------------------------