我試圖通過python進行包調整。所以我是測試非線性最小二乘模塊。然後我寫下如下代碼。我想得到正確的Pmat表示三臺攝像機的攝像機投影矩陣。但是我有一個錯誤,「ValueError:對象太深,無法使用所需數組」。SciPy的非線性最小平方
任何人都可以提供線索來解決這個問題?
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]