You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.4 KiB
77 lines
2.4 KiB
import open3d as o3d |
|
import os |
|
import argparse |
|
import numpy as np |
|
from PIL import Image |
|
|
|
class DisplayProcessor: |
|
def __init__(self): |
|
|
|
# argv = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else [] |
|
parser = argparse.ArgumentParser() |
|
|
|
parser.add_argument( |
|
"--id", |
|
required=True, |
|
) |
|
parser.add_argument( |
|
"--mask", |
|
default=0 |
|
) |
|
|
|
args = parser.parse_args() |
|
|
|
self.id = args.id |
|
mask = args.mask |
|
out_dir = f"out.{self.id}.nomask" |
|
if mask==1: |
|
out_dir = f"out.{self.id}" |
|
|
|
self.mesh = None |
|
self.obj_path = f"/home/algo/Documents/openMVS/data/{self.id}/{out_dir}/mesh.obj" |
|
|
|
self.load_and_show() |
|
|
|
def load_and_show(self): |
|
# 加载并变换所有模型 |
|
|
|
# 加载网格 |
|
mesh = None |
|
try: |
|
mesh = o3d.io.read_triangle_mesh(self.obj_path, enable_post_processing=True) |
|
if not mesh.has_vertices(): |
|
print(f"警告: 网格无有效顶点 - {self.obj_path}") |
|
except Exception as e: |
|
print(f"加载模型失败: {self.obj_path} - {e}") |
|
|
|
if not mesh: |
|
print("没有加载到任何模型,请检查错误信息") |
|
else: |
|
# 可视化模型 |
|
print("显示模型... (按'Q'退出)") |
|
|
|
try: |
|
from packaging import version |
|
o3d_version = version.parse(o3d.__version__) |
|
# 新版本 draw_geometries 参数 |
|
if o3d_version >= version.parse("0.13.0"): |
|
o3d.visualization.draw_geometries( |
|
[mesh], |
|
window_name="模型展示", |
|
mesh_show_back_face=True, |
|
mesh_show_wireframe=False |
|
) |
|
# 旧版本 draw_geometries 参数 |
|
else: |
|
o3d.visualization.draw_geometries( |
|
[mesh], |
|
window_name="模型展示", |
|
point_show_normal=False, |
|
mesh_show_back_face=True |
|
) |
|
except Exception as e: |
|
print(f"使用 draw_geometries 可视化失败: {e}") |
|
|
|
# 主程序 |
|
if __name__ == "__main__": |
|
DisplayProcessor().load_and_show()
|
|
|