|
|
|
@ -1928,64 +1928,6 @@ class ModelProcessor: |
|
|
|
depth = render.render_to_depth_image(z_in_view_space=True) |
|
|
|
depth = render.render_to_depth_image(z_in_view_space=True) |
|
|
|
return np.asarray(depth) |
|
|
|
return np.asarray(depth) |
|
|
|
|
|
|
|
|
|
|
|
def sort_vertices(vertices_original): |
|
|
|
|
|
|
|
return sorted( |
|
|
|
|
|
|
|
(v for v in vertices_original), |
|
|
|
|
|
|
|
key=lambda v: (v.co.x, v.co.y, v.co.z) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _flag_model(self, camera_data, face_points): |
|
|
|
|
|
|
|
"""标记可见顶点""" |
|
|
|
|
|
|
|
vertex_visible = [] |
|
|
|
|
|
|
|
vertex_occlusion = [] |
|
|
|
|
|
|
|
depth_images = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
render = o3d.visualization.rendering.OffscreenRenderer(camera_data['width'], camera_data['height']) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
material = o3d.visualization.rendering.MaterialRecord() |
|
|
|
|
|
|
|
render.scene.add_geometry("mesh", self.mesh, material) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 生成深度图 |
|
|
|
|
|
|
|
depth_image = self._gen_depth_image(camera_data, render) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 计算可见性 |
|
|
|
|
|
|
|
R = self.qvec2rotmat(camera_data['qvec']).T |
|
|
|
|
|
|
|
eye = -R @ camera_data['tvec'] |
|
|
|
|
|
|
|
# eye = camera_data['tvec'] |
|
|
|
|
|
|
|
# final_visible_list, final_occlusion_list, final_vertex_difference_list = self._compute_vertex_in_frustum( |
|
|
|
|
|
|
|
final_visible_list, final_occlusion_list = self._compute_vertex_in_frustum( |
|
|
|
|
|
|
|
camera_data['fx'], camera_data['fy'], |
|
|
|
|
|
|
|
camera_data['cx'], camera_data['cy'], |
|
|
|
|
|
|
|
R, eye, |
|
|
|
|
|
|
|
camera_data['height'], camera_data['width'], |
|
|
|
|
|
|
|
depth_image,camera_data['qvec'], camera_data['tvec'] |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
print("_flag_model", len(final_occlusion_list), len(self.mesh.vertices), len(self.mesh.vertex_colors)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 获取三角形面片数组 |
|
|
|
|
|
|
|
triangles = np.asarray(self.mesh.triangles) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
face_visible_bitmap = np.zeros(len(triangles), dtype=bool) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 遍历所有面片 |
|
|
|
|
|
|
|
for face_idx, face in enumerate(triangles): |
|
|
|
|
|
|
|
v0, v1, v2 = face |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
face_visible_bitmap[face_idx] = any([ # any all |
|
|
|
|
|
|
|
final_visible_list[v0], |
|
|
|
|
|
|
|
final_visible_list[v1], |
|
|
|
|
|
|
|
final_visible_list[v2] |
|
|
|
|
|
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
shrunk_visibility = self._shrink_face_visibility(face_visible_bitmap, 6) # 6 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expanded_visibility = self._expand_face_visibility(face_visible_bitmap, 30) |
|
|
|
|
|
|
|
shrunk_visibility2 = self._shrink_face_visibility(face_visible_bitmap, 50) |
|
|
|
|
|
|
|
expanded_edge = expanded_visibility & ~shrunk_visibility2 |
|
|
|
|
|
|
|
delete_edge = face_visible_bitmap & ~shrunk_visibility |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return shrunk_visibility, expanded_edge, delete_edge |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _flag_contour(self, camera_data, face_points): |
|
|
|
def _flag_contour(self, camera_data, face_points): |
|
|
|
"""标记可见顶点""" |
|
|
|
"""标记可见顶点""" |
|
|
|
vertex_visible = [] |
|
|
|
vertex_visible = [] |
|
|
|
@ -2075,94 +2017,6 @@ class ModelProcessor: |
|
|
|
face_visible_bitmap = np.ones(len(triangles), dtype=bool) # 临时填充 |
|
|
|
face_visible_bitmap = np.ones(len(triangles), dtype=bool) # 临时填充 |
|
|
|
return face_visible_bitmap, face_edge |
|
|
|
return face_visible_bitmap, face_edge |
|
|
|
|
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
def _mask_face_occlusion(self): |
|
|
|
|
|
|
|
# 读取相机数据 |
|
|
|
|
|
|
|
cameras = read_cameras_text(os.path.join(self.pose_path, "cameras.txt")) |
|
|
|
|
|
|
|
images = read_images_text(os.path.join(self.pose_path, "images.txt")) |
|
|
|
|
|
|
|
# cameras = read_cameras_text(os.path.join(self.pose_path, "backup_cameras.txt")) |
|
|
|
|
|
|
|
# images = read_images_text(os.path.join(self.pose_path, "backup_images.txt")) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
face_points_sorted_path = os.path.join(self.pose_path, "face_points_sorted.txt") |
|
|
|
|
|
|
|
print("face_points_sorted_path=", face_points_sorted_path) |
|
|
|
|
|
|
|
#face_points = read_int_text(face_points_sorted_path) |
|
|
|
|
|
|
|
face_points = read_indices_from_file(face_points_sorted_path) |
|
|
|
|
|
|
|
# face_points = {} |
|
|
|
|
|
|
|
camera_data = {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for img in images.values(): |
|
|
|
|
|
|
|
if self.mask_image == img.name[:-4]: |
|
|
|
|
|
|
|
camera = cameras[img.camera_id] |
|
|
|
|
|
|
|
camera_data = { |
|
|
|
|
|
|
|
"qvec": img.qvec, |
|
|
|
|
|
|
|
"tvec": img.tvec, |
|
|
|
|
|
|
|
"fx": camera.params[0], |
|
|
|
|
|
|
|
"fy": camera.params[1], |
|
|
|
|
|
|
|
"cx": camera.params[2], |
|
|
|
|
|
|
|
"cy": camera.params[3], |
|
|
|
|
|
|
|
"width": camera.width, |
|
|
|
|
|
|
|
"height": camera.height, |
|
|
|
|
|
|
|
"name": img.name[:-4] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# print(face_points) |
|
|
|
|
|
|
|
self._flag_model(camera_data, face_points) |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _mask_occlusion(self): |
|
|
|
|
|
|
|
# 读取相机数据 |
|
|
|
|
|
|
|
cameras = read_cameras_text(os.path.join(self.pose_path, "cameras.txt")) |
|
|
|
|
|
|
|
images = read_images_text(os.path.join(self.pose_path, "images.txt")) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
camera_data = {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
countour_faces_dict = {} |
|
|
|
|
|
|
|
visible_faces_dict = {} |
|
|
|
|
|
|
|
edge_faces_dict = {} |
|
|
|
|
|
|
|
delete_edge_faces_dict = {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
total_start = time.time() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
n = 0 |
|
|
|
|
|
|
|
for img in images.values(): |
|
|
|
|
|
|
|
camera = cameras[img.camera_id] |
|
|
|
|
|
|
|
camera_data = { |
|
|
|
|
|
|
|
"qvec": img.qvec, |
|
|
|
|
|
|
|
"tvec": img.tvec, |
|
|
|
|
|
|
|
"fx": camera.params[0], |
|
|
|
|
|
|
|
"fy": camera.params[1], |
|
|
|
|
|
|
|
"cx": camera.params[2], |
|
|
|
|
|
|
|
"cy": camera.params[3], |
|
|
|
|
|
|
|
"width": camera.width, |
|
|
|
|
|
|
|
"height": camera.height, |
|
|
|
|
|
|
|
"name": img.name[:-4] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
img_name = img.name[:-4] |
|
|
|
|
|
|
|
# if (img_name!="73_8" and img_name!="52_8" and img_name!="62_8"): |
|
|
|
|
|
|
|
# if (img_name!="52_8" and img_name!="62_8"): |
|
|
|
|
|
|
|
# if (img_name!="52_8"): |
|
|
|
|
|
|
|
# continue |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
start_time = time.time() |
|
|
|
|
|
|
|
face_visibility, face_edge, face_delete_edge = self._flag_model(camera_data, None) |
|
|
|
|
|
|
|
processing_time = time.time() - start_time |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
visible_faces = np.where(face_visibility)[0].tolist() |
|
|
|
|
|
|
|
visible_faces_dict[img.name[:-4]] = visible_faces |
|
|
|
|
|
|
|
edge_faces_dict[img.name[:-4]] = np.where(face_edge)[0].tolist() |
|
|
|
|
|
|
|
delete_edge_faces_dict[img.name[:-4]] = np.where(face_delete_edge)[0].tolist() |
|
|
|
|
|
|
|
n += 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(f"图像={img_name},耗时={processing_time:.2f}秒,可见面数={len(visible_faces)}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
total_time = time.time() - total_start |
|
|
|
|
|
|
|
print(f"所有图像处理完成,总耗时: {total_time:.2f}秒") |
|
|
|
|
|
|
|
print(f"平均每张图像耗时: {total_time/len(images):.2f}秒") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.save_occlusion_data(visible_faces_dict, edge_faces_dict, delete_edge_faces_dict, self.asset_dir) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {"result1": visible_faces_dict, "result2": edge_faces_dict, "result3": delete_edge_faces_dict} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def save_occlusion_data(self, result1: Dict[str, List[int]], |
|
|
|
def save_occlusion_data(self, result1: Dict[str, List[int]], |
|
|
|
result2: Dict[str, List[int]], |
|
|
|
result2: Dict[str, List[int]], |
|
|
|
result3: Dict[str, List[int]], |
|
|
|
result3: Dict[str, List[int]], |
|
|
|
|