You are on page 1of 54

Spatial descriptions and

transformations
^
YA
YˆB P
tY  X̂ B
A
PBORG

O
tX X̂ A
Position Description
Once a coordinate system is established, we can locate any
point in the space with a 3 x 1 position vector.

Ẑ A
 PX 
A
P
A
P   PY 
 PZ 

YˆA
X̂ A
Coordinate System A
1-3
Orientation Description
Attach Frame B
• To describe the orientation of a
(Coordinate System
Ẑ B body in space, we will attach a
B)
Ẑ A coordinate system (frame B) to
the body and then give a
description of this coordinate
X̂ B A
P YˆB
system relative to the reference
o YˆA system (frame A).
At least three independent values (angles) are
Coordinate System A needed to describe the orientation of frame B
with respect to frame A.
X̂ A

The orientation of a rigid body


is represented with a rotation
A
matrix B R
1-4
Description of a frame
A frame is a coordinate system where, in addition to the
orientation and a position vector which locates its origin
relative to some other embedding frame.

Ẑ B
• The description of a frame can Ẑ A
be thought of as a position
vector and a rotation matrix. X̂ B
A
PBORG YˆB
Position + orientation

{B}  { R, PBORG }
A
B
A
YˆA

X̂ A 1-5
2D Rotation matrix Rotation around the Z-Axis
^
YA
Given: The location of point
YˆB
B
A
PY P P in coordinate frame B: B PX PY

X̂ B A A
B Determine: PX PY
PX

B
PY 
O A
PX X̂ A
A
PX  OP cos(   )  OP  cos  cos   sin  sin    B PX cos   B PY sin 
A
PY  OP sin(   )  OP sin  cos   sin  cos    B PX sin   B PY cos 
 A
PX  cos   sin  0   B PX 
 PX  cos   sin    PX  A
A B
A    
A    B  ; P   PY    sin  cos  0   B PY   BA R B P
 PY   sin  cos    PY   0   0 0 1   0 
 
1-6
^
2D Rotation matrix Rotation around the Z-Axis

YA
One way to describe the rotation
YˆB P
A
PY matrix, BA R
X̂ B , is to write the unit vectors of
B
PX frame {B} in terms of the

B
PY  coordinate frame {A}.
O A
PX X̂ A
  
 OP cos(   )    ^   B ^ ^ ^
 B ^ ^ ^ ^

 PX 
A
OP  X ( P X  B
P Y )  X P X  X  B
P Y  X
A    A
  X B Y B A
  X B A Y B A

 PY   OP sin(   )   OP Y   ( B P X  B P Y )  Y   B P X  Y  B P Y  Y 
 ^ ^ ^ ^ ^ ^ ^ ^

   A   X B Y B A   X B A Y B A 
 
 ^ ^ ^ ^
 B
X  X Y  X  P   ^
  B PX   cos   sin    B PX 
^
 ^ ^
B A B A  X
 XA
YB   B   
A
B 
 ^ ^   B P   B   PY  sin   cos    PY 
 X B  YA YB  YA 

1-7
3D-Rotation matrix
Orientation Description
Hence, each component of a matrix
rotation can be written as the dot product
of a pair of unit vectors: Ẑ A
A Ẑ B
P
A
B R   A Xˆ B YˆB
A A
Zˆ B 
X̂ B
 r11 r12 r13  YˆB
r31  Xˆ B  Zˆ A
  r21 r22 r23  r21  Xˆ B  YˆA
 r31 r32 r33  YˆA
r11  Xˆ B  Xˆ A
 Xˆ B  Xˆ A YˆB  Xˆ A Zˆ B  Xˆ A  X̂
  A
A
R   Xˆ  Yˆ Yˆ  Yˆ Zˆ B  YˆA 
B B A B A
 ˆ ˆ ˆ ˆ ˆ ˆ 
 X B  Z A YB  Z A Z B  Z A 
1-8
3D-Rotation matrix
Directional Cosines

A
B R   A Xˆ B A
YˆB A
Zˆ B  Directional Cosines

 Xˆ B  Xˆ A YˆB  Xˆ A Zˆ B  Xˆ A 
