Está en la página 1de 36

Chapter 3

Camera Geometry and


Single View Geometry
Version 11.05.2015

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-1

Content

3.1 Geometrical Imaging Process


3.1.1 Introduction
3.1.2 Extrinsic Model
3.1.3 Extrinsic Model Matlab Example
3.1.4 Intrinsic Model Projection
3.1.5 Intrinsic Model Affine Transformation
3.1.6 Summary
3.2 Pinhole Camera Model
3.2.1 The Geometrical Model of a Pinhole Camera
3.2.2 The Geometrical Model of a Pinhole Camera Matlab
Example
3.2.3 Intrinsic Model Camera Calibration Matrix K
3.2.4 Extrinsic Model
3.2.5 Extrinsic Model Matlab Example
3.3 Projective Camera Model
3.3.1 Intrinsic Model Camera Calibration Matrix K
3.3.2 The Projection Matrix P
3.3.2 The Projection Matrix P Matlab Example
3.3.3 The Projection Matrix P Example Basler acA630100gc

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-2

3.1 Geometrical Imaging Process


3.1.1 Introduction
An imaging device or camera usually maps an observed
3D scene to a 2D image by projection.
Several projection principles are known and vitally
characterize a camera: parallel projection, perspective
projection, orthographic projection, oblique projection,

Projection principles can be mathematically approximated


by an appropriate model which is commonly known as
camera model or projection model.

Most commonly known imaging devices follows the


perspective projection principle and is known as pinhole
camera model
Focal length f
Camera (box)

Optical axis/principle axis

Sensor Plane/Image Plane

Principle Point / Camera Center / Optical Center / Pinhole

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-3

3.1 Geometrical Imaging Process


3.1.1 Introduction
Mathematically the image that has been projected upsidedown can be flipped using the principle point

Focal length f

Principle Plane
Sensor Plane/Image Plane
Professur Digital- und Schaltungstechnik
Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-4

3.1 Geometrical Imaging Process


3.1.1 Introduction
The principle of the pinhole camera was already
discovered by Aristoteles (384-322 B.C.).
First steps with the pinhole camera was taken by the Arab
Alhazen in 980 as he investigates the human eye.
At the end of the 13th century astronomics used the
pinhole camera to observe sunspots.

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-5

3.1 Geometrical Imaging Process


3.1.1 Introduction
The first published picture of a pinhole camera obscura is apparently a drawing in Gemma Frisius' De Radio Astronomica et
Geometrica (1545).
The very term camera obscura ("dark room") was coined by Johannes Kepler (15711630).
The first photography was taken by a pinhole camera in 1816 by Joseph Nicphore Nipcecht. Unfortunately he wasnt
able to fix it. But a few months later he presents the first photo of the world, a view out of his studyroom.

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-6

3.1 Geometrical Imaging Process


3.1.1 Introduction
The geometrical relationship between 3D scene points
Xwrld and the resulting 2D image points Ximg is often quite
complex due to the physical construction of the imaging
device.

X wrld

xwrld
y
wrld
zwrld

w
wrld

By employing a finite amount of numerical parameters,


the actual process of projection can be replaced by an
appropriate mathematical relationship of bearable
computational cost.

Geometrical imaging process

Ximg

ximg

yimg
wimg

3D scene point
Camera

zwrld

Ximg

X wrld
ywrld

xwrld

Observed scene

2D
Image point

Image

World coordinate system

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-7

3.1 Geometrical Imaging Process


3.1.1 Introduction
The overall imaging process that transfers a scene point
Xwrld to an image point Ximg successively utilizes an
extrinsic and an intrinsic model

X wrld

xwrld
y
wrld
zwrld

w
wrld

Extrinsic model

Xcam

Xcam

xcam
y
cam
zcam

w
cam

Intrinsic model

Ximg

ximg

yimg
wimg

xcam

zcam

ximg
Image coordinate system

Camera

zwrld

ycam

X wrld
xwrld

yimg

ywrld

