|
|
|
@ -1427,13 +1427,15 @@ class ModelProcessor: |
|
|
|
# ============ 法线夹角过滤结束 ============ |
|
|
|
# ============ 法线夹角过滤结束 ============ |
|
|
|
|
|
|
|
|
|
|
|
# 使用与CPU版本相同的后续处理 |
|
|
|
# 使用与CPU版本相同的后续处理 |
|
|
|
shrunk_visibility = self._shrink_face_visibility(face_visible.cpu().numpy(), 12) |
|
|
|
shrunk_visibility = self._shrink_face_visibility(face_visible.cpu().numpy(), 6) |
|
|
|
expanded_visibility = self._expand_face_visibility(face_visible.cpu().numpy(), 0) |
|
|
|
expanded_visibility = self._expand_face_visibility(face_visible.cpu().numpy(), 0) |
|
|
|
shrunk_visibility2 = self._shrink_face_visibility(face_visible.cpu().numpy(), 0) |
|
|
|
shrunk_visibility2 = self._shrink_face_visibility(face_visible.cpu().numpy(), 0) |
|
|
|
|
|
|
|
shrunk_visibility3 = self._shrink_face_visibility(face_visible.cpu().numpy(), 100) |
|
|
|
expanded_edge = expanded_visibility & ~shrunk_visibility2 |
|
|
|
expanded_edge = expanded_visibility & ~shrunk_visibility2 |
|
|
|
delete_edge = face_visible.cpu().numpy() & ~shrunk_visibility |
|
|
|
delete_edge = face_visible.cpu().numpy() & ~shrunk_visibility |
|
|
|
|
|
|
|
delete_edge2 = face_visible.cpu().numpy() & ~shrunk_visibility3 |
|
|
|
|
|
|
|
|
|
|
|
return shrunk_visibility, expanded_edge, delete_edge, face_normal_visible |
|
|
|
return shrunk_visibility, expanded_edge, delete_edge, delete_edge2, face_normal_visible |
|
|
|
|
|
|
|
|
|
|
|
""" |
|
|
|
""" |
|
|
|
def _gen_depth_image_gpu(self, cam_data, render): |
|
|
|
def _gen_depth_image_gpu(self, cam_data, render): |
|
|
|
@ -1464,6 +1466,7 @@ class ModelProcessor: |
|
|
|
visible_faces_dict = {} |
|
|
|
visible_faces_dict = {} |
|
|
|
edge_faces_dict = {} |
|
|
|
edge_faces_dict = {} |
|
|
|
delete_edge_faces_dict = {} |
|
|
|
delete_edge_faces_dict = {} |
|
|
|
|
|
|
|
delete_edge_faces_dict2 = {} |
|
|
|
face_normal_visible_dict = {} |
|
|
|
face_normal_visible_dict = {} |
|
|
|
|
|
|
|
|
|
|
|
total_start = time.time() |
|
|
|
total_start = time.time() |
|
|
|
@ -1490,13 +1493,14 @@ class ModelProcessor: |
|
|
|
# continue |
|
|
|
# continue |
|
|
|
|
|
|
|
|
|
|
|
start_time = time.time() |
|
|
|
start_time = time.time() |
|
|
|
face_visibility, face_edge, face_delete_edge, face_normal_visible = self._flag_model_gpu(camera_data) |
|
|
|
face_visibility, face_edge, face_delete_edge, face_delete_edge2, face_normal_visible = self._flag_model_gpu(camera_data) |
|
|
|
processing_time = time.time() - start_time |
|
|
|
processing_time = time.time() - start_time |
|
|
|
|
|
|
|
|
|
|
|
visible_faces = np.where(face_visibility)[0].tolist() |
|
|
|
visible_faces = np.where(face_visibility)[0].tolist() |
|
|
|
visible_faces_dict[img_name] = visible_faces |
|
|
|
visible_faces_dict[img_name] = visible_faces |
|
|
|
edge_faces_dict[img_name] = np.where(face_edge)[0].tolist() |
|
|
|
edge_faces_dict[img_name] = np.where(face_edge)[0].tolist() |
|
|
|
delete_edge_faces_dict[img_name] = np.where(face_delete_edge)[0].tolist() |
|
|
|
delete_edge_faces_dict[img_name] = np.where(face_delete_edge)[0].tolist() |
|
|
|
|
|
|
|
delete_edge_faces_dict2[img_name] = np.where(face_delete_edge2)[0].tolist() |
|
|
|
face_normal_visible_dict[img_name] = np.where(face_normal_visible.cpu().numpy())[0].tolist() |
|
|
|
face_normal_visible_dict[img_name] = np.where(face_normal_visible.cpu().numpy())[0].tolist() |
|
|
|
|
|
|
|
|
|
|
|
print(f"图像 {img_name} 处理完成,耗时: {processing_time:.2f}秒,可见面数量{len(visible_faces)}") |
|
|
|
print(f"图像 {img_name} 处理完成,耗时: {processing_time:.2f}秒,可见面数量{len(visible_faces)}") |
|
|
|
@ -1505,13 +1509,14 @@ class ModelProcessor: |
|
|
|
print(f"所有图像处理完成,总耗时: {total_time:.2f}秒") |
|
|
|
print(f"所有图像处理完成,总耗时: {total_time:.2f}秒") |
|
|
|
print(f"平均每张图像耗时: {total_time/len(images):.2f}秒") |
|
|
|
print(f"平均每张图像耗时: {total_time/len(images):.2f}秒") |
|
|
|
|
|
|
|
|
|
|
|
self.save_occlusion_data(visible_faces_dict, edge_faces_dict, delete_edge_faces_dict, face_normal_visible_dict, self.asset_dir) |
|
|
|
self.save_occlusion_data(visible_faces_dict, edge_faces_dict, delete_edge_faces_dict, delete_edge_faces_dict2, face_normal_visible_dict, self.asset_dir) |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
"result1": visible_faces_dict, |
|
|
|
"result1": visible_faces_dict, |
|
|
|
"result2": edge_faces_dict, |
|
|
|
"result2": edge_faces_dict, |
|
|
|
"result3": delete_edge_faces_dict, |
|
|
|
"result3": delete_edge_faces_dict, |
|
|
|
"result4": face_normal_visible_dict |
|
|
|
"result4": delete_edge_faces_dict2, |
|
|
|
|
|
|
|
"result5": face_normal_visible_dict |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#""" |
|
|
|
#""" |
|
|
|
@ -2098,6 +2103,7 @@ class ModelProcessor: |
|
|
|
result2: Dict[str, List[int]], |
|
|
|
result2: Dict[str, List[int]], |
|
|
|
result3: Dict[str, List[int]], |
|
|
|
result3: Dict[str, List[int]], |
|
|
|
result4: Dict[str, List[int]], |
|
|
|
result4: Dict[str, List[int]], |
|
|
|
|
|
|
|
result5: Dict[str, List[int]], |
|
|
|
base_path: str) -> None: |
|
|
|
base_path: str) -> None: |
|
|
|
""" |
|
|
|
""" |
|
|
|
保存遮挡数据到文件 |
|
|
|
保存遮挡数据到文件 |
|
|
|
@ -2133,8 +2139,12 @@ class ModelProcessor: |
|
|
|
for image_name, face_list in result3.items(): |
|
|
|
for image_name, face_list in result3.items(): |
|
|
|
delete_edge_faces_map[image_name] = set(face_list) |
|
|
|
delete_edge_faces_map[image_name] = set(face_list) |
|
|
|
|
|
|
|
|
|
|
|
face_normal_visible_map: Dict[str, Set[int]] = {} |
|
|
|
delete_edge_faces_map2: Dict[str, Set[int]] = {} |
|
|
|
for image_name, face_list in result4.items(): |
|
|
|
for image_name, face_list in result4.items(): |
|
|
|
|
|
|
|
delete_edge_faces_map2[image_name] = set(face_list) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
face_normal_visible_map: Dict[str, Set[int]] = {} |
|
|
|
|
|
|
|
for image_name, face_list in result5.items(): |
|
|
|
face_normal_visible_map[image_name] = set(face_list) |
|
|
|
face_normal_visible_map[image_name] = set(face_list) |
|
|
|
|
|
|
|
|
|
|
|
# 保存 visible_faces_map |
|
|
|
# 保存 visible_faces_map |
|
|
|
@ -2181,16 +2191,27 @@ class ModelProcessor: |
|
|
|
except IOError as e: |
|
|
|
except IOError as e: |
|
|
|
print(f"Error writing delete_edge_faces_map file: {e}") |
|
|
|
print(f"Error writing delete_edge_faces_map file: {e}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 保存 delete_edge_faces_map2 |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
file_name = "_delete_edge_faces_map2.txt" |
|
|
|
|
|
|
|
file_path = Path(base_path) / file_name |
|
|
|
|
|
|
|
with open(file_path, "w", encoding='utf-8') as map_file4: |
|
|
|
|
|
|
|
for image_name, face_set in delete_edge_faces_map2.items(): |
|
|
|
|
|
|
|
line = image_name + " " + " ".join(str(face) for face in face_set) + "\n" |
|
|
|
|
|
|
|
map_file4.write(line) |
|
|
|
|
|
|
|
except IOError as e: |
|
|
|
|
|
|
|
print(f"Error writing delete_edge_faces_map2 file: {e}") |
|
|
|
|
|
|
|
|
|
|
|
# 保存 face_normal_visible_map |
|
|
|
# 保存 face_normal_visible_map |
|
|
|
try: |
|
|
|
try: |
|
|
|
file_name = "_face_normal_visible_map.txt" |
|
|
|
file_name = "_face_normal_visible_map.txt" |
|
|
|
file_path = Path(base_path) / file_name |
|
|
|
file_path = Path(base_path) / file_name |
|
|
|
with open(file_path, "w", encoding='utf-8') as map_file4: |
|
|
|
with open(file_path, "w", encoding='utf-8') as map_file5: |
|
|
|
for image_name, face_set in face_normal_visible_map.items(): |
|
|
|
for image_name, face_set in face_normal_visible_map.items(): |
|
|
|
line = image_name + " " + " ".join(str(face) for face in face_set) + "\n" |
|
|
|
line = image_name + " " + " ".join(str(face) for face in face_set) + "\n" |
|
|
|
map_file4.write(line) |
|
|
|
map_file5.write(line) |
|
|
|
except IOError as e: |
|
|
|
except IOError as e: |
|
|
|
print(f"Error writing delete_edge_faces_map file: {e}") |
|
|
|
print(f"Error writing _face_normal_visible_map file: {e}") |
|
|
|
|
|
|
|
|
|
|
|
def process(self): |
|
|
|
def process(self): |
|
|
|
|
|
|
|
|
|
|
|
|