示例#1
0
def make_mesh_2d(all_lines, O, R, g, n_points_w=None):
    all_letters = np.concatenate([line.letters for line in all_lines])
    corners_2d = np.concatenate([letter.corners() for letter in all_letters]).T
    assert corners_2d.shape[0] == 2 and corners_2d.shape[1] == 4 * len(all_letters)
    corners = image_to_focal_plane(corners_2d, O)
    assert corners.shape[0] == 3
    t0s = np.full((corners.shape[1],), np.inf, dtype=np.float64)
    # Get the (X,Y,Z) on the GCS surface
    corners_t, corners_XYZ = newton.t_i_k(R, g, corners, t0s)

    corners_X, _, corners_Z = corners_XYZ
    relative_Z_error = np.abs(g(corners_X) - corners_Z) / corners_Z
    # Only leave corners that are not weird
    # such as: |g(X) - Z| should be close, |Z| should not be extremely large, t < 0 (the GCS should be in front of the camera)
    corners_XYZ = corners_XYZ[:, np.logical_and(relative_Z_error <= 0.02,
                                                abs(corners_Z) < 1e6,
                                                corners_t < 0)]
    corners_X, _, _ = corners_XYZ

    debug_print_points('corners.png', corners_2d)

    if lib.debug:
        try:
            import matplotlib.pyplot as plt
            ax = plt.axes()
            box_XY = Crop.from_points(corners_XYZ[:2]).expand(0.01)
            x_min, y_min, x_max, y_max = box_XY

            for y in np.linspace(y_min, y_max, 3):
                xs = np.linspace(x_min, x_max, 200)
                ys = np.full(200, y)
                zs = g(xs)
                points = np.stack([xs, ys, zs])
                points_r = inv(R).dot(points) + Of[:, newaxis]
                ax.plot(points_r[0], points_r[2])

            base_xs = np.array([corners[0].min(), corners[0].max()])
            base_zs = np.array([-3270.5, -3270.5])
            ax.plot(base_xs, base_zs)
            ax.set_aspect('equal')
            plt.savefig('dewarp/camera.png')
        except Exception as e:
            print(e)
            import IPython
            IPython.embed()

    if g.split():
        meshes = [
            make_mesh_2d_indiv(all_lines, corners_XYZ[:, corners_X <= g.T], O, R, g, n_points_w=n_points_w),
            make_mesh_2d_indiv(all_lines, corners_XYZ[:, corners_X > g.T], O, R, g, n_points_w=n_points_w),
        ]
    else:
        meshes = [make_mesh_2d_indiv(all_lines, corners_XYZ, O, R, g, n_points_w=n_points_w)]

    for i, mesh in enumerate(meshes):
        # debug_print_points('mesh{}.png'.format(i), mesh, step=20)
        pass

    return meshes
示例#2
0
def E_align_project(R, g, all_points, t0s_idx):
    global E_align_t0s
    if len(E_align_t0s) <= t0s_idx:
        E_align_t0s.extend([None] * (t0s_idx - len(E_align_t0s) + 1))
    if E_align_t0s[t0s_idx] is None:
        E_align_t0s[t0s_idx] = np.full((all_points.shape[1],), np.inf)

    return newton.t_i_k(R, g, all_points, E_align_t0s[t0s_idx])
示例#3
0
def E_str_project(R, g, base_points, t0s_idx):
    global E_str_t0s
    if len(E_str_t0s) <= t0s_idx:
        E_str_t0s.extend([None] * (t0s_idx - len(E_str_t0s) + 1))
    if E_str_t0s[t0s_idx] is None:
        E_str_t0s[t0s_idx] = \
            [np.full((points.shape[1],), np.inf) for points in base_points]

    # print([point.shape for point in base_points])
    # print([t0s.shape for t0s in E_str_t0s])

    return [newton.t_i_k(R, g, points, t0s) \
            for points, t0s in zip(base_points, E_str_t0s[t0s_idx])]