Dear All.
I tried to do bundle adjustment by python. So I'm test non-linear least square module. Then I wrote code like below. I want to get right Pmat represents camera projection matrix for three cameras. But I have an error,"ValueError: object too deep for desired array".
Anyone who can give clue to solve this issue?
Regards, Jinho Yoo.
from math import* from numpy import *
import pylab as p from scipy.optimize
import leastsq
Projected_x = \ mat([[ -69.69 , 255.3825, 1. ],
[ -69.69 , 224.6175, 1. ],
[-110.71 , 224.6175, 1. ],
[-110.71 , 255.3825, 1. ],
[ 709.69 , 224.6175, 1. ],
[ 709.69 , 255.3825, 1. ],
[ 750.71 , 255.3825, 1. ],
[ 750.71 , 224.6175, 1. ]])
Projected_x = Projected_x.transpose()
Pmat = \ mat( [[ 5.79746167e+02, 0.00000000e+00, 3.20000000e+02, 0.00000000e+00],
[ 0.00000000e+00, 4.34809625e+02, 2.40000000e+02, 0.00000000e+00],
[ 0.00000000e+00, 0.00000000e+00, 1.00000000e+00, 0.00000000e+00] ] )
reconst_X = \ mat([[-0.95238194, -0.58146697, 0.61506506, 0.00539229],
[-0.99566105, -0.76178453, 0.72451719, 0.00502341],
[-1.15401215, -0.81736486, 0.79417098, 0.00546999],
[-1.11073304, -0.6370473 , 0.68471885, 0.00583888],
[ 2.71283058, 2.34190758, -1.80448545, -0.00612243],
[ 2.7561097 , 2.52222514, -1.91393758, -0.00575354],
[ 2.9144608 , 2.57780547, -1.98359137, -0.00620013],
[ 2.87118168, 2.39748791, -1.87413925, -0.00656901]])
def residuals(p, y, x):
err = y - p*x.transpose()
err = err * err.transpose()
return err
p0 = Pmat
plsq = leastsq(residuals, p0, args=(Projected_x, reconst_X ) )
print plsq[0]