Camera coordinate system

Ximg

Observed scene

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-8

3.1 Geometrical Imaging Process


3.1.2 Extrinsic Model
Transformation from world points Xwrld to camera points Xcam in multiple camera environments
Incorporates the distinct geometrical relationship Hi of each camera with respect to WCS
xcam
zcam

R 0 C0
Camera

Xcam,0
Xcam,1

xcam

zcam

R1 C1
Camera

zwrld

X wrld
xwrld

Observed scene

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

ywrld

H1
H0

R
Hi i
0

R iCi
1

Xcam,0 H 0 1 X wrld
Xcam,1 H11 X wrld

Ci
origin of the camera coordinate
frame provided in world frame
coordinates
Ri
3x3 rotation matrix representing the
orientation of the
camera
coordinate frame with respect to
the world frame
R results out of three angles
discribing a sequence of three
elementary rotations around x, y, zaxis respectively (each performed
clockwise)
Computer Vision
Version vom 11.05.2015

1-9

3.1 Geometrical Imaging Process


3.1.3 Extrinsic Model - Matlab Example
Example: Optical sensor network to observe a complex indoor environment (e.g. domestic home environment)

Camera 3

WCS

Camera 2
Camera 1

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-10

3.1 Geometrical Imaging Process


3.1.3 Extrinsic Model - Matlab Example
0001 clear all; close all; clc;
0002
0003 %% Extrinsic Camera Parameter
0004 % Camera centres
0005 C1 = [ 2.6607;

0.1006; 2.4089]; % Smart Sensor 605

0006 C2 = [-1.6157;

2.7995; 2.4119]; % Smart Sensor 601

0007 C3 = [-1.8482; -1.7443; 2.3955]; % Smart Sensor 602


0008
0009 % Rotation matrices
0010 R1 = [

-0.7770

0.6286

0.0339

0011

0.3719

0.5018

-0.7809

0012

-0.5079

-0.5942

0014 R2 = [

-0.5233

-0.8521

0.0080

0015

-0.5388

0.3236

-0.7778

0016

0.6602

-0.4113

0018 R3 = [

-0.4861

-0.8670

0.1097

0019

-0.6689

0.2884

-0.6852

0020

0.5624

-0.4065

-0.6237];

0013

-0.6285];

0017

-0.7201];

0021

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-11

3.1 Geometrical Imaging Process


3.1.3 Extrinsic Model - Matlab Example
0022 % Translation vectors
0023 T1 = -R1*C1;
0024 T2 = -R2*C2;
0025 T3 = -R3*C3;
0026
0027 %% Setup Homographies
0028 H1 = [R1 T1; 0 0 0 1];
0029 H2 = [R2 T2; 0 0 0 1];
0030 H3 = [R3 T3; 0 0 0 1];
0031
0032 %% Plot WCS
0033 h1 = figure(1); hold on; grid on; axis equal;
0034 xlabel('x [m]'); ylabel('y [m]'); zlabel('z [m]'); view(70, 20);
0035 axis([-3 +3 -3 +3 0 3]);

0036
0037 i = [1; 0; 0];
0038 j = [0; 1; 0];
0039 k = [0; 0; 1];
0040 o = [0; 0; 0];
0041
0042 plot3([o(1) i(1)], [o(2) i(2)], [o(3) i(3)], 'r-', 'MarkerSize', 5);
0043 plot3([o(1) j(1)], [o(2) j(2)], [o(3) j(3)], 'g-', 'MarkerSize', 5);
0044 plot3([o(1) k(1)], [o(2) k(2)], [o(3) k(3)], 'b-', 'MarkerSize', 5);
Professur Digital- und Schaltungstechnik
Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-12

3.1 Geometrical Imaging Process


