套件调整使相机参数更糟

时间:2019-04-02 07:46:55

标签: scipy computer-vision

我正在尝试将here中所述的包调整应用于我自己生成的随机数据。但是,运行优化算法后,该参数与我用来创建数据的地面真实参数相比变得更糟。我的代码如下所示:

我的数据生成:

        <!-- FRHip & Leg -->
        <Transform DEF="FR" rotation="0 0 1 0">
            <Transform rotation="0 1 0 -1.047">
                <Transform translation="1.366 0 0">
                    <Shape USE="Octahedron" />
                    <Transform translation="-0.5 0 0">
                        <Shape USE="Axes" />
                    </Transform>
                </Transform>
            </Transform>

            <!-- FRKnee & Low Leg -->
            <Transform rotation="0 1 0 -1.047">
                <Transform rotation="0 0 1 -0.785">
                    <Transform translation="1.82 1.32 0">
                        <Shape USE="Octahedron" />
                        <Transform translation="-0.5 0 0">
                            <Shape USE="Axes" />
                        </Transform>
                    </Transform>
                </Transform>
            </Transform>

            <!-- FRAnkle & Foot -->
            <Transform rotation="0 1 0 -1.047">
                <Transform rotation="0 0 1 -1.57">
                    <Transform translation="1.2 2.566 0">
                        <Shape USE="Octahedron" />
                        <Transform translation="-0.5 0 0">
                            <Shape USE="Axes" />
                        </Transform>
                    </Transform>
                </Transform>
            </Transform>
        </Transform>

        <Transform USE="FR" />

然后我像这样调用优化过程:

N = 10000
points_3d = np.random.uniform(-1, 1, size=(N, 3))


my_camera_params_gt = np.array(np.array([[ 1.57415159e-02, -1.27909362e-02, -4.40084981e-03,  4.96590616e+00,
           4.89248613e+00,  6.12022403e+00, 3.99751526e+02, -3.17706439e-07, 5.88204905e-13],
          [ 1.59773241e-02, -2.52244646e-02, -9.40014165e-03,  4.99143323e+00,
           4.87811951e+00,  5.71901331e+00,  4.02017534e+02, -3.78047656e-07, 9.30743117e-13]]))
my_camera_params_initial = my_camera_params_gt + my_camera_params_gt * np.random.normal(0,0.1, size = my_camera_params_gt.shape)

my_points_3d_gt = points_3d
my_points_3d_initial = my_points_3d_gt + my_points_3d_gt * np.random.normal(0,0.1, size = my_points_3d_gt.shape)

n_points = my_points_3d_gt.shape[0]
n_observations = n_points * 2
my_camera_indices = np.concatenate([np.zeros((n_points), dtype=np.int16), np.ones((n_points), dtype=np.int16)])
my_point_indices = np.concatenate([np.arange(n_points, dtype=np.int16), np.arange(n_points, dtype=np.int16)])


my_points_2d_gt = project(my_points_3d_gt[my_point_indices], my_camera_params_gt[my_camera_indices])
my_points_2d = my_points_2d_gt + my_points_2d_gt * np.random.normal(0,0.01, size = my_points_2d_gt.shape)

n_cameras = my_camera_params_gt.shape[0]
n_points = my_points_3d_gt.shape[0]

具有链接中定义的所有功能。

但是,如果我要比较基本结果和优化结果:

x0 = np.hstack((my_camera_params_initial.ravel(), my_points_3d_initial.ravel()))
A = bundle_adjustment_sparsity(n_cameras, n_points, my_camera_indices, my_point_indices)
res = least_squares(fun, x0, jac_sparsity=A, verbose=2, x_scale='jac', ftol=1e-5, method='trf',
                    args=(n_cameras, n_points, my_camera_indices, my_point_indices, my_points_2d))

优化结果比最初的猜测要差。 怎么可能呢?

0 个答案:

没有答案