【发布时间】:2018-02-25 07:40:01
【问题描述】:
我编写了一个简单的脚本,根据相机的内在函数和外在函数将 3D 点投影到图像中。但是当我在原点有一个相机指向 z 轴并且 3D 指向 z 轴下方时,它似乎在相机后面而不是在它前面。这是我的脚本,我已经检查了很多次。
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)
我唯一能想到的是,识别旋转矩阵不对应于指向负 z 轴的相机,而向上向量指向正 y 轴的方向。但我看不出情况会如何,例如我从 gluLookAt 之类的函数构造了 Rc,并在原点给它一个指向负 z 轴的相机,我会得到单位矩阵。
【问题讨论】:
-
你能解释一下你是怎么知道你的相机指向负z轴的吗?可能位置 (0,0,0) 的摄像机具有单位旋转矩阵正在查看正 z 轴而不是负 z 轴。
标签: computer-vision camera-calibration projection-matrix