From 575e690868fc254fc06f424e94397762dc0499f9 Mon Sep 17 00:00:00 2001 From: yrx Date: Fri, 22 May 2026 11:02:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=8A=E9=9D=B6=E5=AD=90=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E6=8B=89=E5=88=B0=E4=BA=86=E6=9C=80=E5=89=8D?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shoot_manager.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/shoot_manager.py b/shoot_manager.py index f47c4f9..fcad946 100644 --- a/shoot_manager.py +++ b/shoot_manager.py @@ -466,6 +466,27 @@ def process_shot(adc_val): if _timing_on and _t_sample is not None: _t_sample_ms = (time_std.perf_counter() - _t_sample) * 1000.0 + # 采样提前完成后,先确定靶型对应的物理半径,供后续距离/偏移/上报使用。 + # 40cm_black 表示直径40cm,半径20cm;20cm 表示直径20cm,半径10cm。 + target_radius_cm = 20.0 if sample_target_type == "40cm_black" else (10.0 if sample_target_type == "20cm" else 20.0) + target_type_value = 40 if sample_target_type == "40cm_black" else (20 if sample_target_type == "20cm" else None) + + # 圆心分支原算法默认按40cm靶半径20cm换算;若采样判定为20cm靶,在上报前修正距离和偏移。 + # 三角分支使用 triangle_positions.json 的物方坐标,不在这里二次缩放,避免影响三角单应性结果。 + if sample_target_type == "20cm" and center and radius and not tri_markers: + try: + distance_m = (target_radius_cm * config.FOCAL_LENGTH_PIX) / float(radius) / 100.0 + _scale = target_radius_cm / 20.0 + if dx is not None: + dx = float(dx) * _scale + if dy is not None: + dy = float(dy) * _scale + if logger: + logger.info(f"[采样] 20cm靶修正圆心测距/偏移: distance={distance_m:.2f}m scale={_scale:.2f}") + except Exception as _e_fix: + if logger: + logger.warning(f"[采样] 20cm靶修正失败: {_e_fix}") + # 三角形路径成功时 center/radius 为空是正常的;此时用 triangle 方法名用于保存文件名与上报字段 m if (not method) and tri_markers: method = "triangle_homography" @@ -496,7 +517,7 @@ def process_shot(adc_val): "shot_id": shot_id, "x": srv_x, "y": srv_y, - "r": 20.0, # 保留字段(服务端当前忽略,物理外环半径 cm) + "r": target_radius_cm, # 物理靶半径 cm:40cm靶=20,20cm靶=10 "d": round((distance_m or 0.0) * 100), "d_laser": round((laser_distance_m or 0.0) * 100), "d_laser_quality": laser_signal_quality, @@ -507,7 +528,7 @@ def process_shot(adc_val): "target_y": float(y), "offset_method": offset_method, "distance_method": distance_method, - "target_type": 40 if sample_target_type == "40cm_black" else (20 if sample_target_type == "20cm" else None), + "target_type": target_type_value, } if ellipse_params: