This commit is contained in:
gcw_4spBpAfv
2026-01-23 11:28:40 +08:00
parent 42bfdd033c
commit 28fb62e5d6
12 changed files with 648 additions and 67 deletions

37
main.py
View File

@@ -252,14 +252,6 @@ def cmd_str():
try:
frame = camera_manager.read_frame()
# 先检测靶心以获取距离(用于计算激光点)
# 第一次检测不使用激光点,仅用于获取距离
result_img_temp, center_temp, radius_temp, method_temp, best_radius1_temp, ellipse_params_temp = detect_circle_v3(frame, None)
# 计算距离
distance_m = estimate_distance(best_radius1_temp) if best_radius1_temp else None
# 根据距离动态计算激光点坐标(如果未检测到靶心,使用硬编码值或默认值)
laser_point_method = None # 记录激光点选择方法
if config.HARDCODE_LASER_POINT:
# 硬编码模式:使用硬编码值
@@ -272,15 +264,13 @@ def cmd_str():
logger_manager.logger.info(f"[算法] 使用校准值: {laser_manager.laser_point}")
elif distance_m and distance_m > 0:
# 动态计算模式:根据距离计算激光点
# 先检测靶心以获取距离(用于计算激光点)
# 第一次检测不使用激光点,仅用于获取距离
result_img_temp, center_temp, radius_temp, method_temp, best_radius1_temp, ellipse_params_temp = detect_circle_v3(frame, None)
# 计算距离
distance_m = estimate_distance(best_radius1_temp) if best_radius1_temp else None
laser_point = laser_manager.calculate_laser_point_from_distance(distance_m)
laser_point_method = "dynamic"
logger_manager.logger.info(f"[算法] 使用比例尺: {laser_point}")
else:
# 未检测到靶心且未启用硬编码:使用默认激光点或从配置文件加载
laser_point = laser_manager.laser_point
laser_point_method = "default"
logger_manager.logger.info(f"[算法] 使用默认值: {laser_point}")
if laser_point is None:
logger = logger_manager.logger
if logger:
@@ -290,22 +280,9 @@ def cmd_str():
x, y = laser_point
# 绘制激光十字线
color = image.Color(config.LASER_COLOR[0], config.LASER_COLOR[1], config.LASER_COLOR[2])
frame.draw_line(
int(x - config.LASER_LENGTH), int(y),
int(x + config.LASER_LENGTH), int(y),
color, config.LASER_THICKNESS
)
frame.draw_line(
int(x), int(y - config.LASER_LENGTH),
int(x), int(y + config.LASER_LENGTH),
color, config.LASER_THICKNESS
)
frame.draw_circle(int(x), int(y), 1, color, config.LASER_THICKNESS)
# 重新检测靶心(使用计算出的激光点)
# 检测靶心
result_img, center, radius, method, best_radius1, ellipse_params = detect_circle_v3(frame, laser_point)
camera_manager.show(result_img)
# 计算偏移与距离(如果检测到靶心)