B T
X̂ A
 
ˆ ˆ YˆB  YˆA Zˆ B  YˆA 
B R   X B  YA
A

 ˆ ˆ ˆ  Zˆ ˆ ˆ 
 B A
X  Z Y B A Z B  Z A 

 B Xˆ AT 
B T B T
A
R   Yˆ    Xˆ B
YˆA B ˆ 
ZA   AR
B T
B A  A
Bˆ T
 Z A 
1-9
Rotation matrix
 r11 r12 r13 
A
R  BA R T r r22 r23   r1 r2 r3 
B A
B R   21
A
B R BA R  I  A
B R  BA R 1  r31 r32 r33 
r1  r2  r3  1
B
A RT  B
A R 1
r1  r2  r1  r3  r2  r3  0

• For matrix M,
A
B R 1

– If M-1 = MT , M is orthogonal matrix


A
– B R is orthogonal!!!

In linear algebra, an orthogonal matrix is a square matrix whose


columns and rows are orthogonal unit vectors

1-10
Basic Rotation matrix
Rotation around the X-Axis by an angle 
1 0 0  These basic rotation matrices
 
cos -sin 
clearly satisfy the properties:
B R X ,  0
A

B R K ,0  I 3 ;
A

0 sin cos  A A


B R K , B R K ,  B R K ,(  ) ;
A

Rotation around the Y-Axis by an angle  [ BA R K , ]1  BA R K ,


 cos 0 sin 
A
B R Y ,   0 1 0 
 -sinq 0 cos 
Rotation around the Z-Axis by an angle 
 cos -sin 0 
A
R   sin cos 0 
B Z ,  
 0 0 1  1-11
2D - Translations
PBORG  t X 0
A T
tY A
P  A PBORG  B P
^  A PX  t X   B PX 
YA YˆB P A    B 
A
P   PY    tY    PY 
tY A
PBORG O’  0   0   0 
   
X̂ B  A PX   B PX  t X 
A  B 
A
P   PY    PY  tY 
 0   0 
   
O
tX X̂ A

1-12
Combine Rotation and Translation
^
YA YˆB P

tY A
PBORG
 X̂ B
PBORG  t X 0
A T
tY

O
tX X̂ A
A
P  R Z , P  PBORG
A
B
B A

 A PX  cos   sin  0   B PX  t X 
A    B   
A
P   PY    sin  cos  0   PY    tY 
 0   0 0 1   0   0 
 
1-13
Combine Rotation and Translation
^
It consists 2 operations, a multiplication and a addition
P  BA R Z , B P  A PBORG
YA A
YˆB P
tY  X̂ B
cos   sin  0   B PX  t X 
 
P   sin  0   B PY    tY 
A
PBORG
A
cos 
O
 0 0 1   0   0 
tX X̂ A

Homogeneous Transformation for Mapping

 A PX  cos   sin  0 t X   B PX 
A    B 
 PY   sin  cos  0 tY   PY  A B
A
P   BT P
 0   0 0 1 0  0 
    
Homogeneous coordinates are a way
of representing N-dimensional
coordinates with N+1 numbers. To

 1   0 0 0 1   1  make 2D Homogeneous coordinates,


we simply add an additional variable,
w, into existing coordinates. Therefore,
a point in Cartesian coordinates, (X, Y)
becomes (x, y, w) in Homogeneous 1-14
coordinates.
Homogeneous Transformation
Ẑ B B
Ẑ A P
A
P
A
P  A PBORG  BA R B P
YˆB
X̂ B
A
P  ABT B P
YˆA

X̂ A  A Px   A
PBORG _ x   B Px 
A   A A B 
 Py    B R PBORG _ y   Py 
 A Pz   A
PBORG _ z   B Pz 
    
 1  0 0 0 1   1 
A
B T 1-15
Example
This figure shows a frame {B},
which is rotated relative to
frame {A} about axis XA by 90
degrees, translated 3 units in
YA, and translated 1 units in ZA
Find AP, where BP = [0 1 1]T

