我试着用python做包调整。所以我要测试非线性最小二乘模。
然后我写了如下代码。我想得到正确的Pmat表示三个摄像机的摄像机投影矩阵。但我有一个错误,“ValueError:object too deep for desired array”。
有谁能提供线索来解决这个问题吗?
当做,
杨锦浩。

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]

最佳答案

我的第一个猜测是:leatsq不喜欢矩阵,
使用数组和np.dot,或者在返回之前转换np.asarray(err),可能在残差函数中将p转换为矩阵。
混合矩阵和数组可能是一个令人痛苦的跟踪。

关于python - SciPy的非线性最小二乘,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3965995/

10-12 21:13