For perspective projection with given camera matrices and rotation and translation we can compute the 2D pixel coordinate of a 3D point.
using the projection matrix,
$$ P = K [R | t] $$
where $K$ is intrinsic camera matrix, $R$ is rotation $t$ is translation. The projection is simple matrix multiplication $x = P X $.
It is also known we can add an extra row to the matrices above to get a $4 \times 4$ projection matrix.
$$ \tilde{P} = \left[\begin{array}{cc} K & 0 \\ 0^T & 1 \end{array}\right] \left[\begin{array}{cc} R & t \\ 0^T & 1 \end{array}\right] $$
I am trying to do the reverse. In Computer Vision Alg and Application book, pg. 54, Szeliski says we can invert $\tilde{P}$ to get the ray from camera center that'll pass through all possible points. I tried this approach for a camera with known calibration, for given pixel (200,200),
K = [[ 282.363047, 0., 166.21515189],
[ 0., 280.10715905, 108.05494375],
[ 0., 0., 1. ]]
K = np.array(K)
R = np.eye(3)
t = np.array([[0],[1],[0]])
P = K.dot(np.hstack((R,t)))
P = np.vstack((P,[0,0,0,1]))
print P
x = np.array([200,200,10,1])
X = np.dot(lin.inv(P),x)
print X
to get a direction, which gives me
[-5.17826796 -3.14361632 9. 1. ]
The camera was merely translated one unit in Y direction, but the resulting vector seems to be pointing in the wrong direction. Szeliski talks about a disparity which I am not sure how to encode in the pixel input. Any help on this approach, or alternative approaches to calculate the ray for given pixel, matrix with known orientation and $K$ would be helpful.