1 0 00  0   0 
 BA R 0 0 1 3  1   2 
A
PBorg  B
P T P  P   
A A B

1 0 1  1   2 
B
 0 1  0
    
0 0 0 1  1   1 

1-16
Inverse Transform
• Given a homogeneous
transformation A
B T
• Compute the inverse
transformation: B
AT

 A
R A
PBorg 
B
A R  BA R T  BA R 1
T
A
B
B
 B
( A PBorg )  BA R A PBorg  B PAorg  0
0 0 0 1 
B
PAorg   BA R T A PBorg
 1
B
R B
PAorg 
T T 
B
A
A
B
A

0 0 0 1 

 A
R T
 R  PBorg 
A T A

AT  
B B B

0 0 0 1 
1-17
Inverse Transform

 A
R A
PBorg   A
RT  BA R T A PBorg 
BT AT   
A B B B

0 0 0 1  0 0 0 1 
 A
R A T
R  A
R A T A
R P  A
PBorg   I 0
 B B B B Borg
 
0 0 0 1   0 0 0 1 

1-18
MORE ON REPRESENTATION OF ORIENTATION

Euler's rotation theorem


In geometry, Euler's rotation theorem states that, in three-
dimensional space, any displacement of a rigid body such
that a point on the rigid body remains fixed, is
equivalent to a single rotation about some axis that
runs through the fixed point. It also means that the
composition of two rotations is also a rotation.
1-19
MORE ON REPRESENTATION OF ORIENTATION

Four different ways to represent rotation

1. Fixed angles
2. Euler angles
3. Axis angle
4. Quaternions

1-20
MORE ON REPRESENTATION OF ORIENTATION

The 24 angIe-set conventions

The 12 fixed angle sets are given by The 12 Euler angle sets are given by
1  R XYZ ( ,  ,  ) 1  R X 'Y ' Z ' ( ,  ,  )
2  R XZY ( ,  ,  ) 2  R X ' Z 'Y ' ( ,  ,  )
3  R YXZ ( ,  ,  ) 3  R Y ' X ' Z ' ( ,  ,  )
4  R YZX ( ,  ,  ) 4  R Y ' Z ' X ' ( ,  ,  )
5  R ZXY ( ,  ,  ) 5  R Z ' X 'Y ' ( ,  ,  )
6  R ZYX ( ,  ,  ) 6  R Z 'Y ' X ' ( ,  ,  )
7  R XYX ( ,  ,  ) 7  R X 'Y ' X ' ( ,  ,  )
8  R XZX ( ,  ,  ) 8  R X ' Z ' X ' ( ,  ,  )
9  R YXY ( ,  ,  ) 9  R Y ' X 'Y ' ( ,  ,  )
10  R YZY ( ,  ,  ) 10  R Y ' Z 'Y ' ( ,  ,  )
11  R ZXZ ( ,  ,  ) 11  R Z ' X ' Z ' ( ,  ,  )
12  R Z 'Y ' Z ' ( ,  ,  ) 12  R Z 'Y ' Z ' ( ,  ,  )
1-21
MORE ON REPRESENTATION OF ORIENTATION

3-Equivalent angle-axis representation


R K ( )
Consider the following description of a frame {B}:
Start with the frame coincident with a known
^
frame
{A}; then rotate {B} about the vector A Kby an angle
 according to the right-hand rule.

 k x   kx  The sign of  is determined by the

X r   k y  ; K   k y 
^
A right-hand rule, with the thumb
pointing along the positive sense of
^
 k z   k z  A
K
 k x k x v  c k x k y v  k z s k x k z v  k y s 
 
R K ( )   k x k y v  k z s k y k y v  c k y k z v  k x s 
 k x k z v  k y s k y k z v  k x s k z k z v  c 

with v  (1  cos  ); c  cos  ; s   sin  ;
Note that: R ^ ( )  R ^ ( ) 1-22
K K
MORE ON REPRESENTATION OF ORIENTATION
angle-axis representation  r11 r12 r13 
r r23 
^
Inverse Problem Given:
A
B R   21 r22 Find: (K ,  )
 r31 r32 r31 

 k x k x v  c k x k y v  k z s k x k z v  k y s 
  ^ T
