Camera Calibration by Zhang
Camera Calibration by Zhang
Siniša Kolarić
<http://www.inf.puc-rio.br/~skolaric>
September 2006
Abstract
In this presentation, I present a way to calibrate a camera using the
method by Zhang.
NOTE. This is accompanying material to my trabalhos for the course INF2064 ”Tópicos de Computação Gráfica III -
Realidade Aumentada e Cooperativa” held by prof. Marcelo Gattass, during the 2006.2 semestre.
INF2064 Tópicos de Computação Gráfica III - Realidade Aumentada e Cooperativa Camera calibration by Zhang [1]
The problem
Given a set of photos (either real photos — made with a real camera, or
virtual photos — made with a ”virtual”1 camera), determine camera’s:
• Intrinsic parameters
• Extrinsic parameters
1
For example the one implemented with perspective transformation in OpenGL, or one implemented in a raytracer.
INF2064 Tópicos de Computação Gráfica III - Realidade Aumentada e Cooperativa Camera calibration by Zhang [2]
− sfx sh ox
−fx sh ox
K= 0 − sfy oy = 0 −fy oy
0 0 1 0 0 1
−f ku 0 u0
K= 0 −f kv v0
0 0 1
Remarks:
• no skewness factor
• ku = s−1
x , k v = sy
−1
INF2064 Tópicos de Computação Gráfica III - Realidade Aumentada e Cooperativa Camera calibration by Zhang [5]
f sx fτ uc
K= 0 f sy vc
0 0 1
Compared with Trucco/Verri and Faugeras, IMPA people have added the following changes:
• Having images only, it’s not possible to estimate individual values of f, sx, sy ;
only values fx and fy can be estimated
• However if the manufacturer supplied sx, sy with the camera, it’s possible to
derive f
1
sh ox
sx −f 0 0 0
1 R t
pixels ← 0 oy ← image ← 0 −f 0 0 ← camera ← ← world
sy
0 1
0 0 1 0 0 1 0
Zhang’s method
ZHANG()
1 take several(n ≥ 3) photos of your planar model’s printout
2 detect features in photos using LoG, jvInterpret(), etc
3 calculate camera’s extrinsic and intrinsic parms using closed-form solution
4 calculate coeffs for radial distortion solving linear least-squares
5 fine tune calculated parms using Levenberg-Marquardt
6 output calculated parms
There can be less than 3 photos, but only under the supposition that some
intrinsic parameters are known, see below.
INF2064 Tópicos de Computação Gráfica III - Realidade Aumentada e Cooperativa Camera calibration by Zhang [10]
Zhang’s method
”Planar” means that we can flatten coordinate Z of every point of the model
in the Zhang method, that is, consider Z to be 0.
Examples of planar 3-D models would be, for example, patterns of black
rectangles with known dimensions, printed on a paper, glued to a hard-cover
book, and photographed by a camera.
as
[X Y 1]τ −→ K[r1 r2 t][X Y 1]τ
where r1 and r2 are the first two columns of rotation matrix R, t translation
vector, and K intrinsic matrix. By this reduction, we can work with a simpler
projective plane to projective plane transformation (P 2 −→ P 2) instead with the
more general and more complex (P 3 −→ P 2) transformation.
INF2064 Tópicos de Computação Gráfica III - Realidade Aumentada e Cooperativa Camera calibration by Zhang [13]
Homography
1
[X Y 1]τ −→ K[R t][X Y 1]τ = H[X Y 1]τ = [u v 1]τ
λ
where
Homography
Let M designate the set of 2-D model points, and Mi0 set of 2-D points
detected in image i. In a nutshell, the idea is first to extract n homographies Hi
(3x3 matrices) from n pairs {M, Mi0}, i = 1, . . . n:
" 1 1 1
#
h11 h12 h13
{M, M10 } −→ H1 = 1
h21 1
h22 1
h23
1 1 1
h31 h32 h33
" 2 2 2
#
h11 h12 h13
{M, M20 } −→ H2 = 2
h21 2
h22 2
h23
2 2 2
h31 h32 h33
···
n n n
h11 h12 h13
{M, Mn0 } −→ Hn = n
n
h21 n
n
h22 n
n
h23
h31 h32 h33
INF2064 Tópicos de Computação Gráfica III - Realidade Aumentada e Cooperativa Camera calibration by Zhang [16]
With K in hand, we find extrinsics R = [~r1, ~r2, ~r3] and t for each image i:
~t = λK −1~h3
INF2064 Tópicos de Computação Gráfica III - Realidade Aumentada e Cooperativa Camera calibration by Zhang [17]
A couple of remarks about the aforementioned linear system for sx, sy , γ, u0, v0.
For each image i (and thus each homography Hi = K[r1i r2i ti]), we have a
pair of constraining equations:
hτ1iK −τ K −1h2i = 0
If:
• n = 1 — then we can only solve two intrinsic parameters, for example sx and
sy . In this case, we set u0 = W H
2 , v0 = 2 , γ = 0, that is, u0 , v0 are at the image
center, and skewness is zero.
• n = 2 — then we can solve four intrinsic parameters, for example sx, sy , u0, v0.
In this case, we set γ = 0.
To improve the accuracy of results, matrix K, matrices Ri, and vectors ti will
be fed into a nonlinear-minimization solver. That is, matrix K, matrices Ri, and
vectors ti are treated as an initial guess for further refinement.
INF2064 Tópicos de Computação Gráfica III - Realidade Aumentada e Cooperativa Camera calibration by Zhang [21]
Minimizing a functional
where
• m
~ ij is an observed (detected) point j in image i, and
~ˆ
• m(K, Ri, ti, Mj ) is the (re)projection of model point Mj onto image i using
estimated K, Ri, ti
INF2064 Tópicos de Computação Gráfica III - Realidade Aumentada e Cooperativa Camera calibration by Zhang [22]
Minimizing a functional
~ˆ is an estimate:
Therefore, m
~ˆ
m(K, Ri, ti, Mj ) = H[X Y 1]τj = K[r1 r2 t][X Y 1]τj
The nonlinear minimization solver usually used for the aforementioned problem
is Levenberg-Marquardt solver.
INF2064 Tópicos de Computação Gráfica III - Realidade Aumentada e Cooperativa Camera calibration by Zhang [23]
One of the tasks was to find the position of the camera’s optical centre C
expressed in the coordinate system defined by image i (that is, coordinate system
defined by the pose of calibration pattern during which image i has been taken).
getCoordsOfCamerasOpticalCentreInImageSystem()
1 get extrinsics matrix [R t] for image i, where t = [t1, t2, t3]τ
2 return Rτ (−t)
INF2064 Tópicos de Computação Gráfica III - Realidade Aumentada e Cooperativa Camera calibration by Zhang [24]
EXPLANATION. Let points Oim and Ocam be origins of the image system and
the camera system, respectively, in an absolute system. Let ~t be the vector that
gives the position of Oim in the camera system. Let ~r1, ~r2, ~r3 define the unitary
base of the image system (in relation to the unitary base of the camera system).
Because of this, matrix R which translates image’s canonical base {~i0, ~j 0, ~k 0} into
camera’s canonical base {~i, ~j, ~k}, has columns ~r1, ~r2, ~r3 and is an unitary matrix,
RRτ = Rτ R = I. In other words, matrix R rotates (but only after translation ~t
) image points into their corresponding camera points. Therefore, given a point
with image coordinates Pim = (X, Y, Z = 0), its coordinates Pcam in the camera
system are equal to the coordinates of the vector
−−−−−−→ −−−−−−→ −−−−−→
OcamPim = OcamOim + OimPim −→ Pcam = ~t + RPim
INF2064 Tópicos de Computação Gráfica III - Realidade Aumentada e Cooperativa Camera calibration by Zhang [25]
Now using the fact that RRτ = Rτ R = I, and multiplying Pcam = t + RPim by
Rτ from the left side:
−→ Pim = Rτ Pcam − Rτ t
Therefore, given a point expressed in camera coordinates (Pcam), we can calculate
its image coordinates (Pim).
Finally, in the special case Pcam = Ocam = (0, 0, 0)cam, the formula above
gives:
Pim = Rτ Pcam − Rτ t = −Rτ t = Rτ · (−t)
and this way we get optical centre Ocam expressed in image coordinates.
INF2064 Tópicos de Computação Gráfica III - Realidade Aumentada e Cooperativa Camera calibration by Zhang [26]
Calculating f ovy
How to calculate f ovy for image i, from the intrinsics matrix Ki = {kij }?
Holds
f ovy H/2
= tan
2 fy
where H is the height of image expressed in pixels, and fy = k22 is the focal
length in the y direction, also expressed in pixels. Now
H/2
f ovy = 2 arctan [rad]
fy
360◦
Finally, f ovy · 2π [rad] is the field of view expressed in degrees ◦.
INF2064 Tópicos de Computação Gráfica III - Realidade Aumentada e Cooperativa Camera calibration by Zhang [28]
References