Compare commits

...

16 Commits

  1. 38
      .gitignore
  2. 71
      fill_all_empty_faces_v1.2.py
  3. 1607
      libs/MVS/SceneTexture.cpp
  4. 23
      libs/MVS/mask_face_occlusion.py

38
.gitignore vendored

@ -7,6 +7,7 @@
# Precompiled Headers # Precompiled Headers
*.gch *.gch
*.pch *.pch
*.pyc
# Compiled Dynamic libraries # Compiled Dynamic libraries
*.so *.so
@ -37,3 +38,40 @@ CMakeSettings.json
out/ out/
bin*/ bin*/
make*/ make*/
libs/MVS/texture_output/texture_0.png
libs/MVS/texture_output/texture_1.png
libs/MVS/texture_output/texture_2.png
libs/MVS/texture_output/texture_3.png
libs/MVS/texture_output/texture_4.png
libs/MVS/texture_output/texture_5.png
libs/MVS/texture_output/texture_6.png
libs/MVS/texture_output/texture_7.png
libs/MVS/texture_output/texture_8.png
libs/MVS/texture_output/texture_9.png
libs/MVS/texture_output/texture_10.png
libs/MVS/texture_output/texture_11.png
libs/MVS/texture_output/texture_12.png
libs/MVS/texture_output/texture_13.png
libs/MVS/texture_output/texture_14.png
libs/MVS/texture_output/texture_15.png
libs/MVS/texture_output/texture_16.png
libs/MVS/texture_output/texture_17.png
libs/MVS/texture_output/texture_18.png
libs/MVS/texture_output/texture_19.png
libs/MVS/texture_output/texture_20.png
libs/MVS/texture_output/texture_21.png
libs/MVS/texture_output/texture_22.png
libs/MVS/texture_output/texture_23.png
libs/MVS/texture_output/texture_24.png
libs/MVS/texture_output/texture_25.png
libs/MVS/texture_output/texture_26.png
libs/MVS/texture_output/texture_27.png
libs/MVS/texture_output/texture_28.png
libs/MVS/texture_output/texture_29.png
libs/MVS/texture_output/texture_30.png
libs/MVS/texture_output/texture_31.png
libs/MVS/texture_output/texture_32.png
libs/MVS/texture_output/texture_33.png
libs/MVS/texture_output/texture_34.png
libs/MVS/texture_output/texture_35.png
texture_output/texture_0.png

71
fill_all_empty_faces_v1.2.py

