MCPcopy
hub / github.com/BIT-DataLab/Edit-Banana / save_visualization

Method save_visualization

modules/metric_evaluator.py:1295–1343  ·  view source on GitHub ↗

保存评估结果可视化图 Args: context: 处理上下文 bad_regions: 问题区域列表 output_path: 输出路径

(self, 
                           context: ProcessingContext,
                           bad_regions: List[Dict],
                           output_path: str)

Source from the content-addressed store, hash-verified

1293 self._log(f"保存评估结果: {output_path}")
1294
1295 def save_visualization(self,
1296 context: ProcessingContext,
1297 bad_regions: List[Dict],
1298 output_path: str):
1299 """
1300 保存评估结果可视化图
1301
1302 Args:
1303 context: 处理上下文
1304 bad_regions: 问题区域列表
1305 output_path: 输出路径
1306 """
1307 if not context.image_path or not os.path.exists(context.image_path):
1308 return
1309
1310 img = cv2.imread(context.image_path)
1311 if img is None:
1312 return
1313
1314 h, w = img.shape[:2]
1315
1316 # 1. 画已检测元素(蓝色)
1317 for elem in context.elements:
1318 x1 = max(0, min(w, elem.bbox.x1))
1319 y1 = max(0, min(h, elem.bbox.y1))
1320 x2 = max(0, min(w, elem.bbox.x2))
1321 y2 = max(0, min(h, elem.bbox.y2))
1322 cv2.rectangle(img, (x1, y1), (x2, y2), (255, 100, 0), 2)
1323
1324 # 2. 画问题区域(红色=粗粒度,绿色=细粒度)
1325 for region in bad_regions:
1326 x1, y1, x2, y2 = region['bbox']
1327 color = (0, 0, 255) if region.get('channel') == 'coarse' else (0, 255, 0)
1328 cv2.rectangle(img, (x1, y1), (x2, y2), color, 3)
1329 # 标注
1330 text = f"{region['area_ratio']*100:.1f}%"
1331 cv2.putText(img, text, (x1, y1-10),
1332 cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 1)
1333
1334 # 3. 图例
1335 cv2.putText(img, "Blue: Detected", (10, 30),
1336 cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255, 100, 0), 2)
1337 cv2.putText(img, "Red: Missing (coarse)", (10, 60),
1338 cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 2)
1339 cv2.putText(img, "Green: Missing (fine)", (10, 90),
1340 cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 255, 0), 2)
1341
1342 cv2.imwrite(output_path, img)
1343 self._log(f"保存可视化结果: {output_path}")
1344
1345 def save_uncovered_mask(self,
1346 context: ProcessingContext,

Callers 1

process_imageMethod · 0.45

Calls 1

_logMethod · 0.80

Tested by

no test coverage detected