Ejemplo n.º 1
0
def get_colored_mesh_from_pointcloud(player3d, img, cam):

    player2d, depth = cam.project(player3d, dtype=np.int32)
    colors = img[player2d[:, 1], player2d[:, 0]]

    faces = mesh_utils.triangulate_depthmap_points(player2d, depth, depth_thresh=0.1)
    ply_data = io.numpy_to_ply(player3d, colors*255)
    return ply_data, faces
Ejemplo n.º 2
0
        min_u, max_u = int(np.min(np.round(
            uv[:, 0]))), int(np.max(np.round(uv[:, 0]))) + 1
        min_v, max_v = int(np.min(np.round(
            uv[:, 1]))), int(np.max(np.round(uv[:, 1]))) + 1
        crop = img[min_v:max_v, min_u:max_u, :]

        tmp = uv.copy()
        tmp[:, 0] -= np.min(np.round(uv[:, 0]))
        tmp[:, 1] -= np.min(np.round(uv[:, 1]))

        uvs_atlas.append(tmp)
        textures_atlas.append(crop)

        frame_mesh_points = np.vstack((frame_mesh_points, _vertices))
        frame_mesh_faces = np.vstack((frame_mesh_faces, _faces + cnt))
        cnt += _vertices.shape[0]

    atlas, final_uvs = misc_utils.pack_textures(textures_atlas,
                                                uvs_atlas,
                                                n_rows=1)

    texture_name = join(db.path_to_dataset, 'scene3d',
                        '{0}.jpg'.format(basename))
    cv2.imwrite(join(texture_name), atlas[:, :, (2, 1, 0)] * 255)

    ply_out = io.numpy_to_ply(frame_mesh_points)
    io.write_obj(
        join(db.path_to_dataset, 'scene3d', '{0}.obj'.format(basename)),
        ply_out, list(frame_mesh_faces), final_uvs, texture_name)
Ejemplo n.º 3
0
        p0 = np.array([[cx, cy, cz]])
        n0 = cam.get_direction()
        origin = cam.get_position().T
        n0[1] = 0.0
        n0 /= np.linalg.norm(n0)

        player_points2d = np.vstack((J, I)).T
        p3 = cam.unproject(player_points2d, 0.5)
        direction = p3.T - np.tile(origin, (p3.shape[1], 1))
        direction /= np.tile(
            np.linalg.norm(direction, axis=1)[:, np.newaxis], (1, 3))
        billboard = geom_utils.ray_plane_intersection(origin, direction, p0,
                                                      n0)
        billboard_2d, billboard_depth = cam.project(billboard,
                                                    dtype=np.float32)

        depthmap[I, J] += billboard_depth
        depthmap *= mask

        z_buffer = np.zeros((db.shape[0], db.shape[1]))
        z_buffer[y1:y2, x1:x2] = depthmap
        I, J = (z_buffer > 0).nonzero()

        player3d = cam.depthmap_to_pointcloud(z_buffer)
        color3d = img[I, J, :]

        ply_data = io.numpy_to_ply(player3d, color3d * 255)
        io.write_ply(
            join(db.path_to_dataset, 'players', 'meshes',
                 player_name + '.ply'), ply_data)