Tuan 7 Camera Calibration3
Tuan 7 Camera Calibration3
VISION
Perspective model
u=F*X/Z Virtual
v=F*Y/Z Screen
or CCD
World
https://en.wikipedia.org/wiki/Charge-coupled_device center
sensor
Y
v
v
F
Z F Real
Screen
Or
Thin lens
CCD
or a pin hole
sensor
bigger
area
image plane
• Perspective projection
• 3D to 2D
• F=5mm
• Z=1 meter
• A tree is 2 meters high,0.5 meters wide.
What is the size of the tree appears in
the image?
• Sketch the diagram.
• Answer:___________
Ch2.
• F=5mm
• Z=1 meter
• A tree is 2 meters high,0.5 meters wide. What is the
size of the tree appears in the image?
• Answer: using y=F*Yc /Zc
• Tall=y=F*Y/Z=5x10-3x2 meters/1 meter=10mm
• or 5*2*10^-3/1 =10mm
• Wide=x=F*X/Z=5x10-3x0.5 meters/1 meter=0.0025 meter=2.5mm,
• or =5*0.5*10^-3*1 =2.5mm
1 pixel
Sx =5.46um
Image=
1024x768 Sy=5.46um
pixles
Worksheet 2.2
• For an image of 1280x1024 Sx = Sy =5.2um.
• What is the size of the image (CMOS or CCD
sensor)?
• Find the pixel size of your favorite camera.
Image
• Answer:________________ (CMOS
sensor)
Hint:
www.ovt.com
OVT CameraChip
OV9620/9120
webcam camera
chip
Image
www.ovt.com
OVT CameraChip OV9620/9120 (CMOS sensor)
webcam camera chip
• homogeneous → Cartesian
I am trying to choose a camera and lens for my imaging system. How do I make sure that I have the
correct lens focal length, and image sensor resolution? I know the following about the real life situation:
1. Field of view (FOV): Area under inspection that the camera needs to acquire
2. Smallest feature: The size of the smallest feature that I want to detect in the image
3. Working distance (WD): Distance from the front of the lens to the object under inspection
• Example 1: My FOV is 100mm and my smallest feature is 1mm. Following the equation, the
needed minimum sensor resolution is 200 pixel. A camera with a resolution of 640x480 will
work because 200 is less than the smallest dimension which is 480.
Sensor Format:
Sensor format refers to the physical size of the sensor, but is not dependent on the pixel size.
This specification is used to determine what lens the camera is compatible with. In order for
a lens to be compatible with a camera, the format of the lens needs to be greater than or
equal to the sensor format. If a lens with a smaller format is use, the image experiences
vignetting; this causes regions of the sensor outside of the lens format area to be dark.
v (pixels)
768
(Ox,Oy)=
(512,384) in pixels
x
CCD
u (pixels)
1024
44
50
• Write a pseudo code (or matlab) program to calculate the projected point
[u v] T from [Xc,Yc,Zc]T based on the above camera intrinsic
parameters.
%matlab
• sx=sy=5.4um k=[800 0 512
0 8000 384
• (ox,oy)=(512,384) in pixels 0 0 1]
• f=4.3mm/5.4um=800 pixels x=[0.02 0.05 1.2]'
im=k*x
• [Xc,Yc,Zc]T =[0.02,0.05,1.2]Tmeters im(1)/im(3)
s * u X 800 0 512 0.02 im(2)/im(3)
s * v M Y 0 800 384 0.05
int %answer:
s
Z 0 0
1 1.2 im =
630.4000
• [u v]’=?? 860.8000
1.2000
• Answer: [525.3, 717.3]T u,v=
• Write a pseudo code (or matlab) program to calculate the
projected point [u,v]’ from [Xc,Yc,Zc]’ based on the
525.3333
717.3333
above camera intrinsic parameters.
52
Robotic & Vision Lab RoVis
Ch2. Cameras v.9e2
CCD is glued to the back of a camera
W2 begins
CCD CCD
sensor sensor
X=512
v=600
• [u v]T=??
ox,oy=600, 400
• Answer: [u v]T =____________________ (Image center is
shifted to ox,oy)
• Conclusion: A 3D object point can have different
image positions for different cameras (different Mint)
placed at the same position.
X=512
• [u v]T=[613.3, 733.3]T
v=600
• Conclusion: A 3D object point can have ox,oy=600, 400
different image positions for different (Image center is
cameras (different Mint) placed at the shifted to ox,oy)
same position.
Robotic & Vision Lab RoVis
Complete camera model
extrinsic parameters
intrinsic
parameters
camera matrix
Robotic & Vision Lab RoVis
® © Peter Corke
a university for the
real world
CRICOS No. 00213J
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
® © Peter Corke
a university for the
real world
CRICOS No. 00213J
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Tutorial 2.2
Given
X,Y,Z are in 3D
• Focal length is 3mm, sx=sy=3um
u,v are in 2D
• (ox,oy)=(620,410) in pixels
Y
• A 3D point is at X=0.015 meters, Y=0.02 meters and Z=2 v
meters away from the camera center.
• Fill in the blanks (__?) Z
X=512
• [u v]T=?? v=620
ox,oy=620, 410
• Answer: [u v]T =____________________? (Image center is
shifted to ox,oy)
Ch2. Cameras v.9e2 64
%matlab
m=[1000 0 620; 0
Answer: 1000 410; 0 0 1]
p=[0.015 0.02 2]'
Tutorial 2.2 x=m*p
Given u=x(1)/x(3)
v=x(2)/x(3)
Answer : X,Y,Z are in 3D
• Focal length is 3mm, sx=sy=3um u =627.5,v = 420 u,v are in 2D
• (ox,oy)=(620,410) in pixels Y
• A 3D point is at X=0.015 meters, Y=0.02 meters v
high and Z=2 meters away from the camera center. Z
• Fill in the blanks (__?)
s * u X __ 1000 __?
0 _ 620 ___? _ 0.015 ___?
u=410
s * v M Y _ 0.02 ___?
int 0 _ 1000 ___? _ 410 ___? Y=384 X
s Z 0 0 1 2
(1,1)
X=512
• [u v]T=?? v=620
ox,oy=620, 410
• Answer: [u v]T =___627.5, 420_________________? (Image center is
shifted to ox,oy)
Ch2. Cameras v.9e2 65
Tutorial 2.9
• Suppose that the intrinsic parameters of our
𝑓 𝑜𝑥
camera can be represented by 𝑀𝑖𝑛𝑡 = 𝑓 𝑜𝑦
1
• The camera coordinate center is the same as the
world center, hence Mext =[ I | 0]
1 0 0 0
• There are two points P1, P2 in the world
M ext 0 1 0 0
coordinates
0 0 1 0
𝑇
• P1 = 0.1, 0.2, 1 meters , its image is at 𝐼1 =
1000, 2000 𝑇
• 𝑃2 = 0.3, 0.4, 1 𝑇 meters, its image is at 𝐼2 =
3000, 2200 𝑇 respectively.
• Compute the matrix 𝑀𝑖𝑛𝑡 . (hints : image 𝐼𝑖 = 𝑀𝑖𝑛𝑡 ∗
𝑀𝑒𝑥𝑡 ∗ 𝑃𝑖)
• 1 0 0 0
M ext 0 1 0 0
0 0 1 0
0.1
s1*1000 f ox 1 0 0 0 f ox 0.1
s * 2000 0 .2
1 f o y 0 1 0 0 f o y 0.2 and
1
s1 1 0 0 1 0 1 1
1
s2* 3000 f ox 0.3
s *x f o y 0.4
2
s2 1 1
From the last row of each matrix equation : s1 1, s2 1
1000 f* 0.1 ox , hence ox 1000 f* 0.1 (i)
3000 f*( 0.3 ) ox ----(ii)
put (i) in (ii)
3000 f*( 0.3 ) 1000 f* 0.1
2000 f * 0.2, f 1000
Put back to (i) , ox 1000 1000* 0.1 900
Since
2000 f* 0.2 o y , so o y 2000 1000 * 0.2 1800
1000 900
M int
1000 1800
1
x KR t X
X
su * * * * Y
sv * * * *
Z
s * * * *
1
X
su m11 m12 m13 m14 Y Known 3d
Known 2d sv m
image coords 21 m22 m23 m24
Z locations
s m31 m32 m33 m34
1
First, work out su m11 X m12Y m13 Z m14
where X,Y,Z
projects to under sv m21 X m22Y m23 Z m24
candidate M.
s m31 X m32Y m33 Z m34
X
su m11 m12 m13 m14
Known 2d sv m Y Known 3d
m m m
image coords 21 22 23 24 Z locations
s m31 m32 m33 m34
1
Next, rearrange into form
m11 X m12Y m13 Z m14
where all M coefficients are u
individually stated in terms of m31 X m32Y m33 Z m34
X,Y,Z,u,v.
-> Allows us to form lsq m21 X m22Y m23 Z m24
matrix. v
m31 X m32Y m33 Z m34
( m31 X m32Y m33 Z m34 )u m11 X m12Y m13 Z m14
( m31 X m32Y m33 Z m34 )v m21 X m22Y m23 Z m24
m31uX m32uY m33uZ m34u m11 X m12Y m13 Z m14
m31vX m32 vY m33vZ m34 v m21 X m22Y m23 Z m24
Robotic & Vision Lab RoVis
Unknown Camera Parameters
X
su m11 m12 m13 m14 Y Known 3d
Known 2d sv m
image coords 21 m22 m23 m24
Z locations
s m31 m32 m33 m34
1
Next, rearrange into form
where all M coefficients are
individually stated in terms of
X,Y,Z,u,v.
-> Allows us to form lsq
matrix.
m31uX m32uY m33uZ m34u m11 X m12Y m13 Z m14
m31vX m32 vY m33vZ m34 v m21 X m22Y m23 Z m24
X
su m11 m12 m13 m14 Y
Known 2d sv m m22 m23 m24 Known 3d
image coords 21 Z locations
s m31 m32 m33 m34
1
• Finally, solve for m’s entries using linear least squares
• Method 1 – Ax=b form
m11
m
12
m13
X 1 Y1 Z1 1 0 0 0 0 u1 X 1 u1Y1 u1Z1 m14 u1
0 0 0 0 X1 Y1 Z1 1 v1 X 1 v1Y1 v1Z1 m21 v1 M = A\Y;
m22 M = [M;1];
X n Yn Zn 1 0 0 0 0 un X n unYn un Z n m23 un M = reshape(M,[],3)';
0 0 0 0 X n Yn Zn 1 vn X n vnYn vn Z n m24 vn
m
31
m32
m
33
X
su m11 m12 m13 m14 Y
Known 2d sv m m22 m23 m24 Known 3d
image coords 21 Z locations
s m31 m32 m33 m34
1
• Or, solve for m’s entries using total linear least-squares.
• Method 2 – Ax=0 form m
11
m12
m13
m14
X 1 Y1 Z1 1 0 0 0 0 u1 X 1 u1Y1 u1Z1 u1 0
0 0 m21
0 0 X1 Y1 Z1 1 v1 X 1 v1Y1 v1Z1 v1 0 [U, S, V] = svd(A);
m22
M = V(:,end);
m23
X n Yn Zn 1 0 0 0 0 un X n unYn un Z n u n 0
m24 M = reshape(M,[],3)';
0 0 0 0 X n Yn Zn 1 vn X n vnYn vn Z n vn 0
m
31
m32
m33
m34
m11
Projection error defined by two equations – one for u and one for v m
12
m13
312.747 309.140 30.086 1 0 0 0 0 880 312.747 880 309.140 880 30.086 880
0 m14
0 0 0 312.747 309.140 30.086 1 214 312.747 214 309.140 214 30.086 214 0
m21
305.796 311.649 30.356 1 0 0 0 0 43 305.796 43 311.649 43 30.356 43 0
m22
0 0 0 0 305.796 311.649 30.356 1 203 305.796 203 311.649 43 30.356 203
m
23 0
m24
Xn Yn Zn 1n 0 0 0 0 un X n unYn un Z n un 0
0 m31
0 0 0 Xn Yn Zn 1 vn X n vnYn vn Z n vn
m32
m33
m34
extrinsic parameters
intrinsic
parameters
camera matrix
Robotic & Vision Lab RoVis
® © Peter Corke
a university for the
real world
CRICOS No. 00213J
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
𝛾 :the parameter describing the skewness
of the two image axes
http://www.vision.caltech.edu/bouguetj/calib_doc
/
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Robotic & Vision Lab RoVis
Stereo vision
• Stereo matching là quá trình lấy hai hay nhiều điểm ảnh từ đó tái tạo lại hình ảnh
3D của vật bằng cách tìm điểm tương ứng trên hình và chuyển tọa độ pixel thành
tọa độ 3D.
• Thông thường sẽ có hai camera và chúng ta sẽ tìm điểm tương ứng trên
camera trái và camera phải như hình
X L , YL , Z L X b / 2, Y , Z
Tọa độ chiếu (mm) của điểm P trên camera phải:
X R , YR , Z R X b / 2, Y , Z
Tọa độ điểm ảnh của điểm P trên camera trái và phải:
b f b f
ul ( X ) ur ( X )
2 Z 2 Z
Tọa độ thực điểm P được tính từ tọa độ ảnh pixel được tính:
bf bf b(uL uR ) b(uL uR ) by by
Z X Y
uL uR d 2(uL uR ) 2d uL uR d
Matching correlation
windows across scan lines
Left Right
scanline
SSD error
disparity
Left Right
wL wR
m
wL wR m
( xL , y L ) ( xL d , y L )
IL IR