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()
|
||||
|
||||
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
|
||||
vis_dir = self.visualization_dir
|
||||
|
||||
# 0. 航线规划图(鲁棒搜索:多路径 + rglob)
|
||||
h3 = doc.add_heading("航线规划:", level=3)
|
||||
self._style_heading(h3, level=3)
|
||||
|
||||
# 0. 航线规划图(仅搜索专用目录,找不到则整节跳过)
|
||||
flight_map_files = []
|
||||
flight_search_dirs = [
|
||||
flight_dirs = [
|
||||
work_dir_path / "12_visualization" / "flight_paths",
|
||||
vis_dir / "flight_paths",
|
||||
vis_dir,
|
||||
]
|
||||
for search_dir in flight_search_dirs:
|
||||
if search_dir.exists():
|
||||
flight_map_files = list(search_dir.rglob("*.png")) + list(search_dir.rglob("*.jpg"))
|
||||
for d in flight_dirs:
|
||||
if d.exists():
|
||||
flight_map_files = sorted(d.glob("*.png")) + sorted(d.glob("*.jpg"))
|
||||
if flight_map_files:
|
||||
break
|
||||
|
||||
if flight_map_files:
|
||||
latest_flight_map = max(flight_map_files, key=lambda p: p.stat().st_mtime)
|
||||
success = self._add_image_with_caption(doc, str(latest_flight_map), "航线规划", width=Inches(5.5))
|
||||
|
||||
if success:
|
||||
flight_analysis = self._analyze_flight_path_image(str(latest_flight_map))
|
||||
self._add_ai_analysis_paragraph(doc, flight_analysis)
|
||||
else:
|
||||
doc.add_paragraph("[航线规划图 - 文件未找到]")
|
||||
h3 = doc.add_heading("航线规划:", level=3)
|
||||
self._style_heading(h3, level=3)
|
||||
latest = max(flight_map_files, key=lambda p: p.stat().st_mtime)
|
||||
self._add_image_with_caption(doc, str(latest), "航线规划", width=Inches(5.5))
|
||||
|
||||
# 1. 高光谱原始图像
|
||||
hyperspectral_img_path = work_dir_path / "1_water_mask" / "hsi_preview.png"
|
||||
h3 = doc.add_heading("高光谱原始影像:", level=3)
|
||||
self._style_heading(h3, level=3)
|
||||
if hyperspectral_img_path.exists():
|
||||
self._add_image_with_caption(doc, str(hyperspectral_img_path), "高光谱原始影像", width=Inches(5.5))
|
||||
else:
|
||||
doc.add_paragraph("[高光谱原始影像 - 文件未找到]")
|
||||
hsi_path = work_dir_path / "1_water_mask" / "hsi_preview.png"
|
||||
if hsi_path.exists():
|
||||
h3 = doc.add_heading("高光谱原始影像:", level=3)
|
||||
self._style_heading(h3, level=3)
|
||||
self._add_image_with_caption(doc, str(hsi_path), "高光谱原始影像", width=Inches(5.5))
|
||||
|
||||
# 2. 水体掩膜叠加图
|
||||
water_mask_overlay_path = work_dir_path / "1_water_mask" / "water_mask_overlay.png"
|
||||
h3 = doc.add_heading("水体区域识别:", level=3)
|
||||
self._style_heading(h3, level=3)
|
||||
if water_mask_overlay_path.exists():
|
||||
success = self._add_image_with_caption(doc, str(water_mask_overlay_path),
|
||||
"水体区域识别(蓝色半透明区域为水域)",
|
||||
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("[水体区域识别图 - 文件未找到]")
|
||||
wm_path = work_dir_path / "1_water_mask" / "water_mask_overlay.png"
|
||||
if wm_path.exists():
|
||||
h3 = doc.add_heading("水体区域识别:", level=3)
|
||||
self._style_heading(h3, level=3)
|
||||
self._add_image_with_caption(doc, str(wm_path),
|
||||
"水体区域识别(蓝色半透明区域为水域)",
|
||||
width=Inches(5.5))
|
||||
|
||||
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. 耀斑区域
|
||||
glint_img_path = vis_dir / "glint_deglint_previews" / "glint_severe_glint_area_preview.png"
|
||||
h3 = doc.add_heading("耀斑区域识别结果:", level=3)
|
||||
self._style_heading(h3, level=3)
|
||||
if glint_img_path.exists():
|
||||
self._add_image_with_caption(doc, str(glint_img_path), "耀斑区域识别结果", width=Inches(5.5))
|
||||
else:
|
||||
# 尝试查找其他可能的耀斑预览图
|
||||
glint_files = list(vis_dir.glob("glint_deglint_previews/*glint*.png"))
|
||||
if glint_files:
|
||||
glint_img_path = glint_files[0]
|
||||
self._add_image_with_caption(doc, str(glint_img_path), "耀斑区域识别结果", width=Inches(5.5))
|
||||
else:
|
||||
doc.add_paragraph("[耀斑区域识别结果 - 文件未找到]")
|
||||
|
||||
doc.add_paragraph()
|
||||
|
||||
# 3. 去除耀斑后的图像
|
||||
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
|
||||
)
|
||||
# 4. 去除耀斑后的图像
|
||||
deglint_img = None
|
||||
for d in glint_dirs:
|
||||
if d.exists():
|
||||
cands = sorted(d.glob("*deglint*.png"))
|
||||
if cands:
|
||||
deglint_img = cands[0]
|
||||
break
|
||||
# 也在 3_deglint 目录搜索
|
||||
deglint_dir2 = work_dir_path / "3_deglint"
|
||||
if deglint_img is None and deglint_dir2.exists():
|
||||
cands = sorted(deglint_dir2.glob("*.png"))
|
||||
if cands:
|
||||
deglint_img = cands[0]
|
||||
if deglint_img:
|
||||
h3 = doc.add_heading("去除耀斑后的影像:", level=3)
|
||||
self._style_heading(h3, level=3)
|
||||
self._add_image_with_caption(doc, str(deglint_img), "去除耀斑后的影像", width=Inches(5.5))
|
||||
self._add_ai_analysis_paragraph(doc, glint_analysis)
|
||||
|
||||
# 5. 采样点分布图
|
||||
|
||||
Reference in New Issue
Block a user