R K ( )   k x k y v  k z s k y k y v  c k y k z v  k x s  ; v  (1  cos  ); K  k x ky k z 
 k x k z v  k y s k y k z v  k x s k z k z v  c 

r11  r22  r33  (k x2 (1  c )  c )  (k y2 (1  c )  c )  (k z2 (1  c )  c )
 k x2  k y2  k z2  (k x2  k y2  k z2 )c  3c  1  2c Note that:
r11  r22  r33  1 r  r  r 1 r11  r22  r33  1
c     acos ( 11 22 33 ) 1  acos (
2
)
2 2 r  r  r 1
If s  0  2  2  acos ( 11 22 33 )
2

r32  r23  k y k z v  k x s  (k y k z v  k x s )  2k x s kx   r32  r23 



 K   k y  
^ 1  
 r13  r31  k x k z v  k y s  (k x k z v  k y s )  2k y s r  r
2 s  
13 31
 r  r  k k v  k s  (k k v  k s )  2k s  k z   r21  r12 
 21 12 x y z x y z z
1-23
This solution always computes a value of  between 0 and 180 degrees
MORE ON REPRESENTATION OF ORIENTATION
4-Euler parameters (unit quaternion)
^
With the equivalent axis K   k x k y k z T
 
And the equivalent angle , the Euler parameters are
given by    
1  k x sin ,  2  k y sin ,  3  k z sin ,  4  cos
2 2 2 2
12   22   32   42  1 The Euler parameters are known as a unit
quaternion.

The rotation matrix R  that is equivalent to a set of Euler


parameters is
 1  2 22  2 32 2(1 2   3 4 ) 2(1 3   2 4 ) 
 
R    2(1 2   3 4 ) 1  21  2 3 2( 2 3  1 4 ) 
2 2

 2(1 3   2 4 ) 2( 2 3  1 4 ) 1  212  2 22 


 
1-24
~
Oc

~
??? O c ???
 m1T Pi   Pix 
 T   m11 m12 m13 m14   m
 
T


 
 ui   m3 Pi   1
P 
M   m21 m22 m24    m  Pi   iy 
pi    
T
m23 2

 i
v  m T
2 Pi
 m
 31 m32 m33 m34   m
T 

P
 iz 
 T 
3
1
 m3 Pi 
 m1T Pi 
 T 
 ui   m3 Pi 
pi    
 i
v  m T
2 Pi

 T 
 m3 Pi 

m1T Pi
ui  T  ui ( mT3 Pi )  m1T Pi  0
m3 Pi

mT2 Pi
vi  T  vi ( mT3 Pi )  mT2 Pi  0
m3 Pi
m1T Pi
ui  T  ui ( mT3 Pi )  m1T Pi  0
m3 Pi

mT2 Pi
vi  T  vi ( mT3 Pi )  mT2 Pi  0
m3 Pi

 u1 ( mT3 P1 )  m1T P1  0

v (
 1 3 1mT
P )  m 2 P1  0
T

 ...

 i 3 i
u ( m T
P )  m1 Pi  0
T


v (
 i 3 im T
P )  mT
2 Pi  0
 ...

 n 3 n
u ( m T
P )  m 1 Pn  0
T

 v ( mT P )  mT P  0
 n 3 n 2 n
 P1T  u1P1T 
(1 x 4 )
0T
 T 
0 P1T  v1P1 
T

P   ... ... ... 


 u1 ( m P )  m P  0
T T
 m P  u1 ( m P )  0
T T  

3 1 1 1

1 1 3 1
 PnT 0T  un Pn 
T

v
 1 ( T
m P ) T
m P  0  m P  v1 ( m P )  0
T T
 T 
3 1 2 1 2 1 3 1
0 PnT  vn PnT  2 n12
 ...  ...
  T
 i 3 i
u ( m T
P )  m T
P  0  m P  u ( m 3 Pi )  0
T


1 i
 T 1 i i
 Pm  0
 m1 
( 4 1 )
 vi ( m3 Pi )  m2 Pi  0  m2 Pi  vi ( m3 Pi )  0
T T T

   

...

...
m   m2 
un ( m3 Pn )  m1 Pn  0 m1 Pn  un ( m3 Pn )  0
T T T T

 v ( mT P )  mT P  0  mT P  v ( mT P )  0 m 
 n 3 n 2 n  2 n n 3 n  3 121
^
M   [ A b ]  M  K [ R T ]

-
^
M   [ A b ]  M  K [ R T ]
^
M   [ A b ]  M  K [ R T ]

r3  a 3
Computer Vision Toolbox™, User's Guide

What Is Camera Calibration?


• Geometric camera calibration estimates the
parameters of a lens and image sensor of an image or
video camera.
• You can use these parameters to correct for lens
distortion, measure the size of an object in world units,
or determine the location of the camera in the
scene.
• These tasks are used in applications such as machine
vision to detect and measure objects.
They are also used in robotics, for navigation systems,
and 3-D scene reconstruction.
Examples of what you can do after
calibrating your camera
Pinhole Camera Model
• The pinhole camera parameters are
represented in a 4-by-3 matrix called the
camera matrix.
Camera Calibration Parameters

Extrinsic Parameters
Intrinsic Parameters
The pixel skew
The intrinsic matrix, K.

[cx cy]— Optical center (the principal point), in pixels.


(fx , fy)— Focal length in pixels.
fx= F/px
fy= F/py
F— Focal length in world units, typically expressed in millimeters.
(px, py) — Size of the pixel in world units.
s— Skew coefficient, which is non-zero if the image axes are not
perpendicular.
s = fxtanα
Distortion in Camera Calibration
• The camera matrix does not account for lens
distortion because an ideal pinhole camera
does not have a lens. To accurately represent a
real camera, the camera model includes the
radial and tangential lens distortion.
Radial Distortion
• Radial distortion occurs when light rays bend
more near the edges of a lens than they do at
its optical center. The smaller the lens, the
greater the distortion.
Radial Distortion
• The radial distortion coefficients model this type of distortion.
The distorted points are denoted as (xdistorted, ydistorted):
xdistorted = x(1 + k1*r2 + k2*r4 + k3*r6)
ydistorted= y(1 + k1*r2 + k2*r4 + k3*r6)
• x, y — Undistorted pixel locations. x and y are in normalized
image coordinates. Normalized image coordinates are calculated
from pixel coordinates by translating to the optical center and
dividing by the focal length in pixels. Thus, x and y are
dimensionless.
• k1, k2, and k3 — Radial distortion coefficients of the lens.
• r2: x2 + y2
Typically, two coefficients are sufficient for calibration. For severe
distortion, such as in wide-angle lenses, you can select 3
coefficients to include k3.
Tangential Distortion
• Tangential distortion occurs when the lens and
the image plane are not parallel. The
tangential distortion coefficients model this
type of distortion.
Tangential Distortion
• The distorted points are denoted as (xdistorted, ydistorted):
xdistorted = x + [2 * p1 * x * y + p2 * (r2 + 2 * x2)]
ydistorted = y + [p1 * (r2 + 2 *y2) + 2 * p2 * x * y]
• x, y — Undistorted pixel locations. x and y are in
normalized image coordinates. Normalized image
coordinates are calculated from pixel coordinates by
translating to the optical center and dividing
by the focal length in pixels. Thus, x and y are
dimensionless.
• p1 and p2 — Tangential distortion coefficients of the
lens.
• r2: x2 + y2
Single Camera Calibrator App

Follow this workflow to calibrate your camera using the app:


1. Prepare images, camera, and calibration pattern.
2. Add images and select standard or fisheye camera model.
3. Calibrate the camera.
4. Evaluate calibration accuracy.
5. Adjust parameters to improve accuracy (if necessary).
6. Export the parameters object.

You might also like