fix:测距

This commit is contained in:
2025-12-28 16:19:00 +08:00
parent 21cec260b8
commit b552d20a46
2 changed files with 8 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
id: t11
name: t11
version: 1.0.2
version: 1.0.3
author: t11
icon: ''
desc: t11

11
main.py
View File

@@ -38,7 +38,7 @@ PASSWORD = None
# 服务器连接参数
SERVER_IP = "www.shelingxingqiu.com"
SERVER_PORT = 50005
HEARTBEAT_INTERVAL = 5 # 心跳间隔(秒)
HEARTBEAT_INTERVAL = 60 # 心跳间隔(秒)
# 激光校准配置
CONFIG_FILE = "/root/laser_config.json"
@@ -95,7 +95,7 @@ LASER_OFF_CMD = bytes([0xAA, MODULE_ADDR, 0x01, 0xBE, 0x00, 0x01, 0x00, 0x00, 0x
# 相机标定参数(用于距离估算)
# FOCAL_LENGTH_PIX = 3800.0 # 焦距(像素)
FOCAL_LENGTH_PIX = 1900.0 # 焦距(像素)
FOCAL_LENGTH_PIX = 2200.0 # 焦距(像素)
REAL_RADIUS_CM = 15 # 靶心实际半径(厘米)
# TCP 连接状态
@@ -536,7 +536,10 @@ def detect_circle(frame):
circularity = 4 * np.pi * area / (perimeter ** 2)
if circularity > 0.75 and len(cnt) >= 5:
center, axes, angle = cv2.fitEllipse(cnt)
radius = (axes[0] + axes[1]) / 4
radius = axes[0]
if axes[1] < radius:
radius = axes[1]
radius /= 2
best_center = (int(center[0]), int(center[1]))
best_radius = int(radius)
best_radius1 = best_radius
@@ -834,7 +837,7 @@ def cmd_str():
# 初始化硬件
init_ina226()
load_laser_point()
# load_laser_point()
disp = display.Display()
cam = camera.Camera(640, 480)