triangle algo refind

This commit is contained in:
gcw_4spBpAfv
2026-04-24 18:38:03 +08:00
parent 8efe1ae5c5
commit fe3e26e21d
7 changed files with 211 additions and 94 deletions

View File

@@ -165,13 +165,28 @@ def analyze_shot(frame, laser_point=None):
tri = tri_result.get('data', {})
if tri.get('ok'):
# 保险校验:避免三角形返回 nan/inf 或退化点仍被上报
try:
import numpy as _np
tri_ok = bool(tri.get('ok'))
if tri_ok:
dxv = tri.get("dx_cm")
dyv = tri.get("dy_cm")
H = tri.get("homography")
if not _np.isfinite(dxv) or not _np.isfinite(dyv):
tri_ok = False
elif H is not None and not _np.all(_np.isfinite(H)):
tri_ok = False
except Exception:
tri_ok = bool(tri.get('ok'))
if tri_ok:
logger.info(f"[TRI] end {datetime.now()} — 使用三角形结果(dx={tri['dx_cm']:.2f},dy={tri['dy_cm']:.2f}cm)")
return {
"success": True,
"result_img": frame,
"center": None, "radius": None,
"method": tri.get("offset_method") or "triangle_homography",
"method": "triangle_homography",
"best_radius1": None, "ellipse_params": None,
"dx": tri["dx_cm"], "dy": tri["dy_cm"],
"distance_m": tri.get("distance_m") or distance_m_first,
@@ -231,7 +246,7 @@ def process_shot(adc_val):
# 三角形路径成功时 center/radius 为空是正常的;此时用 triangle 方法名用于保存文件名与上报字段 m
if (not method) and tri_markers:
method = offset_method or "triangle_homography"
method = "triangle_homography"
if config.SHOW_CAMERA_PHOTO_WHILE_SHOOTING:
camera_manager.show(result_img)