(image, depth, keep_edges=False, spherical=False)
| 738 | |
| 739 | |
| 740 | def create_mesh(image, depth, keep_edges=False, spherical=False): |
| 741 | import trimesh |
| 742 | from dzoedepth.utils.geometry import depth_to_points, create_triangles |
| 743 | maxsize = backbone.get_opt('depthmap_script_mesh_maxsize', 2048) |
| 744 | |
| 745 | # limit the size of the input image |
| 746 | image.thumbnail((maxsize, maxsize)) |
| 747 | |
| 748 | if not spherical: |
| 749 | pts3d = depth_to_points(depth[None]) |
| 750 | else: |
| 751 | pts3d = pano_depth_to_world_points(depth) |
| 752 | |
| 753 | pts3d = pts3d.reshape(-1, 3) |
| 754 | |
| 755 | verts = pts3d.reshape(-1, 3) |
| 756 | image = np.array(image) |
| 757 | if keep_edges: |
| 758 | triangles = create_triangles(image.shape[0], image.shape[1]) |
| 759 | else: |
| 760 | triangles = create_triangles(image.shape[0], image.shape[1], mask=~depth_edges_mask(depth)) |
| 761 | colors = image.reshape(-1, 3) |
| 762 | |
| 763 | mesh = trimesh.Trimesh(vertices=verts, faces=triangles, vertex_colors=colors) |
| 764 | |
| 765 | # rotate 90deg over X when spherical |
| 766 | if spherical: |
| 767 | angle = math.pi / 2 |
| 768 | direction = [1, 0, 0] |
| 769 | center = [0, 0, 0] |
| 770 | rot_matrix = trimesh.transformations.rotation_matrix(angle, direction, center) |
| 771 | mesh.apply_transform(rot_matrix) |
| 772 | |
| 773 | return mesh |
no test coverage detected