3.1.3 Extrinsic Model - Matlab Example
0045
0046 %% Plot camera coordinate systems
0047 i1 = H1^-1*[i; 1];
0048 j1 = H1^-1*[j; 1];
0049 k1 = H1^-1*[k; 1];
0050 o1 = H1^-1*[o; 1];
0051
0052 plot3([o1(1) i1(1)], [o1(2) i1(2)], [o1(3) i1(3)], 'r-', 'MarkerSize', 1);
0053 plot3([o1(1) j1(1)], [o1(2) j1(2)], [o1(3) j1(3)], 'g-', 'MarkerSize', 1);
0054 plot3([o1(1) k1(1)], [o1(2) k1(2)], [o1(3) k1(3)], 'b-', 'MarkerSize', 1);
0055
0056 i2 = H2^-1*[i; 1];
0057 j2 = H2^-1*[j; 1];
0058 k2 = H2^-1*[k; 1];

0059 o2 = H2^-1*[o; 1];


0060
0061 plot3([o2(1) i2(1)], [o2(2) i2(2)], [o2(3) i2(3)], 'r-', 'MarkerSize', 1);
0062 plot3([o2(1) j2(1)], [o2(2) j2(2)], [o2(3) j2(3)], 'g-', 'MarkerSize', 1);
0063 plot3([o2(1) k2(1)], [o2(2) k2(2)], [o2(3) k2(3)], 'b-', 'MarkerSize', 1);

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-13

3.1 Geometrical Imaging Process


3.1.3 Extrinsic Model - Matlab Example
Observed Indoor Scene

H0

H1
WCS

H2

0064

0065 i3 = H3^-1*[i; 1];


0066 j3 = H3^-1*[j; 1];
0067 k3 = H3^-1*[k; 1];

Floor (z == 0 m)

0068 o3 = H3^-1*[o; 1];


0069
0070 plot3([o3(1) i3(1)], [o3(2) i3(2)], [o3(3) i3(3)], 'r-', 'MarkerSize', 1);
0071 plot3([o3(1) j3(1)], [o3(2) j3(2)], [o3(3) j3(3)], 'g-', 'MarkerSize', 1);
0072 plot3([o3(1) k3(1)], [o3(2) k3(2)], [o3(3) k3(3)], 'b-', 'MarkerSize', 1);

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-14

3.1 Geometrical Imaging Process


3.1.4 Intrinsic Model - Projection
The Projection process from Xcam to normalized sensor
coordinates Xnorm is modelled by a projection function F
The cameras sensor plane is assumed to have unit
length from the principle point

Xcam

xcam
y
cam
zcam

w
cam

Projection

X norm

xnorm
ynorm
1

Camera sensor plane

ynorm

Xnorm

xnorm
Normalized sensor coordinate system

Xcam

Observed scene

Focal length f normalized


to unit length
ycam

zcam
xcam
Camera centre/Principle point

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-15

3.1 Geometrical Imaging Process


3.1.4 Intrinsic Model - Projection
The camera coordinate Xcam is considered as incident
light ray (, , )

Xcam

xcam

ycam
zcam

The radial projection of an incoming light ray (, , )


onto a virtual image plane with a distance of f = 1 to the
projection center can be modelled with the radial
projection function F():

x
X norm norm F ( ) ( ) u r
ynorm
cos
with u r

sin

elevation
ynorm

Xnorm ()

ur

xnorm

distance

Xcam

Observed scene

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

azimuth
ycam

zcam
xcam

Computer Vision
Version vom 11.05.2015

1-16

3.1 Geometrical Imaging Process


3.1.4 Intrinsic Model - Projection
Projection
Type

Function F

Properties and Applications

Perspective
projection

= tan

Applied
in
conventional
cameras that follow the pinhole
principle with < 2

Stereographic
projection

= 2 tan 2

Commonly
used
for
the
generation of stellar maps and
photography.
angles
are
preserved (equal angles) and
circles are imaged without
distortions (equal circles).

Equidistance
projection

It is the most popular model for


describing fisheye projection
lenses. Incidence angles of rays
are imaged linearly.

Equisolid
angle
projection

= 2 sin

Orthogonal
projection

= sin

