修改后处理逻辑
This commit is contained in:
parent
bcf182c08a
commit
453afa971e
@ -247,63 +247,7 @@ class ImagePreprocessor:
|
|||||||
|
|
||||||
def post_process(self, successful_grid_points: Dict[tuple, pd.DataFrame], grid_points: Dict[tuple, pd.DataFrame], translations: Dict[tuple, tuple]):
|
def post_process(self, successful_grid_points: Dict[tuple, pd.DataFrame], grid_points: Dict[tuple, pd.DataFrame], translations: Dict[tuple, tuple]):
|
||||||
"""后处理:合并或复制处理结果"""
|
"""后处理:合并或复制处理结果"""
|
||||||
if len(successful_grid_points) == 1:
|
if len(successful_grid_points) < len(grid_points):
|
||||||
# 获取唯一成功的网格ID
|
|
||||||
grid_id = list(successful_grid_points.keys())[0]
|
|
||||||
self.logger.info(f"只有一个网格 {grid_id} 成功处理,直接复制结果")
|
|
||||||
|
|
||||||
# 构建源目录路径(成功网格的输出目录)
|
|
||||||
src_dir = os.path.join(
|
|
||||||
self.config.output_dir, f"grid_{grid_id[0]}_{grid_id[1]}", "project")
|
|
||||||
|
|
||||||
# 复制正射影像
|
|
||||||
if self.config.mode == "快拼模式":
|
|
||||||
shutil.copy2(os.path.join(src_dir, "odm_orthophoto", "odm_orthophoto.original.tif"),
|
|
||||||
os.path.join(self.config.output_dir,
|
|
||||||
"orthophoto.tif")
|
|
||||||
)
|
|
||||||
elif self.config.mode == "三维模式":
|
|
||||||
shutil.copy2(os.path.join(src_dir, "odm_georeferencing", "odm_georeferenced_model.laz"),
|
|
||||||
os.path.join(self.config.output_dir,
|
|
||||||
"pointcloud.laz")
|
|
||||||
)
|
|
||||||
shutil.copytree(os.path.join(src_dir, "odm_texturing"),
|
|
||||||
os.path.join(self.config.output_dir, "texturing"))
|
|
||||||
os.rename(os.path.join(self.config.output_dir, "texturing", "odm_textured_model_geo.obj"),
|
|
||||||
os.path.join(self.config.output_dir, "texturing", "textured_model.obj"))
|
|
||||||
os.rename(os.path.join(self.config.output_dir, "texturing", "odm_textured_model_geo.mtl"),
|
|
||||||
os.path.join(self.config.output_dir, "texturing", "textured_model.mtl"))
|
|
||||||
elif self.config.mode == "重建模式":
|
|
||||||
shutil.copy2(os.path.join(src_dir, "odm_orthophoto", "odm_orthophoto.tif"),
|
|
||||||
os.path.join(self.config.output_dir,
|
|
||||||
"orthophoto.tif")
|
|
||||||
)
|
|
||||||
shutil.copy2(os.path.join(src_dir, "odm_georeferencing", "odm_georeferenced_model.laz"),
|
|
||||||
os.path.join(self.config.output_dir,
|
|
||||||
"pointcloud.laz")
|
|
||||||
)
|
|
||||||
shutil.copytree(os.path.join(src_dir, "odm_texturing"),
|
|
||||||
os.path.join(self.config.output_dir, "texturing"))
|
|
||||||
os.rename(os.path.join(self.config.output_dir, "texturing", "odm_textured_model_geo.obj"),
|
|
||||||
os.path.join(self.config.output_dir, "texturing", "textured_model.obj"))
|
|
||||||
os.rename(os.path.join(self.config.output_dir, "texturing", "odm_textured_model_geo.mtl"),
|
|
||||||
os.path.join(self.config.output_dir, "texturing", "textured_model.mtl"))
|
|
||||||
if self.config.produce_dem:
|
|
||||||
shutil.copy2(
|
|
||||||
os.path.join(src_dir, "odm_dem", "dsm.tif"),
|
|
||||||
os.path.join(self.config.output_dir, "dsm.tif")
|
|
||||||
)
|
|
||||||
shutil.copy2(
|
|
||||||
os.path.join(src_dir, "odm_dem", "dtm.tif"),
|
|
||||||
os.path.join(self.config.output_dir, "dtm.tif")
|
|
||||||
)
|
|
||||||
|
|
||||||
self.logger.info("单网格结果复制完成")
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
# 如果有多个网格,执行合并操作
|
|
||||||
elif len(successful_grid_points) < len(grid_points):
|
|
||||||
self.logger.warning(
|
self.logger.warning(
|
||||||
f"有 {len(grid_points) - len(successful_grid_points)} 个网格处理失败,"
|
f"有 {len(grid_points) - len(successful_grid_points)} 个网格处理失败,"
|
||||||
f"将只合并成功处理的 {len(successful_grid_points)} 个网格"
|
f"将只合并成功处理的 {len(successful_grid_points)} 个网格"
|
||||||
|
@ -4,6 +4,7 @@ import numpy as np
|
|||||||
from typing import Dict, Tuple
|
from typing import Dict, Tuple
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
|
||||||
class MergePly:
|
class MergePly:
|
||||||
@ -14,8 +15,15 @@ class MergePly:
|
|||||||
def merge_grid_laz(self, grid_points: Dict[tuple, pd.DataFrame]):
|
def merge_grid_laz(self, grid_points: Dict[tuple, pd.DataFrame]):
|
||||||
"""合并所有网格的点云数据"""
|
"""合并所有网格的点云数据"""
|
||||||
if len(grid_points) == 1:
|
if len(grid_points) == 1:
|
||||||
self.logger.info("只有一个网格,无需合并")
|
grid_id = list(grid_points.keys())[0]
|
||||||
return
|
shutil.copy2(os.path.join(self.output_dir,
|
||||||
|
f"grid_{grid_id[0]}_{grid_id[1]}",
|
||||||
|
"project",
|
||||||
|
"odm_georeferencing",
|
||||||
|
"odm_georeferenced_model.laz"),
|
||||||
|
os.path.join(self.output_dir,
|
||||||
|
"pointcloud.laz")
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 获取所有点云文件路径
|
# 获取所有点云文件路径
|
||||||
@ -31,15 +39,17 @@ class MergePly:
|
|||||||
if os.path.exists(laz_path):
|
if os.path.exists(laz_path):
|
||||||
laz_files.append(laz_path)
|
laz_files.append(laz_path)
|
||||||
else:
|
else:
|
||||||
self.logger.warning(f"网格 ({grid_id[0]},{grid_id[1]}) 的点云文件不存在")
|
self.logger.warning(
|
||||||
|
f"网格 ({grid_id[0]},{grid_id[1]}) 的点云文件不存在")
|
||||||
|
|
||||||
kwargs = {
|
kwargs = {
|
||||||
'all_inputs': " ".join(laz_files),
|
'all_inputs': " ".join(laz_files),
|
||||||
'output': os.path.join(self.output_dir, 'pointcloud.laz')
|
'output': os.path.join(self.output_dir, 'pointcloud.laz')
|
||||||
}
|
}
|
||||||
|
|
||||||
subprocess.run('D:\\software\\LAStools\\bin\\lasmerge64.exe -i {all_inputs} -o "{output}"'.format(**kwargs))
|
subprocess.run(
|
||||||
|
'D:\\software\\LAStools\\bin\\lasmerge64.exe -i {all_inputs} -o "{output}"'.format(**kwargs))
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(f"PLY点云合并过程中发生错误: {str(e)}", exc_info=True)
|
self.logger.error(f"PLY点云合并过程中发生错误: {str(e)}", exc_info=True)
|
||||||
raise
|
raise
|
||||||
|
@ -268,8 +268,14 @@ class MergeObj:
|
|||||||
def merge_grid_obj(self, grid_points: Dict[tuple, pd.DataFrame], translations: Dict[tuple, tuple]):
|
def merge_grid_obj(self, grid_points: Dict[tuple, pd.DataFrame], translations: Dict[tuple, tuple]):
|
||||||
"""合并所有网格的OBJ模型"""
|
"""合并所有网格的OBJ模型"""
|
||||||
if len(grid_points) == 1:
|
if len(grid_points) == 1:
|
||||||
self.logger.info("只有一个网格,无需合并")
|
grid_id = list(grid_points.keys())[0]
|
||||||
return
|
shutil.copytree(os.path.join(self.output_dir,
|
||||||
|
f"grid_{grid_id[0]}_{grid_id[1]}",
|
||||||
|
"project",
|
||||||
|
"odm_texturing"),
|
||||||
|
os.path.join(self.output_dir, "texturing"))
|
||||||
|
os.rename(os.path.join(self.output_dir, "texturing", "odm_textured_model_geo.obj"),
|
||||||
|
os.path.join(self.output_dir, "texturing", "textured_model.obj"))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 创建输出目录
|
# 创建输出目录
|
||||||
|
@ -107,8 +107,15 @@ class MergeTif:
|
|||||||
self.logger.info(f"开始合并{product_name}")
|
self.logger.info(f"开始合并{product_name}")
|
||||||
|
|
||||||
if len(grid_points) < 2:
|
if len(grid_points) < 2:
|
||||||
self.logger.info("只有一个网格,无需合并")
|
grid_id = list(grid_points.keys())[0]
|
||||||
return
|
shutil.copy2(os.path.join(self.output_dir,
|
||||||
|
f"grid_{grid_id[0]}_{grid_id[1]}",
|
||||||
|
"project",
|
||||||
|
product_path,
|
||||||
|
filename),
|
||||||
|
os.path.join(self.output_dir,
|
||||||
|
product_info['output'])
|
||||||
|
)
|
||||||
|
|
||||||
input_tif1, input_tif2 = None, None
|
input_tif1, input_tif2 = None, None
|
||||||
merge_count = 0
|
merge_count = 0
|
||||||
@ -129,7 +136,8 @@ class MergeTif:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# 如果文件大于600MB,则不使用original文件
|
# 如果文件大于600MB,则不使用original文件
|
||||||
file_size_mb = os.path.getsize(grid_tif) / (1024 * 1024) # 转换为MB
|
file_size_mb = os.path.getsize(
|
||||||
|
grid_tif) / (1024 * 1024) # 转换为MB
|
||||||
if file_size_mb > 600:
|
if file_size_mb > 600:
|
||||||
grid_tif = os.path.join(
|
grid_tif = os.path.join(
|
||||||
self.output_dir,
|
self.output_dir,
|
||||||
|
Loading…
Reference in New Issue
Block a user