Ejemplo n.º 1
0
def get_3DSV(mesh):
    from opendr.camera import ProjectPoints
    from opendr.renderer import DepthRenderer
    WIDTH, HEIGHT = 250, 250

    camera = ProjectPoints(v=mesh.vertices,
                           f=np.array([WIDTH, WIDTH]),
                           c=np.array([WIDTH, HEIGHT]) / 2.,
                           t=np.array([0, 0, 2.5]),
                           rt=np.array([np.pi, 0, 0]),
                           k=np.zeros(5))
    frustum = {'near': 1., 'far': 10., 'width': WIDTH, 'height': HEIGHT}
    rn = DepthRenderer(camera=camera,
                       frustum=frustum,
                       f=mesh.faces,
                       overdraw=False)

    points3d = camera.unproject_depth_image(rn.r)
    points3d = points3d[points3d[:, :, 2] > np.min(points3d[:, :, 2]) + 0.01]

    # print('sampled {} points.'.format(points3d.shape[0]))
    return points3d
Ejemplo n.º 2
0
def get_3DSV(mesh):
    from opendr.camera import ProjectPoints
    from opendr.renderer import DepthRenderer
    WIDTH, HEIGHT = 250, 250

    rt = R.from_euler('xyz', [np.pi, 0, 0]).as_rotvec()
    rt_mat = R.from_euler('xyz', [np.pi, 0, 0]).as_matrix()
    camera = ProjectPoints(v=mesh.vertices, f=np.array([WIDTH, WIDTH]), c=np.array([WIDTH, HEIGHT]) / 2.,
                           t=np.array([0, 0, 3.0]), rt=rt, k=np.zeros(5))
    frustum = {'near': 1., 'far': 10., 'width': WIDTH, 'height': HEIGHT}
    rn = DepthRenderer(camera=camera, frustum=frustum, f=mesh.faces, overdraw=False)

    # import cv2
    depth_image = rn.depth_image.copy()
    mask = depth_image < depth_image.max() - 0.01
    depth_image[~mask] = 0
    depth_image[mask] = 255 - (depth_image[mask] - depth_image[mask].min()) / (depth_image[mask].max() - depth_image[mask].min()) * 255

    points3d = camera.unproject_depth_image(rn.r)
    mask = points3d[:, :, 2] > np.min(points3d[:, :, 2]) + 0.01

    points3d = points3d[mask]

    return points3d, depth_image