Each pixel corresponds to one


distinct solid angle which makes
the image look like the reflection
by a specular ball.
This camera principle models
the projection onto a sphere.
The projection radius is
increasing with increasing
incidence angle
until reaches pi/2. Than it is
declining again.

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-17

3.1 Geometrical Imaging Process


3.1.4 Intrinsic Model - Projection
Perspective Projection
Most commonly applied projection method
Limited field of view (FOV) to approx. 120 ()

Equiangular Projection
Applied by e.g. fish-eye cameras
FOV > 180

= tan

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-18

3.1 Geometrical Imaging Process


3.1.5 Intrinsic Model Affine Transformation
The transformation from normalized sensor coordinates to
image coordinates is finally done by means of an affine
transformation matrix K
K is called camera calibration matrix

X norm

xnorm
ynorm
1

Affine
Transformation

Ximg

ximg

yimg
wimg

ynorm

Xnorm

xnorm

ximg

Normalized sensor coordinate system

Image coordinate system


yimg

Ximg

Ximg K X norm

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-19

3.1 Geometrical Imaging Process


3.1.6 Summary
Geometrical imaging process is characterized by an
extrinsic and intrinsic model
Intrinsic model (camera model) is split into different
projection models F and an affine transformation K
Relevant camera models are
Pinehole camera model
Projective camera model

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-20

3.2 Pinhole Camera Model


3.2.1 The Geometrical Model of a Pinhole Camera
Central projection is mapping a point Xcam in 3D space to
a point Ximg in 2D space:

xcam , ycam , zcam

imaging process

, yimg

img

Using similar triangles one verifies that:

xcam , ycam , zcam

Xcam

f xcam / zcam , f ycam / zcam

Using homogeneous coordinates, one can put that


transformation in a matrix expression:
ximg
f xcam f
1


yimg z f ycam
cam
1

zcam

0
0
1 0

xcam

1 ycam

zcam zcam

1
normalized sensor coordinates
tan

image point in 2D
image frame

Ximg

The 3x4 transformation matrix used is called a camera


projection matrix P

Ximg P Xcam
P can be decomposed in the following manner:

object point in
3D world frame
Xcam

x
f ycam / zcam
f

P diag( f , f ,1) I | 0

The Diagonal Matrix is called the camera calibration


matrix K
K diag ( f , f ,1)
Professur Digital- und Schaltungstechnik
Prof. Dr.-Ing. Gangolf Hirtz

zcam

Computer Vision
Version vom 11.05.2015

1-21

3.2 Pinhole Camera Model


3.2.2 The Geometrical Model of a Pinhole Camera - Matlab Example
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028

%% Camera Matrix
% Intrinsic Camera Parameter
f = 4;
% Focal Length
% Setup Projection matrix
P = diag([f f 1])*[eye(3) zeros(3, 1)];
%% Project World Point
Xw = [4; 5; 9];
% Object Point (World Frame)
% X = 4, Y = 5, Z = 9
Xw_h = [Xw; 1];
% Transform to homogeneous Coordinates
Xc_h = P*Xw_h;
% Project!
Xc = 1/Xw(3)*Xc_h;% Image Point (Camera Frame)
%% Plot Principal Point
figure_01 = figure; hold on; grid on;
plot3(0, 0, 0, 'm.', 'Markersize', 20);
%% Draw Image Plane
[X, Y, Z] = meshgrid(-5:0.1:5, -5:0.1:5, -5:0.1:5);
data = 0*X+0*Y+1*Z-f; % Normal from for a plane
p = patch(isosurface(X, Y, Z, data, 0)); hold on;
set(p, 'FaceColor', 'red', 'EdgeColor', 'none')
alpha(0.5); view(17,24);
axis([-5 5 -5 5 0 10]);

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-22

3.2 Pinhole Camera Model


3.2.2 The Geometrical Model of a Pinhole Camera - Matlab Example
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0041
0042
0043
0044
0045
0046

%% Draw Object and Image Point


