Computer Vision (Cs708) : Lecture02 - Image Formation and Opencv
Computer Vision (Cs708) : Lecture02 - Image Formation and Opencv
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 1 / 54
Contents
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 2 / 54
Contents
2 Image formation
Pinhole camera
3 Projective geometry
2D geometry
Homogeneous coordinates
3D projection
Vanishing points and lines
4 OpenCV Installation
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 3 / 54
Computer vision overview
Overview of vision, examples of the state of the art, preview of
projects
2 Image formation
Pinhole camera
3 Projective geometry
2D geometry
Homogeneous coordinates
3D projection
Vanishing points and lines
4 OpenCV Installation
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 8 / 54
A camera
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 9 / 54
Image formation
This lecture
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 10 / 54
Image formation
Camera and world geometry
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 11 / 54
Camera and world geometry
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 12 / 54
Image formation
Let’s design a camera
Idea 1: put a piece of film in front of an object
Do we get a reasonable image?
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 13 / 54
Image formation
Idea 2: add a barrier to block off most of the rays
This reduce blurring
The opening known as the aperture
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 14 / 54
Contents
2 Image formation
Pinhole camera
3 Projective geometry
2D geometry
Homogeneous coordinates
3D projection
Vanishing points and lines
4 OpenCV Installation
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 14 / 54
Image formation
Pinhole camera
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 16 / 54
Projective geometry
What is lost?
What is lost?
Length
Which one is closer?
What is lost?
Length
Angles
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 19 / 54
Projective geometry
What is preserved?
What is preserved?
Straight lines are still straight
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 20 / 54
Contents
2 Image formation
Pinhole camera
3 Projective geometry
2D geometry
Homogeneous coordinates
3D projection
Vanishing points and lines
4 OpenCV Installation
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 21 / 54
Contents
2 Image formation
Pinhole camera
3 Projective geometry
2D geometry
Homogeneous coordinates
3D projection
Vanishing points and lines
4 OpenCV Installation
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 21 / 54
2D Modeling Transformation
2D Translation
Figure: 2D translation.
old coordinates are (x, y) and the new coordinates are (x’, y’)
0
x = x + Tx
0
y = y + Ty
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 22 / 54
2D Modeling Transformation
2D Translation
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 23 / 54
2D Modeling Transformation
2D scaling
Scaling alters the size of the object. Sx and Sy are the scaling factors:
0 0
Old coordinates are (x, y ) and the new coordinates are (x , y )
0
x = x ∗ Sx
0
y = y ∗ Sy
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 24 / 54
2D Modeling Transformation
2D scaling
Figure: 2D scaling.
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 25 / 54
2D Modeling Transformation
2D Rotation
Figure: 2D rotation.
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 26 / 54
2D Modeling Transformation
Formula for rotation
0 0
Old coordinates are (x, y ) and the new coordinates are (x , y )
θ = initial angle, α = angle of rotation.
x = r cos θ
y = r sin θ
0
x = r cos(θ + α) = r cos θ cos α − r sin θ sin α
0
y = r sin(θ + α) = r sin θ cos α + r cos θ sin α
hence,
0
x = x cos α − y sin α
0
y = y cos α + x sin α
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 27 / 54
2D Modeling Transformation
Martix representation of transformations
0 0
Scaling: x = x ∗ Sx , y = y ∗ Sy , which can be written as:
T
0 0 x S 0
× x
x y =
y 0 Sy
Rotation:
0
x = x cos α − y sin α
0
y = y cos α + x sin α
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 28 / 54
2D Modeling Transformation
Martix representation of transformations
T
0 0 x S 0
× x
x y =
y 0 Sy
0 T
00 00 x cos α sin α
x y = 0 ×
y − sin α cos α
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 29 / 54
2D Modeling Transformation
Matrix representation of transformations
T
00 00 x Sx 0 cos α sin α
x y = × ×
y 0 Sy − sin α cos α
T
x Sx cos α Sx sin α
= ×
y −Sy sin α Sy cos α
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 30 / 54
2D Transformations
Matrix representation of transformations
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 31 / 54
Contents
2 Image formation
Pinhole camera
3 Projective geometry
2D geometry
Homogeneous coordinates
3D projection
Vanishing points and lines
4 OpenCV Installation
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 31 / 54
2D transformations
Homogeneous coordinates
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 32 / 54
2D transformations
Homogeneous coordinates
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 33 / 54
2D transformations
Homogeneous coordinates
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 34 / 54
Homogeneous coordinates
Projection world to image coordinates
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 36 / 54
Homogeneous coordinates
Scaling
Invariant to scaling
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 37 / 54
Homogeneous coordinates
Projection Matrix
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 38 / 54
Contents
2 Image formation
Pinhole camera
3 Projective geometry
2D geometry
Homogeneous coordinates
3D projection
Vanishing points and lines
4 OpenCV Installation
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 38 / 54
Projection Matrix
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 39 / 54
Projection Matrix
Remove assumption: known optical center
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 40 / 54
Projection Matrix
Remove assumption: square pixels
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 41 / 54
Homogeneous coordinates
Oriented and translated camera
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 42 / 54
Projection Matrix
Allow camera translation
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 43 / 54
Projection Matrix
3D rotation of points
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 44 / 54
Projection Matrix
Allow camera rotation
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 45 / 54
Projection
Degrees of freedom
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 46 / 54
Projection
Field of View (Zoom, focal length)
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 47 / 54
Projection Matrix
Beyond Pinholes: Radial Distortion
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 48 / 54
Contents
2 Image formation
Pinhole camera
3 Projective geometry
2D geometry
Homogeneous coordinates
3D projection
Vanishing points and lines
4 OpenCV Installation
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 48 / 54
Projective geometry
Vanishing points and lines
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 49 / 54
Projective geometry
Vanishing points and lines
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 51 / 54
Things to remember
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 52 / 54
Contents
2 Image formation
Pinhole camera
3 Projective geometry
2D geometry
Homogeneous coordinates
3D projection
Vanishing points and lines
4 OpenCV Installation
Dr. Abdul Basit (CSIT - UoB) Computer Vision September 29, 2016 53 / 54
The End
59 / 59