Skip to content

Commit 5e3cabc

Browse files
committed
Update load_scan function to support .obj.
1 parent 40b0630 commit 5e3cabc

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

utils.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ def load_landmarks(landmark_path: str,
712712

713713
return landmarks
714714

715-
def load_scan(scan_path):
715+
def load_scan(scan_path, return_vertex_colors=False):
716716
"""
717717
Load scan given its scan_path using open3d.
718718
Scan can be defined as:
@@ -725,13 +725,16 @@ def load_scan(scan_path):
725725

726726
ext = scan_path.split(".")[-1]
727727
ext_extended = f"{scan_path.split('.')[-2]}.{ext}"
728-
supported_extensions = [".ply",".ply.gz"]
728+
supported_extensions = [".ply",".ply.gz", ".obj"]
729729

730-
if ext == "ply":
730+
if ext in ["ply", "obj"]:
731731
scan = o3d.io.read_triangle_mesh(scan_path)
732732
scan_vertices = np.asarray(scan.vertices)
733733
scan_faces = np.asarray(scan.triangles)
734734
scan_faces = scan_faces if scan_faces.shape[0] > 0 else None
735+
if return_vertex_colors:
736+
scan_vertex_colors = np.asarray(scan.vertex_colors)
737+
print(scan_vertex_colors.shape)
735738

736739
elif ext_extended == "ply.gz":
737740
with gzip.open(scan_path, 'rb') as gz_file:
@@ -748,14 +751,19 @@ def load_scan(scan_path):
748751
scan_vertices = np.asarray(scan.vertices)
749752
scan_faces = np.asarray(scan.triangles)
750753
scan_faces = scan_faces if scan_faces.shape[0] > 0 else None
754+
if return_vertex_colors:
755+
scan_vertex_colors = np.asarray(scan.vertex_colors)
751756
os.remove(temp_ply_path)
752757

753758
else:
754759
supported_extensions_str = ', '.join(supported_extensions)
755760
msg = f"Scan extensions supported: {supported_extensions_str}. Got .{ext}."
756761
raise ValueError(msg)
757762

758-
return scan_vertices, scan_faces
763+
if return_vertex_colors:
764+
return scan_vertices, scan_vertex_colors
765+
else:
766+
return scan_vertices, scan_faces
759767

760768
def load_fit(path):
761769

0 commit comments

Comments
 (0)