plot3(Xw(1), Xw(2), Xw(3), 'b*', 'Markersize', 10);
plot3(Xc(1), Xc(2), f, 'b*', 'Markersize', 5);
plot3([0 Xw(1)], [0 Xw(2)], [0 Xw(3)], 'b--');

%% Add some text


text(0.5, 0.5, 0,...
'Principal Point', 'FontSize', 10,...
'FontWeight', 'bold', 'Color', 'magenta');
text(Xw(1) - 3.0, Xw(2) - 3.0, Xw(3),...
'Object Point',
'FontSize', 10, 'FontWeight', 'bold', 'Color', 'blue');
text(Xc(1) + 0.5, Xc(2) + 0.5, f,...
'Image Point',
'FontSize', 10,...
'FontWeight', 'bold', 'Color', 'blue');
text(-2, -2, f,...
'Image Plane',
'FontSize', 10,...
'FontWeight', 'bold', 'Color', 'red');

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-23

3.2 Pinhole Camera Model


ximg

3.2.3 Intrinsic Model - Camera Calibration Matrix K


It is common for images to have only positive coordinates
(image coordinates start at the upper left corner of the
image), so a further adaption has to be done

ximg ximg cx

yimg yimg c y

The principal point (cx, cy) is the offset with respect to the
image frame and enhances the camera calibration matrix

f
K

Image coordinate system


yimg

Ximg

ximg
Principal Point (cx, cy)

yimg

cx
c y
1

K is an upper triangle matrix with 3 dof


A camera is denoted as a calibrated camera so soon as
K is known
The pinhole camera model is a ideal one assuming that
image coordinates are Euclidean coordinates having
equal scales in both axial directions

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-24

3.2 Pinhole Camera Model


3.2.4 Extrinsic Model
Every single cameras position C is described by a
rotation R and a translation T with respect to the world
coordinate system
A Point Xwrld can be translated into a point Xcam by the
following mathematical relationship
H0

Xcam R X wrld C

H1

H2

WCS
Homogeneous coordinates let us use this relation in a
more compact matrix form
R RC
Xcam
X wrld
1

The overall imaging process is now as follows:


Ximg P X cam
Ximg K I | 0 X cam
R RC
Ximg K I | 0
X wrld
1

With the new relationship one can determine the image


coordinates of a point given in world coordinates as
follows:
Ximg P X wrld

with P KR I | C

P can be computed from point correspondences Xwrld


Ximg

Ximg K R |
RC X wrld
Translation vector T
Ximg K R I | C X wrld

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-25

3.2 Pinhole Camera Model


3.2.5 Extrinsic Model Matlab Example
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026

%% Camera Matrix
% Intrinsic Camera Parameter
f = 2;
% Focal Length
K = diag([f f 1]); % Intrinsic camera Parameter
% Extrinsic Camera Parameter
C1 = [-3; +4; -3];
% Camera Centre Cam 1
C2 = [3; -4; 1];
% Camera Centre Cam 2
C3 = [3; -5; -5];
% Camera Centre Cam 2
% Rotate Cam 1 by 0, Cam2
% arround the x-axis
R1 = [1.0000
0
0
1.0000
0
0
R2 = [1.0000
0
0
-0.7071
0
0.7071
R3 = [1.0000
0
0
0
0
1.0000
t1 = -R1*C1;
t2 = -R2*C2;
t3 = -R3*C3;

by 45 and Cam3 by 90
0
0
1.0000];
0
0.7071
0.7071];
0
1.0000
0];

% Translation vector with respect to R and C


% Translation vector with respect to R and C
% Translation vector with respect to R and C

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-26

3.2 Pinhole Camera Model


3.2.5 Extrinsic Model Matlab Example
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054

% Setup Projection matrix


