Kalibrasi Kamera

Image target kalibrasi (stereo1.jpg)

Image target kalibrasi (stereo2.jpg)

Urutan untuk memasukkan koordinat object

input = imread(‘stereo2.jpg’);
imshow(input),uv = ginput(12);
kalibrasi = calibrate(input,calibPts,uv);

Nilai matriks kalibrasi :

0.6527 -0.7566 -0.0287 364.0208
-0.1987 -0.1420 -0.9352 345.0292
0.0005 0.0003 -0.0002 1.0000

mean squared error : 4.474812e-001

error proyeksi : 5.122219e-011

input = imread(‘stereo2.jpg’);
imshow(input),uv = ginput(12);
kalibrasi = calibrate(input,calibPts,uv);

Nilai matriks kalibrasi :
1.0166 -0.1647 -0.0491 348.8653
-0.0334 -0.1977 -0.9364 341.7672
0.0004 0.0006 -0.0002 1.0000

mean squared error : 3.100241e-001

error proyeksi : 7.542963e-009

Listing program

% CALIBRATE
%
% Function to perform camera calibration
%
% Usage: C = calibrate(im, XYZ, uv)
%
% Where: im – is the image of the calibration target.
% XYZ – is a n x 3 array of XYZ coordinates
% of the calibration target points.
% uv – is a 2 x n array of the image coordinates
% of the calibration target points.
% C – is the 3 x 4 camera calibration matrix.
%
% This function plots the uv coordinates onto the image of
% the calibration target. It also projects the XYZ coordinates
% back into image coordinates using the calibration matrix
% and plots these points too as a visual check on the accuracy of
% the calibration process.
% Lines from the origin to the vanishing points in the X, Y and
% Z directions are overlaid on the image.
% The mean squared error between the positions of the uv coodinates
% and the projected XYZ coordinates is also reported.
%
% The function should also report the error in satisfying the
% camera calibration matrix constraint – the magnitude of
% (q1 x q3).(q2 x q3)
%

function C = calibrate(im, XYZ, uv)

% transpose koordinat 2 dimensi
b = uv’;

% dapatkan ukuran 3 dimensi image
[rows, cols] = size(XYZ);

% tambahkan kolom bernilai 1 ke matriks koordinat 3 dimensi
XYZ1 = [XYZ, ones(rows, 1)];

% buat matriks A
for n = 1:rows
A(2*n-1, πŸ™‚ = [XYZ1(n, πŸ™‚ 0 0 0 0 -b(1, n)*XYZ(n, :)];
A(2*n, πŸ™‚ = [0 0 0 0 XYZ1(n, πŸ™‚ -b(2, n)*XYZ(n, :)];
end

% masukkan ke persamaan utama
q = A \ b(:);
q(12) = 1;

% buat matriks kalibrasi
disp(‘Nilai matriks kalibrasi :’);
C = reshape(q,4,3)’;
disp(C);

% dapatkan koordinat sebenarnya di 2 dimensi
XYZ1 = XYZ1′;

for i = 1:rows
suv(:,i) = C*XYZ1(:,i);
suv(:,i) = suv(:,i)/suv(3,i);
end

mse = mean(mean((b – suv(1:2,:)).^2));
fprintf(1, ‘mean squared error : %d\n’, mse);

% calculate the error in satisfying the camera calibration matrix constraint
q1 = C(1,1:3)’;
q2 = C(2,1:3)’;
q3 = C(3,1:3)’;

error = abs(dot(cross(q1, q3), cross(q2, q3)));
fprintf(1, ‘error proyeksi : %d\n’, error);

% tampilkan hasil kalibrasi
imshow(im);
hold;

% plot uv coordinates
plot(b(1, :), b(2, :),’rx’,’markerSize’,15)

% plot XYZ coordinates
plot(suv(1,:), suv(2,:),’b+’,’markerSize’,10)

% inisialisasi panjang sumbu koordinat yang akan ditampilkan
sumbu = [200 0 0 1; 0 200 0 1; 0 0 200 1];
sumbu = sumbu’;

% gambar vanishing lines
for i = 1:3
axis(:,i) = C*sumbu(:,i);
axis(:,i) = axis(:,i)/axis(3,i);
line([C(1,4), axis(1,i)],[C(2,4), axis(2,i)]);
end

% plot pusat koordinat
plot(C(1,4),C(2,4),’go’);
hold;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s