new shoot algo

This commit is contained in:
gcw_4spBpAfv
2026-04-17 18:30:50 +08:00
parent 0ee970d8bd
commit 43e7e0ba17
11 changed files with 1976 additions and 97 deletions

View File

@@ -102,4 +102,95 @@ WiFi 连接成功
尝试切换到 4G
上层检测到连接断开:
重新 connect_server() → 自动选择 4G
重新 connect_server() → 自动选择 4G
10. 现在使用的相机其实是支持更大的分辨率的比如说1920*1280但是由于我们的图像处理拍照处理之后很容易触发OOM。
11. 环数计算流程:
现在设备侧的目标是:算出箭点相对靶心的偏移(dx,dy)单位是物理厘米cm然后把它作为 x,y 上报给后端;后端再去算环。
设备侧本身不直接算环数,它算的是偏移与距离,并上报。
算法流程(一次射箭从触发到上报)
1) 触发后取一帧图
在 process_shot() 里读取相机帧并调用 analyze_shot(frame)
2) 确定激光点laser_point
analyze_shot() 第一步先确定激光点 (x,y)(像素坐标):
硬编码config.HARDCODE_LASER_POINT=True → 用 laser_manager.laser_point
已校准laser_manager.has_calibrated_point() → 用校准值
动态模式:先 detect_circle_v3(frame, None) 粗估距离,再根据距离反推激光点
代码在:
if config.HARDCODE_LASER_POINT:
...
elif laser_manager.has_calibrated_point():
...
else:
_, _, _, _, best_radius1_temp, _ = detect_circle_v3(frame, None)
distance_m_first = estimate_distance(best_radius1_temp) ...
laser_point = laser_manager.calculate_laser_point_from_distance(distance_m_first)
3) 优先走三角形路径(成功就直接用于上报 x/y
如果 config.USE_TRIANGLE_OFFSET=True先尝试识别靶面四角三角形标记
if getattr(config, "USE_TRIANGLE_OFFSET", False):
K, dist_coef, pos = _get_triangle_calib()
img_rgb = image.image2cv(frame, False, False)
tri = try_triangle_scoring(img_rgb, (x, y), pos, K, dist_coef, ...)
if tri.get("ok"):
return {... "dx": tri["dx_cm"], "dy": tri["dy_cm"], "distance_m": tri.get("distance_m"), ...}
这一步里 try_triangle_scoring() 做了两件事(都在 triangle_target.py
单应性homography把激光点从图像坐标映射到靶面坐标系得到(dx,dy)cm
PnP用识别到的角点与相机标定估算 相机到靶的距离 distance_m
关键代码:
ok_h, tx, ty, _H = homography_calibration(...)
out["dx_cm"] = tx
out["dy_cm"] = -ty
out["distance_m"] = dist_m
out["distance_method"] = "pnp_triangle"
注意:这里 dy_cm 取了负号是为了和现网约定一致laser_manager.compute_laser_position 的坐标方向)。
4) 三角形失败 → 回退圆形/椭圆靶心检测(兜底)
如果三角形不可用或识别失败,就走传统靶心检测:
detect_circle_v3(frame, laser_point) 找黄心/红心、半径、椭圆参数
用 laser_manager.compute_laser_position() 把像素偏移换算成厘米偏移(dx,dy)
在 shoot_manager.py
result_img, center, radius, method, best_radius1, ellipse_params = detect_circle_v3(frame, laser_point)
if center and radius:
dx, dy = laser_manager.compute_laser_position(center, (x, y), radius, method)
distance_m = estimate_distance(best_radius1) ...
在 laser_manager.compute_laser_position()(核心换算逻辑):
r = radius * 5
target_x = (lx-cx)/r*100
target_y = (ly-cy)/r*100
return (target_x, -target_y)
这里 (像素差)/(radius*5)*100 是你们旧约定下的“像素→厘米”比例模型(并且 y 方向同样取负号)。
5) 上报数据:把(dx,dy) 作为 x/y 发给后端
最终上报发生在 process_shot(),直接把 dx,dy 填到 inner_data["x"],["y"]
srv_x = round(float(dx), 4) if dx is not None else 200.0
srv_y = round(float(dy), 4) if dy is not None else 200.0
inner_data = {
"x": srv_x,
"y": srv_y,
"d": round((distance_m or 0.0) * 100),
"m": method if method else "no_target",
"offset_method": offset_method,
"distance_method": distance_method,
...
}
network_manager.safe_enqueue(...)
x,y物理厘米cm
d相机到靶距离m→cm乘 100三角形成功时来自 PnP
m/offset_method/distance_method标记本次用的算法路径triangle / yellow / pnp 等)
后端收到 x,y 后,再用你之前给的 Go 公式 CalculateRingNumber(x,y,tenRingRadius) 计算环数。
你现在的“环数计算”实际依赖关系
最好路径(快+稳):三角形 → dx,dy单应性 + distance_mPnP
兜底路径:圆/椭圆靶心 → dx,dy基于黄心半径比例/透视校正) + distance_m黄心半径估距