Computer Vision - 3D Transformations

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

Computer vision

3D Transformations

Le Thanh Ha, Ph.D


Assoc. Prof. at University of Engineering and Technology,
Vietnam National University
ltha@vnu.edu.vn; lthavnu@gmail.com; 0983 692 592
Coordinate Frames
Y0

X0

2/23/2023
Coordinate Frames
• Interested in Some Point described by a Vector R
• We need to express R which we know in Frame 1 in Frame 0

x1 = R  sin( )
y1 = R  cos( ) Y0

x0 = x1  cos(1 ) − y1  sin(1 ) R

y0 = x1  sin(1 ) + y1  cos(1 ) 

Equation is independent of values


−1
X0

2/23/2023
Coordinate Frames
• Now lets put it in matrix form
x0 = x1  cos(1 ) − y1  sin(1 )
y0 = x1  sin(1 ) + y1  cos(1 )

 x0  cos(1 ) − sin(1 )  x1 
 y  =  sin( ) cos( )    y 
 0  1 1   1

 x0   x1 
 y  = T   y 
 0  1

• So what if we want to map the other way?


 x1  −1  x0 
 y  = T    y 
 1  0

• What is the inverse of T? Why?

2/23/2023
Coordinate Frames
• If we look at the columns and rows of T we see that they have a norm of
one.
• Also if we take the dot product of the columns we find they are orthogonal
to each other.
• So T is an ortho-normal Matrices. Thus its transpose is its inverse.
cos(1 ) − sin(1 )  cos(1 ) sin(1 ) 
T  =   T 
−1
= 
 sin(1 ) cos(1 )  − sin(1 ) cos(1 )

• This was a simple 2DOF example what about 3.


• If we project a Z axes out the plane generated by the X and Y axes, then a
rotation around the Z axes will not affect the Z position of the vector R.

2/23/2023
Coordinate Frames
• The 3D transformation axes about the Z axes is:
cos( ) − sin( ) 0
T z =  sin( ) cos( ) 0
 0 0 1

• Similarly for rotations around the X or Y axes we get


1 0 0   cos( ) 0 sin(  ) 
T x = 0 cos( ) − sin( ) T Y =  0 1 0 
0 sin( ) cos( )  − sin(  ) 0 cos( )

• Shorthand notation is often used


cos(x)=c x sin(x)=s x

2/23/2023
Coordinate Transformations
• For multiple transformation we simply multiply by more matrices.
• If we have multiple rotations about the same axes we can just add the angles of the matrices. Does this make sense.

cos( 𝜑) − sin( 𝜑) 0 cos( 𝛾) − sin( 𝛾) 0


𝑇(𝛾 + 𝜑) 𝑧 = sin( 𝜑) cos( 𝜑) 0 ⋅ sin( 𝛾) cos( 𝛾) 0
0 0 1 0 0 1

cos( 𝜑) ⋅ cos( 𝛾) − sin( 𝜑) ⋅ sin( 𝛾) − cos( 𝜑) ⋅ sin( 𝛾) − sin( 𝜑) ⋅ cos( 𝛾) 0


= sin( 𝜑) ⋅ cos( 𝛾) + cos( 𝜑) ⋅ sin( 𝛾) − sin( 𝜑) ⋅ sin( 𝛾) + cos( 𝜑) ⋅ cos( 𝛾) 0
0 0 1

sin( 𝜑 + 𝛾) = sin( 𝜑) cos( 𝛾) + cos( 𝜑) sin( 𝛾)


cos( 𝜑 + 𝛾) = cos( 𝜑) cos( 𝛾) − sin( 𝜑) sin( 𝛾)

cos( 𝜑 + 𝛾) − sin( 𝜑 + 𝛾) 0 Substituting we get


𝑇(𝛾 + 𝜑) 𝑧 = sin( 𝜑 + 𝛾) cos( 𝜑 + 𝛾) 0
0 0 1

2/23/2023
Coordinate Transformation
• So now we can express a vector in a reference frame rotated to
an arbitrary angle in space.
• What if we want to express it in a translated frame

2/23/2023
Translating Coordinate Frames
Y1

Y0

X1

X0

2/23/2023
Translating Coordinate Frames
• Now we can translate and rotate. Y0
Y1

x0 = x1 + x R

y0 = y1 + y
X1

• Or in terms of vectors X0

