相机(坐标系)的旋转
设相机从
o
−
x
y
z
o-xyz
o−xyz坐标系经过旋转之后形成新的
o
′
−
x
′
y
′
z
′
o'-x'y'z'
o′−x′y′z′坐标系,而
o
−
x
y
z
o-xyz
o−xyz坐标系下的一组单位正交基
(
e
^
1
,
e
^
2
,
e
^
3
)
(\hat{e}_1, \hat{e}_2, \hat{e}_3)
(e^1,e^2,e^3)经过旋转之后变为
(
e
^
1
′
,
e
^
2
′
,
e
^
3
′
)
(\hat{e}^{\prime}_1, \hat{e}^{\prime}_2, \hat{e}^{\prime}_3)
(e^1′,e^2′,e^3′)。对于同一个向量
a
⃗
\vec{a}
a,它在两个坐标系下的坐标分别为
[
a
1
,
a
2
,
a
3
]
T
{[a_1,a_2,a_3]}^T
[a1,a2,a3]T和
[
a
1
′
,
a
2
′
,
a
3
′
]
T
{[a^{\prime}_1,a^{\prime}_2,a^{\prime}_3]}^T
[a1′,a2′,a3′]T。于是以下等式成立:
(1)
[
e
^
1
,
e
^
2
,
e
^
3
]
[
a
1
a
2
a
3
]
=
[
e
^
1
′
,
e
^
2
′
,
e
^
3
′
]
[
a
1
′
a
2
′
a
3
′
]
[\hat{e}_1, \hat{e}_2, \hat{e}_3]\left[\begin{matrix}a_1\\a_2\\a_3\end{matrix}\right]=[\hat{e}^{\prime}_1, \hat{e}^{\prime}_2, \hat{e}^{\prime}_3]\left[\begin{matrix}a^{\prime}_1\\a^{\prime}_2\\a^{\prime}_3\end{matrix}\right] \tag 1
[e^1,e^2,e^3]⎣⎡a1a2a3⎦⎤=[e^1′,e^2′,e^3′]⎣⎡a1′a2′a3′⎦⎤(1)
等式两边同时左乘
[
e
^
1
T
e
^
2
T
e
^
3
T
]
\left[\begin{matrix}\hat{e}^T_1\\\hat{e}^T_2\\\hat{e}^T_3\end{matrix}\right]
⎣⎡e^1Te^2Te^3T⎦⎤,得到下式:
(2)
[
a
1
a
2
a
3
]
=
[
e
^
1
T
e
^
1
′
e
^
1
T
e
^
2
′
e
^
1
T
e
^
3
′
e
^
2
T
e
^
1
′
e
^
2
T
e
^
2
′
e
^
2
T
e
^
3
′
e
^
3
T
e
^
1
′
e
^
3
T
e
^
2
′
e
^
3
T
e
^
3
′
]
[
a
1
′
a
2
′
a
3
′
]
≜
R
[
a
1
′
a
2
′
a
3
′
]
\left[\begin{matrix}a_1\\a_2\\a_3\end{matrix}\right]=\left[\begin{matrix}\hat{e}^T_1 \hat{e}^{\prime}_1 & \hat{e}^T_1 \hat{e}^{\prime}_2 & \hat{e}^T_1 \hat{e}^{\prime}_3 \\ \hat{e}^T_2 \hat{e}^{\prime}_1 & \hat{e}^T_2 \hat{e}^{\prime}_2 & \hat{e}^T_2 \hat{e}^{\prime}_3 \\ \hat{e}^T_3 \hat{e}^{\prime}_1 & \hat{e}^T_3 \hat{e}^{\prime}_2 & \hat{e}^T_3 \hat{e}^{\prime}_3\end{matrix}\right]\left[\begin{matrix}a^{\prime}_1\\a^{\prime}_2\\a^{\prime}_3\end{matrix}\right]\triangleq{\mathbf{R}\left[\begin{matrix}a^{\prime}_1\\a^{\prime}_2\\a^{\prime}_3\end{matrix}\right]} \tag 2
⎣⎡a1a2a3⎦⎤=⎣⎡e^1Te^1′e^2Te^1′e^3Te^1′e^1Te^2′e^2Te^2′e^3Te^2′e^1Te^3′e^2Te^3′e^3Te^3′⎦⎤⎣⎡a1′a2′a3′⎦⎤≜R⎣⎡a1′a2′a3′⎦⎤(2)
矩阵
R
\mathbf{R}
R称为旋转矩阵,它描述了从
o
−
x
y
z
o-xyz
o−xyz到
o
′
−
x
′
y
′
z
′
o'-x'y'z'
o′−x′y′z′的旋转。
由于旋转矩阵为正交矩阵,故有:
(3)
[
a
1
′
a
2
′
a
3
′
]
=
R
−
1
[
a
1
a
2
a
3
]
=
R
T
[
a
1
a
2
a
3
]
\left[\begin{matrix}a^{\prime}_1\\a^{\prime}_2\\a^{\prime}_3\end{matrix}\right]=\mathbf{R}^{-1}\left[\begin{matrix}a_1\\a_2\\a_3\end{matrix}\right]=\mathbf{R}^T\left[\begin{matrix}a_1\\a_2\\a_3\end{matrix}\right] \tag 3
⎣⎡a1′a2′a3′⎦⎤=R−1⎣⎡a1a2a3⎦⎤=RT⎣⎡a1a2a3⎦⎤(3)
旋转矩阵的例子:
坐标系绕z轴转 θ \theta θ角,对应的旋转矩阵为: R = [ c o s θ − s i n θ 0 s i n θ c o s θ 0 0 0 1 ] \mathbf{R}=\left[\begin{matrix}cos\theta & -sin\theta & 0 \\ sin\theta & cos\theta & 0 \\ 0 & 0 & 1\end{matrix}\right] R=⎣⎡cosθsinθ0−sinθcosθ0001⎦⎤。
相机(坐标系)的平移
相机的平移可用一个平移向量
t
⃗
\vec{t}
t表示。
设相机从
o
−
x
y
z
o-xyz
o−xyz坐标系沿着向量
t
⃗
\vec{t}
t(它在o-xyz坐标系下的坐标为
[
t
1
,
t
2
,
t
3
]
T
{[t_1,t_2,t_3]}^T
[t1,t2,t3]T)经过平移之后形成新的
o
′
−
x
′
y
′
z
′
o'-x'y'z'
o′−x′y′z′坐标系。对于同一个点
P
P
P,它在两个坐标系下的坐标分别为
[
p
1
,
p
2
,
p
3
]
T
{[p_1,p_2,p_3]}^T
[p1,p2,p3]T和
[
p
1
′
,
p
2
′
,
p
3
′
]
T
{[p^{\prime}_1,p^{\prime}_2,p^{\prime}_3]}^T
[p1′,p2′,p3′]T,则有:
(4)
p
⃗
=
p
⃗
′
+
t
⃗
\vec{p}=\vec{p}^{\prime}+\vec{t} \tag 4
p=p′+t(4)
即:
[
p
1
,
p
2
,
p
3
]
T
=
[
p
1
′
,
p
2
′
,
p
3
′
]
T
+
[
t
1
,
t
2
,
t
3
]
T
{[p_1,p_2,p_3]}^T={[p^{\prime}_1,p^{\prime}_2,p^{\prime}_3]}^T+{[t_1,t_2,t_3]}^T
[p1,p2,p3]T=[p1′,p2′,p3′]T+[t1,t2,t3]T
旋转+平移
假设相机先后经过一次旋转
R
\mathbf{R}
R和一次平移
t
′
⃗
\vec{t^{\prime}}
t′之后,对应的坐标系由
o
−
x
y
z
o-xyz
o−xyz变为
o
′
−
x
′
y
′
z
′
o^{\prime}-x'y'z'
o′−x′y′z′再变为
o
′
′
−
x
′
′
y
′
′
z
′
′
o''-x''y''z''
o′′−x′′y′′z′′,向量
a
⃗
\vec{a}
a在各个坐标系下的坐标分别为
[
a
1
,
a
2
,
a
3
]
T
{[a_1,a_2,a_3]}^T
[a1,a2,a3]T、
[
a
1
′
,
a
2
′
,
a
3
′
]
T
{[a^{\prime}_1,a^{\prime}_2,a^{\prime}_3]}^T
[a1′,a2′,a3′]T和
[
a
1
′
′
,
a
2
′
′
,
a
3
′
′
]
T
{[a^{\prime\prime}_1,a^{\prime\prime}_2,a^{\prime\prime}_3]}^T
[a1′′,a2′′,a3′′]T,则有:
(5)
[
a
1
a
2
a
3
]
=
R
o
′
o
(
[
a
1
′
′
a
2
′
′
a
3
′
′
]
+
[
t
1
′
t
2
′
t
3
′
]
)
=
R
[
a
1
′
′
a
2
′
′
a
3
′
′
]
+
[
t
1
t
2
t
3
]
\left[\begin{matrix}a_1\\a_2\\a_3\end{matrix}\right]=\mathbf{R_{o'o}}\left(\left[\begin{matrix}a^{\prime\prime}_1\\a^{\prime\prime}_2\\a^{\prime\prime}_3\end{matrix}\right]+\left[\begin{matrix}t^{\prime}_1\\t^{\prime}_2\\t^{\prime}_3\end{matrix}\right]\right)=\mathbf{R}\left[\begin{matrix}a^{\prime\prime}_1\\a^{\prime\prime}_2\\a^{\prime\prime}_3\end{matrix}\right]+\left[\begin{matrix}t_1\\t_2\\t_3\end{matrix}\right] \tag 5
⎣⎡a1a2a3⎦⎤=Ro′o⎝⎛⎣⎡a1′′a2′′a3′′⎦⎤+⎣⎡t1′t2′t3′⎦⎤⎠⎞=R⎣⎡a1′′a2′′a3′′⎦⎤+⎣⎡t1t2t3⎦⎤(5)
假设相机先平移
t
⃗
\vec{t}
t再旋转
R
\mathbf{R}
R,则向量
a
⃗
\vec{a}
a在变换前后的坐标之间的关系为:
(6)
[
a
1
a
2
a
3
]
=
R
o
′
′
o
′
[
a
1
′
′
a
2
′
′
a
3
′
′
]
+
[
t
1
t
2
t
3
]
=
R
[
a
1
′
′
a
2
′
′
a
3
′
′
]
+
[
t
1
t
2
t
3
]
\left[\begin{matrix}a_1\\a_2\\a_3\end{matrix}\right]=\mathbf{R_{o''o'}}\left[\begin{matrix}a^{\prime\prime}_1\\a^{\prime\prime}_2\\a^{\prime\prime}_3\end{matrix}\right]+\left[\begin{matrix}t_1\\t_2\\t_3\end{matrix}\right]=\mathbf{R}\left[\begin{matrix}a^{\prime\prime}_1\\a^{\prime\prime}_2\\a^{\prime\prime}_3\end{matrix}\right]+\left[\begin{matrix}t_1\\t_2\\t_3\end{matrix}\right] \tag 6
⎣⎡a1a2a3⎦⎤=Ro′′o′⎣⎡a1′′a2′′a3′′⎦⎤+⎣⎡t1t2t3⎦⎤=R⎣⎡a1′′a2′′a3′′⎦⎤+⎣⎡t1t2t3⎦⎤(6)
齐次变换矩阵
引入齐次坐标,将旋转和平移写到一个矩阵里面:
(7)
[
a
1
]
=
[
R
t
0
T
1
]
[
a
′
′
1
]
≜
T
[
a
′
′
1
]
\left[\begin{matrix}\mathbf{a} \\ 1\end{matrix}\right]=\left[\begin{matrix}R & \mathbf{t} \\ \mathbf{0}^T & 1\end{matrix}\right]\left[\begin{matrix}\mathbf{a''} \\ 1\end{matrix}\right]\triangleq{\mathbf{T}\left[\begin{matrix}\mathbf{a''} \\ 1\end{matrix}\right]} \tag 7
[a1]=[R0Tt1][a′′1]≜T[a′′1](7)
T
\mathbf{T}
T即为齐次坐标下的坐标变换矩阵。