@ -323,7 +323,7 @@ def compute_regions_face_colors(
return regions_face_color return regions_face_color
def update_uv_map_and_indices( def update_uv_map_and_indices2(
uv_map: torch.Tensor, uv_map: torch.Tensor,
uvs: torch.Tensor, uvs: torch.Tensor,
face_uv_indices: torch.Tensor, face_uv_indices: torch.Tensor,
@ -394,6 +394,75 @@ def update_uv_map_and_indices(
return new_uv_map, uvs_updated, face_uv_indices return new_uv_map, uvs_updated, face_uv_indices
def update_uv_map_and_indices(
uv_map: torch.Tensor,
uvs: torch.Tensor,
face_uv_indices: torch.Tensor,
regions: List[Tuple[set, set]],
regions_face_color: Dict[int, torch.Tensor],
device: str
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
"""
根据计算得到的区域颜色更新UV贴图及对应的UV坐标并批量更新face_uv_indices
"""
total_regions = len(regions_face_color)
# 1. 在CPU上创建新的UV贴图
new_height = int(uv_map.shape[0] + uv_map.shape[0] / 2)
new_width = uv_map.shape[1]
# 将原始UV贴图移到CPU
uv_map_cpu = uv_map.cpu().numpy()
# 创建新的UV贴图(在CPU上)
new_uv_map_cpu = np.zeros((new_height, new_width, 3), dtype=np.uint8)
new_uv_map_cpu[:uv_map.shape[0], :, :] = uv_map_cpu
# 2. 在CPU上创建颜色块
grid_size = new_width // 3
for i, (region_index, color) in enumerate(regions_face_color.items()):
all_c = i // grid_size
all_r = i % grid_size
# 计算3x3颜色块的位置
for dr in range(3):
for dc in range(3):
r = all_r * 3 + dr
c = all_c * 3 + dc + uv_map.shape[0] # 偏移到下半部分
if r < new_width and c < new_height:
new_uv_map_cpu[c, r, :] = color.cpu().numpy()
# 3. 更新UV坐标
uvs[:, 1] = uvs[:, 1] * (2 / 3) + 1 / 3
# 计算新的UV坐标
new_uvs = []
for i, (region_index, _) in enumerate(sorted(regions_face_color.items(), key=lambda x: x[0])):
r = (i % grid_size) * 3 + 1
c = uv_map.shape[0] + (i // grid_size) * 3 + 1
u_new = r / (new_width - 1)
v_new = (new_height - 1 - c) / (new_height - 1)
new_uvs.append([u_new, v_new])
new_uvs_tensor = torch.tensor(new_uvs, device=device)
uvs_updated = torch.cat([uvs, new_uvs_tensor], dim=0)
uv_coordinates_start = uvs_updated.shape[0] - total_regions
# 4. 批量更新face_uv_indices
for i, (region_index, _) in enumerate(sorted(regions_face_color.items(), key=lambda x: x[0])):
region_faces_indexes = torch.tensor(list(regions[region_index][0]), device=device)
face_uv_indices[region_faces_indexes] = torch.full(
(1, 3), uv_coordinates_start + i,
device=device, dtype=face_uv_indices.dtype
)
# 将结果转回GPU
new_uv_map = torch.from_numpy(new_uv_map_cpu).to(device)
return new_uv_map, uvs_updated, face_uv_indices
def group_regions_by_y_axis( def group_regions_by_y_axis(
regions: List[Tuple[set, set]], regions: List[Tuple[set, set]],
vertices: torch.Tensor, vertices: torch.Tensor,

1607
libs/MVS/SceneTexture.cpp

File diff suppressed because it is too large Load Diff

23
libs/MVS/mask_face_occlusion.py

@ -4,7 +4,8 @@ import os
import numpy as np import numpy as np
from scipy.spatial.transform import Rotation from scipy.spatial.transform import Rotation
import sys import sys
sys.path.append("/home/algo/Documents/openMVS/openMVS/libs/MVS/utils") # sys.path.append("/home/algo/Documents/openMVS/openMVS/libs/MVS/utils")
sys.path.append("/root/code/openMVS/libs/MVS/utils")
from colmap_loader import read_cameras_text, read_images_text, read_int_text, write_int_text, read_indices_from_file from colmap_loader import read_cameras_text, read_images_text, read_int_text, write_int_text, read_indices_from_file
# from get_pose_matrix import get_w2c # from get_pose_matrix import get_w2c
import argparse import argparse
@ -33,6 +34,7 @@ from typing import Dict, List, Set
import struct import struct
import math import math
# import os # import os
from pathlib import Path
CameraModel = collections.namedtuple( CameraModel = collections.namedtuple(
"CameraModel", ["model_id", "model_name", "num_params"] "CameraModel", ["model_id", "model_name", "num_params"]
@ -2175,6 +2177,8 @@ class ModelProcessor:
base_path: 基础文件路径 base_path: 基础文件路径
""" """
os.makedirs(base_path, exist_ok = True)
print(f"save_occlusion_data {base_path}, {len(result1)}, {len(result2)}, {len(result3)}") print(f"save_occlusion_data {base_path}, {len(result1)}, {len(result2)}, {len(result3)}")
# 处理返回的可见面字典 - 转换为图像名到面编号集合的映射 # 处理返回的可见面字典 - 转换为图像名到面编号集合的映射
@ -2197,9 +2201,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)
# 保存 visible_faces_map # 保存 visible_faces_map
try: try:
with open(base_path + "/_visible_faces_map.txt", "w", encoding='utf-8') as map_file: file_name = "_visible_faces_map.txt"
file_path = Path(base_path) / file_name
with open(file_path, "w", encoding='utf-8') as map_file:
for image_name, face_set in visible_faces_map.items(): for image_name, face_set in visible_faces_map.items():
# 写入图像名称和所有面ID,用空格分隔 # 写入图像名称和所有面ID,用空格分隔
line = image_name + " " + " ".join(str(face) for face in face_set) + "\n" line = image_name + " " + " ".join(str(face) for face in face_set) + "\n"
@ -2209,7 +2216,9 @@ class ModelProcessor:
# 保存 face_visible_relative # 保存 face_visible_relative
try: try:
with open(base_path + "/_face_visible_relative.txt", "w", encoding='utf-8') as relative_file: file_name = "_face_visible_relative.txt"
file_path = Path(base_path) / file_name
with open(file_path, "w", encoding='utf-8') as relative_file:
for face in face_visible_relative: for face in face_visible_relative:
relative_file.write(str(face) + "\n") relative_file.write(str(face) + "\n")
except IOError as e: except IOError as e:
@ -2217,7 +2226,9 @@ class ModelProcessor:
# 保存 edge_faces_map # 保存 edge_faces_map
try: try:
with open(base_path + "/_edge_faces_map.txt", "w", encoding='utf-8') as map_file2: file_name = "_edge_faces_map.txt"
file_path = Path(base_path) / file_name
with open(file_path, "w", encoding='utf-8') as map_file2:
for image_name, face_set in edge_faces_map.items(): for image_name, face_set in edge_faces_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_file2.write(line) map_file2.write(line)
@ -2226,7 +2237,9 @@ class ModelProcessor:
# 保存 delete_edge_faces_map # 保存 delete_edge_faces_map
try: try:
with open(base_path + "/_delete_edge_faces_map.txt", "w", encoding='utf-8') as map_file3: file_name = "_delete_edge_faces_map.txt"
file_path = Path(base_path) / file_name
with open(file_path, "w", encoding='utf-8') as map_file3:
for image_name, face_set in delete_edge_faces_map.items(): for image_name, face_set in delete_edge_faces_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_file3.write(line) map_file3.write(line)

Loading…
Cancel
Save