我寫了一個簡單的腳本,將3D點投影到基於相機內部函數和外部函數的圖像上。但是當我在原點指向Z軸的相機和3D指向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)
我可以想到的唯一事情是,確定旋轉矩陣不對應於相機朝下負z軸與所述y軸正方向上的向上矢量。但我不明白這是不是這種情況,例如我已經從像gluLookAt這樣的函數構造Rc,並給它一個相機在原點指向負Z軸我會得到單位矩陣。
你能解釋一下我怎麼知道你的相機指向負z軸?也許一個相機在位置(0,0,0)與身份旋轉矩陣正在看加Z軸,而不是負面的。 –