8/17/2011

World 3D point reconstruction using Direct Linear Transformation(DLT) / Matlab source / 선형 삼각법을 이용한 월드좌표 복원



Created Date : 2011.07
Language : Matlab
Tool : Matlab
Library & Utilized: rodrigues function(obtain from internet)
Reference : Multiple View Geometry Book


Calculate 3D world coordination using Direct Linear Transformation(DLT)
Firstly, I prepared 2D coordinate of Left, Right image and rotation, translation and camera calibration matrix.
Make Projection matrix. P1 is left camera projection matrix, P2 is right.
But, P1 is reference camera, so P1 is just P1=C[I|0].
Make World coordination using DLT, The DLT method is introduced in Multiple view geometry page 312.
Again, calculate image coordinate using W, P1, P2 for confirmation.
We can confirm that calculated coordinate and input image coordinate is same.

You can download entire matlab source code < here >



--------------------------------------------------------------


선형 삼각법을 이용한 3D 월드 좌표 계산.
아래 소스는 임의로 정한 왼쪽, 오른쪽 이미지의 매칭된 좌표 쌍과
임의로 정한 회전, 이동 행렬 그리고  카메라 파라미터를 이용하여 월드 3D점을 계산하는 과정이다.
복원된 3D 좌표는 확인을 위하여 다시 2D의 이미지 좌표로 변환한다.
변환한 2D 이미지 좌표가 처음 입력한 좌표와 값이 같음을 확인할 수 있다.

여기에서 전체 매트랩 코드를 다운 받으세요 < here >
----------------------------------------------------------------------------------------------
%%
clc;
clear all;
close all;
%% image coordinate 
m1 = [ -88.6          1019.21739130435          1046.63913043478         -9643.52173913043          1488.59518796992;
      -216         -14137.7391304348          -629.04347826087          18775.3043478261         -464.421052631579];
m2 = [ 644.916058797683          8264.25802702142          2735.93716970091         -3264.00791696585          4601.62993487106;
    237.341114262516          -16276.926674065         -591.505245744724          4076.20064528107         -313.261770012357];
% rotation matrix
RealR = rodrigues( [-10 30 20]*pi/180 );
% translation matrix
RealT = [20 30 200]';
RealA=rodrigues(RealR)*180/pi; % rotation matrix angle Test
K = [1000 1 512;0 1000 384;0 0 1;]; %calibration matrix
%% P1, P2 만들기
P1 = K*[eye(3) zeros(3,1)]; % left camera Projection matrix 
P2 = K*[RealR RealT]; % right camera projection matrix
%% 3차원 점 만들기
%P1, P2를 이용한 3차원 점 복원
% World 3D coordination reconstruction by Direct Linear Transformation 
% Multiple view geometry P.312
W=[];
for i=1:5
    A=[ m1(1,i)*P1(3,:) - P1(1,:); 
        m1(2,i)*P1(3,:) - P1(2,:);
        m2(1,i)*P2(3,:) - P2(1,:);
        m2(2,i)*P2(3,:) - P2(2,:)];
    A(1,:) = A(1,:)/norm(A(1,:));
    A(2,:) = A(2,:)/norm(A(2,:));
    A(3,:) = A(3,:)/norm(A(3,:));
    A(4,:) = A(4,:)/norm(A(4,:));
    
    [u d v] = svd(A);
    W=[W v(:,4)/v(4,4)];    
end
%% 다시 3차원 점에서 픽셀 점 만들기
% again calculate 2D image point from World coordinate, projection matrix
reip1 = P1*W;
reip1 = [reip1(1,:)./reip1(3,:); reip1(2,:)./reip1(3,:)]
m1(:,1:5)
reip2 = P2*W;
reip2 = [reip2(1,:)./reip2(3,:); reip2(2,:)./reip2(3,:)]
m2(:,1:5)
% m1 and reip1 is same. Also, m2 and reip2 is same.






(Please understand my bad english ability. If you point out my mistake, I would correct pleasurably. Thank you!!)

No comments:

Post a Comment