視覚の幾何学1
呉海元@和歌山大学 2011 年 5 月 23 日
参考書 佐藤 淳:
「コンピュータビジョン -視覚の幾何学-」
コロナ社
Single view geometry
Camera model Single view geom.
レンズによる写真投影 ピンホールカメラ投影
理想的なカメラ
☆左側の平面上に撮像素子を置いてお けば,ピントの合った画像が得られる
透視変換(中心投影) 正射影(平行投影)
●3次元空間のある点から発せられた光はレンズ によって一点に集光される
●光がレンズに入射する角度に応じて集光され る位置が変わる
●
どのような角度で入射した平行な光もすべてあ る一つの平面上に集光される
実際のカメラ
●実際に使用するカメラは対象物からの光を受ける受光部(撮像素 子)と、受光により発生する微弱な電気信号を処理する信号処理部 からなっている
★イメージセンサに受光部と信号処理部を含まれる
●受光部の前にはレンズが置かれ、光はこのレンズによって集光 され、絞りを通して撮像素子(イメージセンサ)に至る
●レンズ系と撮像素子によって、3D空間から2D画像への投影
実際のカメラ
●実際のカメラではレンズ収差や歪みが生じるため、複 数のレンズを組み合わせて、レンズ収差や歪みなどを 取り除く
レンズの外観 レンズの中
カメラモデル(Camera model)
画像内の一点と3次元空間中の光線の関係
投影(
Projections )・射影関係によって決定
⇒
この関係を記述するカメラモデルが複数ある?
投影による3次元空間の2次元画像への変換
レンズによる写真投影(物理モデル) ピンホ ルカメラ投影 レンズによる写真投影(物理モデル) ピンホールカメラ投影
透視変換(中心投影) 正射影(平行投影)
平行投影・正射影モデル 透視投影モデル
カメラモデル( Camera model )
投影中心
投影面 投影面
理想・簡単 物理モデルに一番近い
ピンホール・カメラ(pinhole camera)
Pinhole Object
f o
像が上下逆転
●撮像素子が置かれる面を画像面I (image plane)
●全ての光が通過する点(pinhole)を光学中心o(optical center)
●光学中心と画像面の間の距離を焦点距離f (focal length)
特徴:
●ピント合わせの必要がない
●投影の幾何学的な性質がそのまま保存されている
●視覚の幾何を考える上で理想的な性質を持つ
Image plane
ピンホール・カメラから 透視投影 (Perspective Projection)へ
●仮想的に画像面(Virtual image plane
)を光学中心の前 (対象物側)に置くと、像が上下逆転せずに投影される
⇒
投影がより扱いやすくなる●普通、画像面を対象物側に置いて考える もちろん 光学中心の後ろのまま考える場合もある もちろん、光学中心の後ろのまま考える場合もある
Image plane
Pinhole Virtual Object image plane
Z軸の方向や画像面の場所によって、
数式の±記号の差がある
透視投影モデル
z
y y’
(x, y, z) (x’, y’, z’)
O
(x,y,z)から(x’,y’,z’)へ投影:
(相似三角関係より)
x’ x z’
z
簡略されたモデル:
x x’
z z
z z y y
z z x x
(-f = Z’)
★幾何関係だけ考える理論系の人はよくf
= Z’ =1とする
●透視投影はZに関し非線形である 仮定:
1.原点をレンズの中心に 2.Z軸と光軸と平行
透視投影の画像
Amsterdam: what do you see in this picture?
straight line
size
parallelism/angle
shape
Photo by Robert Kosara, [email protected]
http://www.kosara.net/gallery/pinholeamsterdam/pic01.html s ape
shape of planes
depth
透視投影の画像
Amsterdam
straight line
size
parallelism/angle
shape
Photo by Robert Kosara, [email protected]
http://www.kosara.net/gallery/pinholeamsterdam/pic01.html shape
shape of planes
depth
透視投影の画像
Amsterdam
straight line
size
parallelism/angle
shape
Photo by Robert Kosara, [email protected]
http://www.kosara.net/gallery/pinholeamsterdam/pic01.html shape
shape of planes
depth
透視投影の画像
Amsterdam
straight line
size
parallelism/angle
shape
Photo by Robert Kosara, [email protected]
http://www.kosara.net/gallery/pinholeamsterdam/pic01.html s ape
shape of planes
depth
透視投影の画像
Amsterdam
straight line
size
parallelism/angle
shape
Photo by Robert Kosara, [email protected]
http://www.kosara.net/gallery/pinholeamsterdam/pic01.html s ape
shape of planes
depth
透視投影の画像
Amsterdam
straight line
size
parallelism/angle
shape
Photo by Robert Kosara, [email protected]
http://www.kosara.net/gallery/pinholeamsterdam/pic01.html s ape
shape of planes
parallel to image
depth
透視投影の画像
Amsterdam: what do you see?
straight line
size
parallelism/angle
shape
-We see spatial shapes rather than individual pixels - Knowledge: top-down vision belongs to human - Stereo & Motion most successful in 3D CV & application - You can see it but you don't know how…
s ape
shape of planes
parallel to image
Depth ?
stereo
motion
size
structure …
点⇒点
透視投影 (まとめ)
線⇒線
面⇒面
ポリゴン⇒ポリゴン
遠い物体が小さい
奥行き情報が得られない 消失点
Perspective effects
Perspective effects カメラの内部パラメータI
(o
x, o
y)
●画像座標系:(ximage, yimage) ●画像中心:(ox, oy)
●カメラ座標系:(xcamera, ycamera)
●ワールド座標系Real world coordinates (X, Y, Z)
●焦点距離Focal length
f
●画素の有効サイズEffective size of pixel in millimeter (kx
, k
y)
y camera y image
x camera x image
o y k y
o x k x
0
0
camera xx image
o o y
x k k y x
カメラのパラメータ
行列・ベクトル を導入
1 1 0 0 0
0 1
0
camera camera y y
x x image image
camera y y image
y x o k
o k y
x
y o k y
同次座標系
を導入することによって、複雑な座標変換がすべて行列の形で処理できる
同次座標系を導入
同次座標導入の利点
同次座標を使わない場合
•
一回目のアフィン変換•
二回目のアフィン変換1 1
'
M P b
P
2 ' 2 '
'
M P b
P
2 1 1 2 '
'
M (M P b ) b
P
2 1 2 1 2 ' '
2 1 1 2
b b M 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つ次元を 1つ次元を 上げると・
上げると・・・
2次元座標変換(回転+移動):
3次元座標変換(回転+移動):
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つ次元を 1つ次元を 上げると・
上げると・・・
y camera y image
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
, y
image) ⇒K行列
g g
●画像中心:(ox
, o
y)
●カメラ座標系:(xcamera
, y
camera)
●ワールド座標系
(X, Y, Z)
●焦点距離
f
●画素の有効サイズ
(k
x, k
y)
内部パラメータ(
Intrinsic Camera Parameters
)はワー ルド座標系内のカメラの位置と姿勢と依存しないカメラの内部パラメータII
レンズのひずみ
Lens Distortions
Modeled as simple radial
) 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
Modeled as simple radial distortions
r2= xd2+yd2
(xd , yd) distorted points
k1 , k2: distortion coefficients
カメラの外部パラメータ Extrinsic Camera Parameters
外部パラメータはワールド座標系内のカメラ座標系 の位置と姿勢によって決定される
•
平行移動Translation (3x1ベクトル)•
回転Rotation (3x3行列)カメラ座標系
Zw
Xw
Yw x
O y
Pw
P p xim
yim
(xim,yim)
t R
O
ワールド座標系 カメラ座標系
コンピュータ内の画像座標系 カメラに対する画像座標系 ワールド座標系とカメラ座標系間 の絶対的な位置Tと姿勢Rの関係
カメラ座標と世界座標
世界座標とカメラ座標の関係(回転後平行移動)
ワールド座標を中心とする
w w
c Rm t
m m
w R
1( m
c t
w) R
T( m
c t
w)
カメラ座標と世界座標
,
世界座標とカメラ座標の関係(平行移動後回転)
ワールド座標を中心とする
平行移動( Translation )
(t
x, t
y, t
z) 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
world world world
z y x
camera camera camera
Z Y X
t t t
Z Y X
3次元
同次座標
Matrix n Translatio
1 1
world world world
camera camera camera
Z Y X
Z Y X
t 同次座標
ピンホールカメラモデル、f =1
Inverse translation
0 0 1
0 1 0
0 0 1
y x
t t t
t
1 0 0
0 1 0
0 0 1
1 y
x
t t t
t
平行移動( Translation )行列の特性
0 0 0 1 1 0
0 tz
1 0 0 0
1 0
0 tz
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
Z- 軸周りの回転( Rotation )
Z-軸周り
YZ
X (X,Y,Z) (X’,Y’,Z’)
R
R
cos R X
sin R Y
変換前:
coscos sinsin cos X YR R
R
X
cossin sincos sin X YR 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 I
R
Z.
Z T
cos sin 0 cos sin 0 1 0 0
1 0 0
0 1 0 1 0 0
0 cos sin 1 0 0
0 cos
sin
回転行列は直交行列!!
0 otherwise 1 i j
j T
i
R
R
I R R RR R
R1
T, i . e .
T
T
X-軸周り
Y-軸周り
cos sin 0
sin cos 0
0 0 1 RX
0 i
0 1 0
sin 0 cos RY
3軸の回転(Rotation)
Z-軸周り
回転なし
sin 0 cos
1 0 0
0 cos sin
0 sin cos
RZ
1 0 0
0 1 0
0 0 1 R
, ,
はX, Y, Z
軸周りの回転角注意:
回転行列とEuler角
X Y
Z
R R
R R
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
• 一回一つの角度しか回転できない
• 順番と関係がある
Zw
Xw
Yw
O
1 1 1
R
If angle is small, then cos =1 and sin =
また * + =
座標間の関係
世界座標
カメラ座標 画像座標
外部パラメータ 内部パラメータ
w w
c
Rm t
m
射影行列(透視投影行列) 世界座標と画像座標の関係
カメラのパラメータ
ワールド座標系とカメラ座標系の下(回転後平行移動)
t
x, t
y, t
zとr
1,1…r
3,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
cameracamera camera
y y
x x image image
Z Y X o fk
o fk y
x
1
1 1 0 0 0 0 1 0 0
0 0
0 0
1
3,1 3,2 3,33 , 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行列
幾何学的変換の関係
射影変換 アフィン変換
線形変換 ユークリッド変換 線形変換
拡大・縮小
鏡像 回転
スキュー
クリッド変換
平行移動
2 次元アフィン変換
b a y x y x '
平行移動'
x ' a 0 x
拡大・縮小
x' a b x e
アフィン変換は線型変換(回転、拡大縮小、剪断)と平行移動の組み合わせ
y ' 0 b y
拡大・縮小
y x y
x
cos sin
sin cos '
回転'
一般化!
y' c d y f
アフィン変換
せん断
y x sh
sh y
x
y x
1
1
'
'
2次元アフィン変換
b a y x y x '
平行移動'
f e y x d c
b a y x ' '
アフィン変換
2 次元アフィン変換
y x b a y x
0 0 '
'
拡大・縮小一般化!
f e y x d c
b a y x ' '
アフィン変換
2 次元アフィン変換
y x y
x
cos sin
sin cos '
回転'
f e y x d c
b a y x ' '
アフィン変換
アフィン変換をもっと簡単な形に~
同次座標
x' a b x e
' '
y x f d c
e b a y x
(homogeneous coordinates) (homogeneous coordinates)
図形の変換を全て行列の乗算1回で処理可能
複雑な座標変換がすべて行列の形で処理できる
y' c d y f
積 和
1 0 0 1 1
積のみ!
1つ次元を 上げると・・・
同次座標の基本2D変換
Basic 2D transformations as 3x3 matrices
1 1 0 0
1 0
0 1
1 ' '
y x t t y
x
y x
1 1 0 0
0 0
0 0
1 ' '
y x s s y x
y x
1 1 0 0
0 cos sin
0 sin cos
1 ' '
y x y
x
1 0 0 1 1
1 1 0 0
0 1
0 1
1 ' '
y x sh
sh y
x
y x
平行移動Translate
回転Rotate せん断Shear
1 0 0 1 1
拡大・縮小Scale
行列の合成
複雑な座標変換の行列は各処理の行列の掛け算 から合成
y x s s ty
tx y
x
x0 0
0 0 0 cos sin
0 sin cos 1 0
0 1 ' '
w
y s ty
w
y
y1 0 0
0 0 1 0 0
0 cos sin 1 0 0
1 0 ' '
p’ = T(tx,ty) R() S(sx,sy) p
同次座標 ( 3 次元)
3次元座標値を,一つ次元を上げて4次元空間の
中で処理
( x, y, z ) ( x, y, z, f )
(x/f, y/f, z/f) が三次元座標値となる
f=1のときはそのまま(x, y, z)が座標値 2次元アフィン変換と同じく、
座標変換をまとめて表記できる!
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次元 3次元
P(x, y, z) からP(x’, y’, z’) へのアフィン変換(同次座標による表現)
AP P '
(A: アフィン変換行列)
同次座標系導入の利点
f=w=1
直線上の点はすべて同じ座標を持つものとする
(点と線が同一視される)
出席チェック
1.ピンホールカメラ(透視投影モデル)の原理図を 描き、撮影された画像の特徴について述べなさい 2 カメラの内部パラメ タ 外部パラメ タは?
2.カメラの内部パラメータ、外部パラメータは?
3.同次座標系導入の利点について述べなさい
無限遠要素
無限遠点 無限遠直線 無限遠平面