nic*_*ine 6 computer-vision camera-calibration projection-matrix
我写了一个简单的脚本,将3D点投影到基于相机内在函数和extrintics的图像上.但是当我在原点指向z轴并且沿z轴进一步向下指向3D时,它看起来是在摄像机后面而不是在它前面.这是我的剧本,我已经多次检查过了.
import numpy as np
def project(point, P):
Hp = P.dot(point)
if Hp[-1] < 0:
print 'Point is behind camera'
Hp = Hp / Hp[-1]
print Hp[0][0], 'x', Hp[1][0]
return Hp[0][0], Hp[1][0]
if __name__ == '__main__':
# Rc and C are the camera orientation and location in world coordinates
# Camera posed at origin pointed down the negative z-axis
Rc = np.eye(3)
C = np.array([0, 0, 0])
# Camera extrinsics
R = Rc.T
t = -R.dot(C).reshape(3, 1)
# The camera projection matrix is then:
# P = K [ R | t] which projects 3D world points
# to 2D homogenous image coordinates.
# Example intrinsics dont really matter ...
K = np.array([
[2000, 0, 2000],
[0, 2000, 1500],
[0, 0, 1],
])
# Sample point in front of camera
# i.e. further down the negative x-axis
# should project into center of image
point = np.array([[0, 0, -10, 1]]).T
# Project point into the camera
P = K.dot(np.hstack((R, t)))
# But when projecting it appears to be behind the camera?
project(point,P)
Run Code Online (Sandbox Code Playgroud)
我唯一能想到的是识别旋转矩阵不对应于指向负z轴的相机,而向上矢量指向正y轴方向.但是我看不出这是不是这种情况,例如我从像gluLookAt这样的函数构造了Rc,并且在原点指向负z轴的相机,我会得到单位矩阵.
我认为困惑仅在于这一行:
if Hp[-1] < 0:
print 'Point is behind camera'
Run Code Online (Sandbox Code Playgroud)
因为这些公式假设正 Z 轴进入屏幕,所以实际上具有正 Z 值的点将位于相机后面:
if Hp[-1] > 0:
print 'Point is behind camera'
Run Code Online (Sandbox Code Playgroud)
我似乎记得这个选择是任意的,以使 3D 表示与我们的 2D 先入为主的效果很好地配合:如果你假设你的相机朝 -Z 方向看,那么当正 Y 指向上方时,负 X 将位于左侧。在这种情况下,只有负 Z 值的物体才会出现在相机前面。