P1 = K*[R1 t1];
P2 = K*[R2 t2];
P3 = K*[R3 t3];
%% Plot Principal Points
figure_01 = figure; hold on; grid on;
plot3(C1(1), C1(2), C1(3), 'r.', 'Markersize', 20);
plot3(C2(1), C2(2), C2(3), 'g.', 'Markersize', 20);
plot3(C3(1), C3(2), C3(3), 'b.', 'Markersize', 20);
%% Draw Image Plane Camera 1
[X, Y, Z] = meshgrid(
(C1(1)-3):0.1:(C1(1)+3),...
(C1(2)-3):0.1:(C1(2)+3),...
(C1(3)-3):0.1:(C1(3)+3));
plane = P1(3, :);
data = plane(1)*X + plane(2)*Y + plane(3)*Z + (plane(4)-f)*1;
p = patch(isosurface(X, Y, Z, data, 0)); hold on;
set(p, 'FaceColor', 'red', 'EdgeColor', 'none');
%% Draw Image Plane Camera 2
[X, Y, Z] = meshgrid(
(C2(1)-3.0):0.1:(C2(1)+3.0),...
(C2(2)-4.2):0.1:(C2(2)+4.2),...
(C2(3)-4.2):0.1:(C2(3)+4.2));
plane = P2(3, :);
data = plane(1)*X + plane(2)*Y + plane(3)*Z + (plane(4)-f)*1;
p = patch(isosurface(X, Y, Z, data, 0)); hold on;
set(p, 'FaceColor', 'green', 'EdgeColor', 'none');

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-27

3.2 Pinhole Camera Model


3.2.5 Extrinsic Model Matlab Example
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066

%% Draw Image Plane Camera 3


[X, Y, Z] = meshgrid(
(C3(1)-3):0.1:(C3(1)+3),...
(C3(2)-3):0.1:(C3(2)+3),...
(C3(3)-3):0.1:(C3(3)+3));
plane = P3(3, :);
data = plane(1)*X + plane(2)*Y + plane(3)*Z + (plane(4)-f)*1;
p = patch(isosurface(X, Y, Z, data, 0)); hold on;
set(p, 'FaceColor', 'blue', 'EdgeColor', 'none');

alpha(0.5); view(140, 35);


axis([C(1)-10 C(1)+10 C(2)-10 C(2)+10 C(3)-10 C(3)+10]);

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-28

3.3 Projective Camera Model


ximg

3.3.1 Intrinsic Model - Camera Calibration Matrix K


In the case of CCD cameras there is the possibility to
have non-square pixels and hence having unequal scale
factors for both image directions.

yimg

Ximg

Imagine a pixel density (no. of pixels per unit length) of


mx (x-direction) and my (y-direction), the calibration matrix
K changes to

x s
K
y

cx
c y with x f mx , y f m y , s f
1

where x and y represent the focal length with respect


to the pixel dimensions in both directions.
Although it is very seldom for some rare cases it is
necessary to introduce the skew factor s, defining the
geometrical dependency of the y-dimension in pixel
frame from the x-axis:
s>0

s=0

A camera having P as described above is known as finite


projective camera.and has 11 degrees of freedom

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Aspect Ratio

The ratio of x and y is often called aspect ratio and is


very close to 1.
x/y =<1

x/y = =1

mxno. of pixel per m along the x-axis, hor. pixel density,


[px/m]
myno. of pixel per m along the y-axis,vert. pixel density,
[px/m],
Shear angle between the image axes; is encoded
within s
(x, y)
focal length, with respect to pixel dimensions
Computer Vision
Version vom 11.05.2015

1-29

3.3 Projective Camera Model


3.3.2 The Projection Matrix P
The imaging process of a camera is completely described
by the projection matrix P

Ximg P X wrld

The projection matrix P is a 3x4 matrix performing the


transformation from projective space in 3D to a 2D plane

x1 p11

x2 p21
x p
3 31

p12
p22
p32

p13
p23
p33

x
p14 1
x
p24 2
x
p34 3
x4

Note that P has only eleven degrees of freedom, though


it has twelf components. In other words, P is determined
up to an unknown scale factor
P can be decomposed in the following manner

