PCV
PCV copied to clipboard
possible error in camera.py
to factorize the camera matrix P line 26 to line 41
def factor(self):
""" Factorize the camera matrix into K,R,t as P = K[R|t]. """
# factor first 3*3 part
K,R = linalg.rq(self.P[:,:3])
# make diagonal of K positive
T = diag(sign(diag(K)))
if linalg.det(T) < 0:
T[1,1] *= -1
self.K = dot(K,T)
self.R = dot(T,R) # T is its own inverse
self.t = dot(linalg.inv(self.K),self.P[:,3])
return self.K, self.R, self.t
base on the example in the book on page 108
import camera
K = array([[1000,0,500],[0,1000,300],[0,0,1]])
tmp = camera.rotation_matrix([0,0,1])[:3,:3]
Rt = hstack((tmp,array([[50],[40],[30]])))
cam = camera.Camera(dot(K,Rt))
print K,Rt
print cam.factor()
K,R = linalg.rq(self.P[:,:3]) returns K = [[ 1000., 0., 500.], [ 0., -1000., 300.], [ 0., 0., 1.]] T = diag(sign(diag(K))) returns T = [1, -1, 1] linalg.det(T) returns -1.0 then T[1,1] *= -1 will not make diagonal of K positive