R0 = R1 + R

2/23/2023
What if we have a rotation and a translation
• First we can rotate the frames
Y0’
• then we can translate R


Y0

 x0   x1  x 
 y  = T   y  + y  
 0  1   1 X0’

X0

2/23/2023
Homogeneous Transformation Matrices
C1 − S1 0
• 3x3 Rotation Matrix T1 =  S1 C1 0
 0 0 1

• 3x1 Displacement Vector


 x1 
R1 =  y1 
 z1 

• For a displacement and a rotation


R0  = T  R1 + R
2/23/2023
4x4 Homogeneous Matrix

• If we want to perform a rotation and a translation with one


operation
 x0   x1  x  C1 − S1 0
 y  = T   y  + y  T =  S1 C1 0
 0  1  
 z 0   z1   z   0 0 1

• We can create a homogeneous Transformation Matrix


C1 − S1 0 x0   x0   x1 
 S1 C1 0 y0  y  y 
TH =    = TH   1 
0
0 0 1 z0  z0   z1 
     
0 0 0 1   
0 0
2/23/2023
Homogeneous Transformation Matrices
1 0 0 x
0 0 y 
• What does a pure translation look like TT = 
1
0 0 1 z
 
0 0 0 1

C1 − S1 0 0
• What does a pure rotation look like  S1 C1 0 0
TR = 
0 0 1 0
 
0 0 0 1

• Multiply to move from one coordinate to another.

2/23/2023
Notation

• Coordinate systems are represented with brackets


{B}, {0}, etc.
• Vectors
Frame of Reference
– Lets Look at a Vector P
Described in Frame A  px 
A
P =  p y 
– Leading Subscript describes the frame  p z 
in which the Vector is described or
Referenced
– Individual Elements of a vector
are described by a trailing subscript

2/23/2023
Matrix Notation

New Frame of Reference

A
A T
B R B

Original Frame of Reference

2/23/2023
Homogenous Transformations Represent 3 Things
• Describe a Frame
• Map from one Frame to another
• Act as an Operator to move within a Frame

A
B T

2/23/2023
Transforms Describe Frames
C1 − S1 0 A
PBorgX 
 
S1 A
• Frames can be described by
A Homogenous Transformation
A
BT =  C1
 0 B0
R 0
1
A

A
PBorgY 
PBorgZ 
 
Matrices  0 0 0 1 

• Description of Frame
– Columns of BA R are the Unit Vectors defining the directions of the principle axes of {B}
in terms of {A}  B Xˆ A 
A
B R=  Xˆ
A
B YˆB
A A ˆ
 
Z B =  BYˆA 

 B Zˆ 
 A
A
– Rows of R are the Unit Vectors defining the directions of the principle axes of {A} in
B
terms of {B}
– A PBorg is the location of the origin of {B} in terms or {A}

2/23/2023
Mapping Between Frames
• Maps vector from Frame {B} to Frame {A}
C1 − S1 0 A
PBorgX 
• A
will rotate a vector to project its
R 
S1 A

B
components originally described in
A
BT =  C1
 0 B0
R 0
1
A

A
PBorgY 
PBorgZ 
 
{B} in the {A} of Frame  0 0 0 1 

• A
will translate the vector to adjust its origin from frame {B} to
PBorg
its new origin in {A}
B A
P P
2/23/2023
Acts as an Operator within a coordinate frame
• Operator will rotate and translate a vector

• R Defines the angle to rotate about

• PBorg Defines the distance to translate


C1 − S1 0 P2orgX 
 
• Usually drop subscripts T =
0
S1 C1
0
R 0
1
P2orgY 
P2 orgZ 
 
 0 0 0 1 
• T Operates on A
P1 to create A P2

2/23/2023
Bài tập
• Ký hiệu hệ tọa độ 3 chiều của căn phòng là N
• Ký hiệu hệ tọa độ 3 chiều của 01 camera gắn trong phòng là C
• Tọa độ của camera C trong căn phòng là (3, 5, 10) mét
• Góc xoay của camera C so với căn phòng theo từng trục x, y, z
là (20, 45, 210) độ
• Hãy thiết lập ma trận chuyển đổi (homogenerous matrix) 𝑵𝑪𝑻
để chuyển đổi tọa độ của một đối tượng trong camera sang
hệ tọa độ của căn phòng.
2/23/2023

You might also like