p1R
P p 2R
p 3R

|
p1C
|

p 2C

p 3C

|
p 4C
|

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-30

3.3 Projective Camera Model


3.3.2 The Projection Matrix P
Rows
Rows of P can be seen as planes in the projective space
P3 (Principal Plane, Planes orthogonal to x-, y-axis
containing principal point and origin of image coordinate
system)
The line formed by the intersection of the rows p2R and
p3R connects the principal point and the origin of the
image coordinate system

Columns
Columns of P denote special points within the projection
plane
p1C, p2C, p3C are the projections of the axis directions of
x-, y- and z-axis.
p4C is the projection of the origin of the world frame.
Projection Centre/Principal Point
P C 0

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-31

3.3 Projective Camera Model


3.3.3 The Projection Matrix P - Matlab Example
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042

%% Camera Matrix
% Intrinsic Camera Parameter
f = 2;
% Focal Length
K = diag([f f 1]); % Intrinsic camera Parameter
K(1, 3) = 0;
K(2, 3) = 0;
% Extrinsic Camera Parameter
C = [0; 0; 0];
% Camera Centre
R = [1 0 0
0 0 1
0 1 0];
% We change x and y coordinates
t = -R*C;
% Translation vector with respect to R and C
% Setup Projection matrix
P = K*[R t];
%% Graphical Sketch
figure_01 = figure; hold on; grid on;
plot3(C(1), C(2), C(3), 'm.', 'Markersize', 20);
%% Draw all Planes encoded in P
[X, Y, Z] = meshgrid(
(C(1)-5):0.1:(C(1)+5),...
(C(2)-0):0.1:(C(2)+5),...
(C(3)-5):0.1:(C(3)+5));

0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060

set(p, 'FaceColor', 'red', 'EdgeColor', 'none');


% The Image Plane is the Principal Plane with an offset of f!
plane = P(3, :);
data = plane(1)*X + plane(2)*Y + plane(3)*Z + (plane(4)-f)*1;
p = patch(isosurface(X, Y, Z, data, 0)); hold on;
set(p, 'FaceColor', 'blue', 'EdgeColor', 'none');
alpha(0.5); view(110, 15);
axis([C(1)-5 C(1)+5 C(2)-0 C(2)+5 C(3)-5 C(3)+5]);
% Save Image
print(figure_01, '-r600', '-dtiff',...
'..\Images\16_Example_Projection_Matrix_01.tif');
% Convert document to rtf
highlight('m05_Example_Camera_Matrix.m', 'rtf', ...
'm05_Example_Camera_Matrix.rtf')

P=
2
0
0

0
0
1

0
2
0

0
0
0

% The x-axis Plane is the 1rd row of P!


plane = P(1, :);
data = plane(1)*X + plane(2)*Y + plane(3)*Z + plane(4)*1;
p = patch(isosurface(X, Y, Z, data, 0)); hold on;
set(p, 'FaceColor', 'yellow', 'EdgeColor', 'none');
% The y-axis Plane is the 2rd row of P!
plane = P(2, :);
data = plane(1)*X + plane(2)*Y + plane(3)*Z + plane(4)*1;
p = patch(isosurface(X, Y, Z, data, 0)); hold on;
set(p, 'FaceColor', 'green', 'EdgeColor', 'none');
% The Principal Plane is the 3rd row of P!
plane = P(3, :);
data = plane(1)*X + plane(2)*Y + plane(3)*Z + plane(4)*1;
p = patch(isosurface(X, Y, Z, data, 0)); hold on;

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-32

3.3 Projective Camera Model


3.3.3 The Projection Matrix P - Matlab Example
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042

