視覚の幾何学1
呉海元@和歌山大学
参考書 佐藤 淳:
「コンピュータビジョン -視覚の幾何学-」
コロナ社
? projections
Single view geometry
Camera model Single view geom.
画像内の一点と3次元空間中の光線の関係
投影(Projections)・射影関係によって決定
⇒ この関係を記述するカメラモデルが複数ある
カメラモデル( Camera model )
?
投影による3次元空間から2次元画像への変換
レンズによる写真投影(物理モデル) ピンホールカメラ投影
射影・透視変換(中心投影) 正射影(平行投影)
平行投影・正射影モデル (Orthographic)
投影面
理想・簡単
) , ( ) , ,
( X Y Z x y
3D point 2D image position
投影中心
投影面
物理モデルに一番近い
透視投影モデル (Perspective)
Z fY Z X fX Y
X, , ) ,
(
3D point 2D image position
ピンホール・カメラ(pinhole camera)
●撮像素子が置かれる面を画像面I (image plane)
●全ての光が通過する点(pinhole)を光学中心o(optical center)
●光学中心と画像面の間の距離を焦点距離f (focal length)
特徴:
●ピント合わせの必要がない
●投影の幾何学的な性質がそのまま保存されている
●視覚の幾何を考える上で理想的な性質を持つ
Image plane
Pinhole Object
f o
像が上下逆転
ピンホール・カメラから
透視投影 (Perspective Projection) へ
●仮想的に画像面(Virtual image plane)を光学中心の前 (対象物側)に置くと、像が上下逆転せずに投影される
⇒ 投影がより扱いやすくなる
●普通、画像面を対象物側に置いて考える もちろん、光学中心の後ろのまま考える場合もある
Image plane
Pinhole Virtual Object image plane 注意:
Z軸の方向や画像面の場所によって、
数式の±記号の差がある
透視投影モデル
x
z
y
x’
y’
(X, Y, Z) (x, y, z)
O
(X,Y,Z)から(x,y,z)へ投影:
(相似三角関係より)
z z
Z zY y
Z zX x
X
x z
Z
(
f = z)
★幾何関係だけ考える理論系の人はよくf= z=1とする
●透視投影はZに関し非線形である 仮定:
1.原点をレンズの中心に 2.Z軸と光軸と平行 簡略されたモデル:
透視投影の画像
Photo by Robert Kosara, [email protected]
http://www.kosara.net/gallery/pinholeamsterdam/pic01.html Amsterdam: what do you see in this picture?
straight line
size
parallelism/angle
shape
shape of planes
depth
点⇒点
線⇒線
面⇒面
ポリゴン⇒ポリゴン
遠い物体が小さい
奥行き情報が得られない
透視投影 (まとめ)
消失点
Linear Perspective
(c) 2006 Walt Anthony
カメラの内部パラメータI
(ox, oy)
●画像座標系:(ximage, yimage) ●画像中心:(ox, oy)
●カメラ座標系:(xcamera, ycamera)
●ワールド座標系Real world coordinates (X, Y, Z)
●焦点距離Focal length f
●画素の有効サイズEffective size of pixel in millimeter (kx, ky)
y camera y image
x camera x image
o y k y v
o x k x u
1 1 0 0 0
0 1
1
0 0
camera camera y y
x x image image
y x camera camera y x image image
y x o k
o k y
x v u
o o y
x k k y
x v u
カメラと画像間のパラメータ
同次座標系
を導入することによって、複雑な座標変換がすべて行列の積で処理できる
同次座標系を導入 行列・ベクトル を導入
同次座標導入の利点
同次座標を使わない場合
• 一回目のアフィン変換
• 二回目のアフィン変換
1 1
' M P b
P
2 ' 2 '
' MP b
P
2 1 2 1 2 ' '
2 1 1 2 ' '
b b M P M M P
b ) b P (M M P
同次座標を導入した場合
P A A P
P A P
1 2 ' '
1 '
メリット:
座標変換を全て行列の乗算で処理可能
線形代数の原理原則は全部使えるようになる
同次座標系 Homogenous Coordinates
f e y x d c
b a y x ' '
積 和
1 1 0 0 1
' '
y x f d c
e b a y x
積のみ!
1つ次元を 上げると・・・
2次元座標変換(回転+移動):
C V
3 2 1
33 32 31
23 22 21
13 12 11
' ' '
b b b
z y x
a a a
a a a
a a a
z y x
3次元座標変換(回転+移動):
1 1 0 0 0 1
' ' '
3 33 32 31
2 23 22 21
1 13 12 11
z y x
b a a a
b a a a
b a a a
z y x
1つ次元を 上げると・・・
C V
ピンホールカメラモデル ワールド座標系と理想なカメラの関係
0 1 1 0 0
0 0 0
0 0 0
1 Z
Y X f
f y
x
camera
camera image y camera y
x camera x image
o y k y
o x k x
1 1 0 0 0
0 1
camera camera y y
x x
image image
y x o k
o k
y x
カメラの内部パラメータ
0 1 1 0 0
0 0 0
0 0 0
1 0 0 0
0
1 Z
Y X f
f o k
o k
y x
y y
x x
image image
カメラ座標系と画像座標系の関係:
ワールド座標系と画像座標系の関係:
⇒A行列
カメラの内部パラメータ(K行列)
0 1 1 0 0
0 0
0 0
0 1 1 0 0
0 0 0
0 0 0 1 0 0 0
0
1 Z
Y X o fk
o fk Z Y X f
f o k
o k y x
y y
x x y
y x x image image
●画像座標系:(ximage, yimage)
●画像中心:(ox, oy)
●カメラ座標系:(xcamera, ycamera)
●ワールド座標系(X, Y, Z)
●焦点距離 f
●画素の有効サイズ(kx, ky)
⇒K行列
内部パラメータ(Intrinsic Camera Parameters)はワール ド座標系内のカメラの位置と姿勢と依存しない
カメラの内部パラメータII
レンズのひずみ Lens Distortions
Modeled as simple radial distortions
r2= xd2+yd2
(xd , yd) distorted points
k1 , k2: distortion coefficients ) 1
(
) 1
(
4 2 2 1
4 2 2 1
r k r k y y
r k r k x x
d d
(xd, yd) (x, y)
k1 , k2
カメラの外部パラメータ Extrinsic Camera Parameters
外部パラメータはワールド座標系内のカメラ座標系 の位置Tと姿勢Rによって決定される
• 平行移動Translation (3x1ベクトル)
• 回転Rotation (3x3行列)
Zw
Xw Yw
y x O
Pw P p xim
yim
(xim,yim)
T R
O
ワールド座標系 カメラ座標系
コンピュータ内の画像座標系 カメラに対する画像座標系(内部)
ワールド座標系とカメラ座標系間 の絶対的な位置Tと姿勢Rの関係
カメラ座標とワールド座標
ワールド座標とカメラ座標の関係(回転後平行移動)
ワールド座標を中心とする
w w
c
Rm t
m
1( ) ( c w) Tw c
w R m t R m t
m
順番がある
カメラ座標とワールド座標
,
ワールド座標とカメラ座標の関係(平行移動後回転)
ワールド座標を中心とする 順番がある
Z-軸周りの回転( Rotation )
Z-
軸周り
YZ
X (X,Y,Z) (X’,Y’,Z’)
R R
cos R X
sin R Y
coscos sinsin cos X Y
R R
R
X
cossin sincos sin X Y
R R
R
Y
sin cos Y X
X
cos sin Y X Y
Z Y X Z
Y X
1 0 0
0 cos sin
0 sin cos
変換前:
変換後: 変換前と変換後の関係:
回転(Rotation)行列の特性
Inverse rotation
R IRZ. Z T
1 0 0
0 1 0
0 0 1 1 0 0
0 cos sin
0 sin cos 1 0 0
0 cos sin
0 sin cos
回転行列は直交行列!!
0 otherwise 1 i j
j T
i R
R
I R R RR R
R1 T,i.e. T T
X-軸周り
Y-軸周り
Z-軸周り
回転なし
cos sin 0
sin cos 0
0 0 1 RX
cos 0 sin
0 1 0
sin 0 cos RY
1 0 0
0 cos sin
0 sin cos
RZ
1 0 0
0 1 0
0 0 1 R
3軸の回転(Rotation)
, , はX, Y, Z軸周りの回転角
注意:
• 一回一つの角度しか回転できない
• 順番と関係がある
回転行列と Euler 角
X Y
ZR R
R R
Zw
Xw Yw
O
cos cos cos sin sin sin cos sin sin cos sin cos
cos sin cos cos sin sin sin sin cos cos sin sin
sin sin
cos cos
cos R
1 1 1
R
If angle is small, then cos=1 and sin= また * + =
近似された行列
平行移動( Translation )
(tx, ty, tz) Translation vector
z y x
world world world
camera camera camera
t t t Z Y X Z Y X
1 1 0 0 0
1 0 0
0 1 0
0 0 1
1
Matrix n Translatio
world world world
z y x
camera camera camera
Z Y X t t t Z
Y X
1 1
world world world
camera camera camera
Z Y X Z Y X
t 3次元
同次座標
ピンホールカメラモデル、f =1
Inverse translation
1 0 0 0
1 0 0
0 1 0
0 0 1
z y x
t t t
t
1 0 0 0
1 0 0
0 1 0
0 0 1
1
z y x
t t t t
I
tt
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
1 0 0 0
1 0 0
0 1 0
0 0 1
1 0 0 0
1 0 0
0 1 0
0 0 1
1
z y x
z y x
t t t t
t t
平行移動( Translation )行列の特性 座標間の関係
射影行列(透視投影行列) 世界座標
カメラ座標 画像座標
世界座標と画像座標の関係 外部パラメータ 内部パラメータ
w w
c
Rm t
m
K
1 回転後平行移動 K
カメラの外部パラメータ
ワールド座標系とカメラ座標系の下(回転後平行移動)
tx, ty, tzとr1,1…r3,3はカメラ外部パラメータ
T R
worldcamera
X
X
1 1 0 0 0 1
3 , 3 2 , 3 1 , 3
3 , 2 2 , 2 1 , 2
3 , 1 2 , 1 1 , 1
world world world
z y x
camera camera camera
Z Y X
t r r r
t r r r
t r r r
Z Y X
外部パラメータ
カメラのパラメータ
ワールド座標系と画像座標系の下で
0 1 1 0 0
0 0
0 0
1 camera
camera camera
y y
x x
image image
Z Y X o fk
o fk
y x
1 1 0 0 0 0
1 0 0
0 0
0 0
1 3,1 3,2 3,3
3 , 2 2 , 2 1 , 2
3 , 1 2 , 1 1 , 1
world world world
z y x
y y
x x
image image
Z Y X
t r r r
t r r r
t r r r o fk
o fk
y x
内部パラメータ 外部パラメータ P行列
3D-2D Projective mapping
Projection Matrix (3x4)
出席チェック
1.ピンホールカメラ(透視投影モデル)の原理図を 描き、撮影された画像の特徴について述べなさい 2.カメラの内部パラメータ、外部パラメータは?
3.同次座標系導入の利点について述べなさい
Camera parameters(まとめ)
Camera frame 1
Intrinsic parameters:
Image coordinates relative to camera Pixel coordinates
Extrinsic parameters:
Camera frame 1 World coordinate
Camera frame 2 World coordinate Or
Camera frame 2
• Extrinsic params: rotation matrix and translation vector
• Intrinsic params: focal length, pixel sizes (mm), image center point, radial distortion parameters
Slide credit: Kristen Grauman
幾何学的変換の関係
射影変換 アフィン変換
線形変換
拡大・縮小
鏡像 回転
スキュー
ユークリッド変換
平行移動
2D Transformations
tx ty
= +
1
= 1 0 tx 0 1 ty .
= 1 0 tx
0 1 ty
0 0 1
. Example: translation
Now we can chain transformations スキュー
平行移動 平行移動
回転
平行移動 回転
拡大・縮小
無限遠要素
無限遠点 無限遠直線 無限遠平面
2次元アフィン変換
b a y x y x ' 平行移動 '
y x b a y x
0 0 '
拡大・縮小 '
y x y
x
cos sin
sin cos ' 回転 '
一般化!
f e y x d c
b a y x ' '
アフィン変換
せん断
y x sh
sh y
x
y x
1 1 ' '
アフィン変換は線型変換(回転、拡大縮小、剪断)と平行移動の組み合わせ
同次座標の基本2D変換
Basic 2D transformations as 3x3 matrices
1 1 0 0
0 cos sin
0 sin cos
1 ' '
y x y
x
1 1 0 0
1 0
0 1
1 ' '
y x t t y
x
y x
1 1 0 0
0 1
0 1 1
' '
y x sh
sh y
x
y x
平行移動Translate
回転Rotate せん断Shear
1 1 0 0
0 0
0 0
1 ' '
y x s s y x
y x
拡大・縮小Scale
行列の合成
複雑な座標変換の行列は各処理の行列の掛け算 から合成
w y x s s ty
tx
w y x
y x
1 0 0
0 0
0 0 1 0 0
0 cos sin
0 sin cos 1 0 0
1 0
0 1 ' ' '
p’ = T(tx,ty) R() S(sx,sy) p
3次元アフィン変換
1 1 0 0 1
' '
y x f d c
e b a y x
2次元
1 1 0 0 0 1
' ' '
33 32 31
23 22 21
13 12 11
z y x
b a a a
b a a a
b a a a
z y x
z y x
3次元
P(x, y, z) からP(x’, y’, z’) へのアフィン変換(同次座標による表現)
AP P
'
(A: アフィン変換行列)
同次座標系導入の利点
直線上の点はすべて同じ座標を持つものとする (点と線が同一視される)
f=w=1