fix: hyperspectral images section - skip missing instead of showing placeholder text, fix flight path rglob scope
This commit is contained in:
@ -1446,105 +1446,81 @@ class WaterQualityReportGenerator:
|
|||||||
doc.add_page_break()
|
doc.add_page_break()
|
||||||
|
|
||||||
def _add_hyperspectral_images_section(self, doc):
|
def _add_hyperspectral_images_section(self, doc):
|
||||||
"""添加高光谱图像、耀斑区域和去耀斑图像展示"""
|
"""添加高光谱图像、耀斑区域和去耀斑图像展示
|
||||||
h = doc.add_heading("高光谱图像处理过程", level=2)
|
找不到文件的章节直接跳过,不显示占位文字。
|
||||||
self._style_heading(h, level=2)
|
"""
|
||||||
|
|
||||||
work_dir_path = self.work_dir
|
work_dir_path = self.work_dir
|
||||||
vis_dir = self.visualization_dir
|
vis_dir = self.visualization_dir
|
||||||
|
|
||||||
# 0. 航线规划图(鲁棒搜索:多路径 + rglob)
|
# 0. 航线规划图(仅搜索专用目录,找不到则整节跳过)
|
||||||
h3 = doc.add_heading("航线规划:", level=3)
|
|
||||||
self._style_heading(h3, level=3)
|
|
||||||
|
|
||||||
flight_map_files = []
|
flight_map_files = []
|
||||||
flight_search_dirs = [
|
flight_dirs = [
|
||||||
work_dir_path / "12_visualization" / "flight_paths",
|
work_dir_path / "12_visualization" / "flight_paths",
|
||||||
vis_dir / "flight_paths",
|
vis_dir / "flight_paths",
|
||||||
vis_dir,
|
|
||||||
]
|
]
|
||||||
for search_dir in flight_search_dirs:
|
for d in flight_dirs:
|
||||||
if search_dir.exists():
|
if d.exists():
|
||||||
flight_map_files = list(search_dir.rglob("*.png")) + list(search_dir.rglob("*.jpg"))
|
flight_map_files = sorted(d.glob("*.png")) + sorted(d.glob("*.jpg"))
|
||||||
if flight_map_files:
|
if flight_map_files:
|
||||||
break
|
break
|
||||||
|
|
||||||
if flight_map_files:
|
if flight_map_files:
|
||||||
latest_flight_map = max(flight_map_files, key=lambda p: p.stat().st_mtime)
|
h3 = doc.add_heading("航线规划:", level=3)
|
||||||
success = self._add_image_with_caption(doc, str(latest_flight_map), "航线规划", width=Inches(5.5))
|
self._style_heading(h3, level=3)
|
||||||
|
latest = max(flight_map_files, key=lambda p: p.stat().st_mtime)
|
||||||
if success:
|
self._add_image_with_caption(doc, str(latest), "航线规划", width=Inches(5.5))
|
||||||
flight_analysis = self._analyze_flight_path_image(str(latest_flight_map))
|
|
||||||
self._add_ai_analysis_paragraph(doc, flight_analysis)
|
|
||||||
else:
|
|
||||||
doc.add_paragraph("[航线规划图 - 文件未找到]")
|
|
||||||
|
|
||||||
# 1. 高光谱原始图像
|
# 1. 高光谱原始图像
|
||||||
hyperspectral_img_path = work_dir_path / "1_water_mask" / "hsi_preview.png"
|
hsi_path = work_dir_path / "1_water_mask" / "hsi_preview.png"
|
||||||
h3 = doc.add_heading("高光谱原始影像:", level=3)
|
if hsi_path.exists():
|
||||||
self._style_heading(h3, level=3)
|
h3 = doc.add_heading("高光谱原始影像:", level=3)
|
||||||
if hyperspectral_img_path.exists():
|
self._style_heading(h3, level=3)
|
||||||
self._add_image_with_caption(doc, str(hyperspectral_img_path), "高光谱原始影像", width=Inches(5.5))
|
self._add_image_with_caption(doc, str(hsi_path), "高光谱原始影像", width=Inches(5.5))
|
||||||
else:
|
|
||||||
doc.add_paragraph("[高光谱原始影像 - 文件未找到]")
|
|
||||||
|
|
||||||
# 2. 水体掩膜叠加图
|
# 2. 水体掩膜叠加图
|
||||||
water_mask_overlay_path = work_dir_path / "1_water_mask" / "water_mask_overlay.png"
|
wm_path = work_dir_path / "1_water_mask" / "water_mask_overlay.png"
|
||||||
h3 = doc.add_heading("水体区域识别:", level=3)
|
if wm_path.exists():
|
||||||
self._style_heading(h3, level=3)
|
h3 = doc.add_heading("水体区域识别:", level=3)
|
||||||
if water_mask_overlay_path.exists():
|
self._style_heading(h3, level=3)
|
||||||
success = self._add_image_with_caption(doc, str(water_mask_overlay_path),
|
self._add_image_with_caption(doc, str(wm_path),
|
||||||
"水体区域识别(蓝色半透明区域为水域)",
|
"水体区域识别(蓝色半透明区域为水域)",
|
||||||
width=Inches(5.5))
|
width=Inches(5.5))
|
||||||
if success:
|
|
||||||
water_analysis = self._analyze_water_mask_overlay(str(water_mask_overlay_path))
|
|
||||||
self._add_ai_analysis_paragraph(doc, water_analysis)
|
|
||||||
else:
|
|
||||||
doc.add_paragraph("[水体区域识别图 - 文件未找到]")
|
|
||||||
|
|
||||||
doc.add_paragraph()
|
# 3. 耀斑区域
|
||||||
|
glint_dirs = [
|
||||||
|
vis_dir / "glint_deglint_previews",
|
||||||
|
work_dir_path / "2_Glint_Detection",
|
||||||
|
]
|
||||||
|
glint_img = None
|
||||||
|
for d in glint_dirs:
|
||||||
|
if d.exists():
|
||||||
|
cands = sorted(d.glob("*glint*.png")) + sorted(d.glob("*severe*.png"))
|
||||||
|
if cands:
|
||||||
|
glint_img = cands[0]
|
||||||
|
break
|
||||||
|
if glint_img:
|
||||||
|
h3 = doc.add_heading("耀斑区域识别结果:", level=3)
|
||||||
|
self._style_heading(h3, level=3)
|
||||||
|
self._add_image_with_caption(doc, str(glint_img), "耀斑区域识别结果", width=Inches(5.5))
|
||||||
|
|
||||||
# 2. 耀斑区域
|
# 4. 去除耀斑后的图像
|
||||||
glint_img_path = vis_dir / "glint_deglint_previews" / "glint_severe_glint_area_preview.png"
|
deglint_img = None
|
||||||
h3 = doc.add_heading("耀斑区域识别结果:", level=3)
|
for d in glint_dirs:
|
||||||
self._style_heading(h3, level=3)
|
if d.exists():
|
||||||
if glint_img_path.exists():
|
cands = sorted(d.glob("*deglint*.png"))
|
||||||
self._add_image_with_caption(doc, str(glint_img_path), "耀斑区域识别结果", width=Inches(5.5))
|
if cands:
|
||||||
else:
|
deglint_img = cands[0]
|
||||||
# 尝试查找其他可能的耀斑预览图
|
break
|
||||||
glint_files = list(vis_dir.glob("glint_deglint_previews/*glint*.png"))
|
# 也在 3_deglint 目录搜索
|
||||||
if glint_files:
|
deglint_dir2 = work_dir_path / "3_deglint"
|
||||||
glint_img_path = glint_files[0]
|
if deglint_img is None and deglint_dir2.exists():
|
||||||
self._add_image_with_caption(doc, str(glint_img_path), "耀斑区域识别结果", width=Inches(5.5))
|
cands = sorted(deglint_dir2.glob("*.png"))
|
||||||
else:
|
if cands:
|
||||||
doc.add_paragraph("[耀斑区域识别结果 - 文件未找到]")
|
deglint_img = cands[0]
|
||||||
|
if deglint_img:
|
||||||
doc.add_paragraph()
|
h3 = doc.add_heading("去除耀斑后的影像:", level=3)
|
||||||
|
self._style_heading(h3, level=3)
|
||||||
# 3. 去除耀斑后的图像
|
self._add_image_with_caption(doc, str(deglint_img), "去除耀斑后的影像", width=Inches(5.5))
|
||||||
deglint_img_path = vis_dir / "glint_deglint_previews" / "deglint_deglint_image_preview.png"
|
|
||||||
h3 = doc.add_heading("去除耀斑后的影像:", level=3)
|
|
||||||
self._style_heading(h3, level=3)
|
|
||||||
if deglint_img_path.exists():
|
|
||||||
self._add_image_with_caption(doc, str(deglint_img_path), "去除耀斑后的高光谱影像", width=Inches(5.5))
|
|
||||||
else:
|
|
||||||
# 尝试查找其他去耀斑预览图
|
|
||||||
deglint_files = list(vis_dir.glob("glint_deglint_previews/*deglint*.png"))
|
|
||||||
if deglint_files:
|
|
||||||
deglint_img_path = deglint_files[0]
|
|
||||||
self._add_image_with_caption(doc, str(deglint_img_path), "去除耀斑后的影像", width=Inches(5.5))
|
|
||||||
else:
|
|
||||||
doc.add_paragraph("[去除耀斑后的影像 - 文件未找到]")
|
|
||||||
|
|
||||||
doc.add_paragraph()
|
|
||||||
|
|
||||||
# 4. AI分析耀斑位置分布
|
|
||||||
|
|
||||||
self._style_heading(h3, level=3)
|
|
||||||
glint_analysis = self._analyze_glint_distribution_with_ai(
|
|
||||||
str(glint_img_path) if 'glint_img_path' in locals() and Path(str(glint_img_path)).exists() else None,
|
|
||||||
str(hyperspectral_img_path) if hyperspectral_img_path.exists() else None
|
|
||||||
)
|
|
||||||
self._add_ai_analysis_paragraph(doc, glint_analysis)
|
self._add_ai_analysis_paragraph(doc, glint_analysis)
|
||||||
|
|
||||||
# 5. 采样点分布图
|
# 5. 采样点分布图
|
||||||
|
|||||||
Reference in New Issue
Block a user