%% Camera Matrix
% Intrinsic Camera Parameter
f = 2;
% Focal Length
K = diag([f f 1]); % Intrinsic camera Parameter
K(1, 3) = 3;
K(2, 3) = 2;
% Extrinsic Camera Parameter
C = [3; 2; 1];
% Camera Centre
R = [1 0 0
0 0 1
0 1 0];
% We change x and y coordinates
t = -R*C;
% Translation vector with respect to R and C
% Setup Projection matrix
P = K*[R t];
%% Graphical Sketch
figure_01 = figure; hold on; grid on;
plot3(C(1), C(2), C(3), 'm.', 'Markersize', 20);
%% Draw all Planes encoded in P
[X, Y, Z] = meshgrid(
(C(1)-5):0.1:(C(1)+5),...
(C(2)-0):0.1:(C(2)+5),...
(C(3)-5):0.1:(C(3)+5));

0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060

set(p, 'FaceColor', 'red', 'EdgeColor', 'none');


% The Image Plane is the Principal Plane with an offset of f!
plane = P(3, :);
data = plane(1)*X + plane(2)*Y + plane(3)*Z + (plane(4)-f)*1;
p = patch(isosurface(X, Y, Z, data, 0)); hold on;
set(p, 'FaceColor', 'blue', 'EdgeColor', 'none');
alpha(0.5); view(110, 15);
axis([C(1)-5 C(1)+5 C(2)-0 C(2)+5 C(3)-5 C(3)+5]);
% Save Image
print(figure_01, '-r600', '-dtiff',...
'..\Images\16_Example_Projection_Matrix_01.tif');
% Convert document to rtf
highlight('m05_Example_Camera_Matrix.m', 'rtf', ...
'm05_Example_Camera_Matrix.rtf')

P=
2
0
0

3
2
1

0
2
0

-12
-6
-2

% The x-axis Plane is the 1rd row of P!


plane = P(1, :);
data = plane(1)*X + plane(2)*Y + plane(3)*Z + plane(4)*1;
p = patch(isosurface(X, Y, Z, data, 0)); hold on;
set(p, 'FaceColor', 'yellow', 'EdgeColor', 'none');
% The y-axis Plane is the 2rd row of P!
plane = P(2, :);
data = plane(1)*X + plane(2)*Y + plane(3)*Z + plane(4)*1;
p = patch(isosurface(X, Y, Z, data, 0)); hold on;
set(p, 'FaceColor', 'green', 'EdgeColor', 'none');
% The Principal Plane is the 3rd row of P!
plane = P(3, :);
data = plane(1)*X + plane(2)*Y + plane(3)*Z + plane(4)*1;
p = patch(isosurface(X, Y, Z, data, 0)); hold on;

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-33

3.3 Projective Camera Model


3.3.4 The Projection Matrix P - Example Basler acA640-100gc

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-34

3.3 Projective Camera Model


3.3.4 The Projection Matrix P - Example Basler acA640-100gc
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022

%% Example Projection Matrix (Computed)

P (computed)

fx = 4.5e-3;
fy = 4.5e-3;
mx = 1/6.5e-6;
my = 1/6.5e-6;
x0 = 640/2;
y0 = 480/2;
ax = fx*mx;
ay = fy*my;
s = 0;

692,3076923076
0
0
692,3076923076
0
0
1

K = [

ax
0
0

s
ay
0

%
%
%
%

Focal
Focal
no of
no of

Length
Length
pixels
pixels

4.5mm
4.5mm
per mm
per mm

320
240
0

0
0

% skew factor
x0;
y0;
1 ];

C = [0; 0; 0];
R = eye(3);
t = -R*C;
P = K*[R t];
disp(P);

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

P (estimated by calibration procedure)


8.275244814e+02
0
0
0
8.2706873781e+02
0
0
0
1

3.2435919943e+02

2.4445479377e+02
0

Computer Vision
Version vom 11.05.2015

1-35

Literature

[1] Richard Hartley, Andrew Zisserman. Multiple View Geometry in


computer vision. Cambridge university press, 2003

Professur Digital- und Schaltungstechnik


Prof. Dr.-Ing. Gangolf Hirtz

Computer Vision
Version vom 11.05.2015

1-55

También podría gustarte