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

@@ -72,7 +72,7 @@ printf 'AT+MHTTPDLFILE="http://static.shelingxingqiu.com/shoot/v1/main.py","down
遇到问题:
./build_all.sh: line 56: maixtool: command not found
解决办法:
export PATH="/mnt/d/code/MaixCDK/.venv/bin:$PATH"
pip install maixtool
遇到问题:
./update_img.sh: line 80: mcopy: command not found

View File

@@ -221,4 +221,56 @@ Why it works:
MIPSEND enters prompt mode (>) — after the >, the AT parser treats ALL bytes as data, including CR/LF
We construct the complete HTTP request ourselves (headers + Content-Length + multipart body) with real CRLF bytes
Key bug found during integration: _send_chunk() wrapped calls in self.at._cmd_lock, but self.at.send() also acquires the same lock internally — threading.Lock() is not reentrant, causing deadlock. Fixed by removing the outer lock (the network_manager.get_uart_lock() already provides thread safety).Trade-off: UART is locked during the entire upload, so heartbeats pause. For small JPEG files (~2-80KB), this is 5-20 seconds — acceptable if server heartbeat timeout is generous
Key bug found during integration: _send_chunk() wrapped calls in self.at._cmd_lock, but self.at.send() also acquires the same lock internally — threading.Lock() is not reentrant, causing deadlock. Fixed by removing the outer lock (the network_manager.get_uart_lock() already provides thread safety).Trade-off: UART is locked during the entire upload, so heartbeats pause. For small JPEG files (~2-80KB), this is 5-20 seconds — acceptable if server heartbeat timeout is generous
13. 算环数算法1「黄心 + 红心」椭圆/圆:主要在 vision.py 的 detect_circle_v3() 里完成:颜色先用 HSV 做掩码,再在轮廓上做面积、圆度筛选,黄圈用椭圆拟合,红圈预先筛成候选,最后用几何关系配对。
1. 黄色怎么判、范围是什么?
图像先转 HSVcv2.COLOR_RGB2HSV注意输入是 RGB
饱和度 S 整体乘 1.1 并限制在 0255让黄色更「显」一点
黄色 inRangeOpenCV HSVH 多为 0179
通道 下限 上限
H 7 32
S 80 255
V 0 255
在黄掩码上找轮廓后,还要满足:面积 > 50圆度 > 0.7circularity = 4π·面积/周长²),且点数 ≥5 才 fitEllipse 当黄心椭圆。
2. 红色怎么判、范围是什么?
红色在 HSV 里跨 0°所以用 两段 H 做并集:
两段分别是:
H 010S 80255V 0255
H 170180S 80255V 0255
红轮廓候选:面积 > 50圆度 > 0.6(比黄略松),再拟合椭圆或最小外接圆得到圆心和半径。
3. 「黄心」和「红心」怎样算一对?(几何范围)
对每个黄圈,在红色候选里找第一个满足:
两圆心距离 dist_centers < yellow_radius * 1.5
红半径 red_radius > yellow_radius * 0.8(红在外圈、略大)
dist_centers = math.hypot(ddx, ddy)
if dist_centers < yellow_radius * 1.5 and rc["radius"] > yellow_radius * 0.8:
小结黄色 = HSV H∈[7,32]、S80 S 放大 1.1+ 形态学闭运算 + 面积/圆度红色 = 两段 H010 170180)、S80 + 闭运算 + 面积/圆度配对用 同心/包含 的距离与半径比例阈值若你还关心 laser_manager.py 激光红点的另一套阈值LASER_*那是另一条链路和靶心黄/ HSV 可以分开看
14. 算环数算法2
使用单应性矩阵计算镜头中心点照片中心像素到虚拟平面的转换它不需要知道相机在 3D 空间中的具体位置直接通过单应性矩阵 H的逆运算 2D 像素翻译成虚拟平面上的 2D 坐标
转换的本质2D 2D 查字典
单应性变换Homography是平面到平面的映射它不处理 3D 空间中的投影线”,而是直接建立图像像素 (u,v) 与虚拟平面坐标 (x,y) 的一一对应关系
你可以把单应性矩阵 H想象成一本翻译字典”:
正变换 H已知靶纸上的真实位置 (x,y)查字典得到它在照片上哪个像素 (u,v)。
逆变换 H1已知照片上的像素 (u,v)如镜头中心点查字典反推它在靶纸上的真实位置 (x,y)。
这个虚拟平面就是你的靶纸平面Z=0 的世界坐标系)。算法没有在物理上移动任何点只是在做坐标系的换算
详细步骤镜头中心点如何落地
相机分辨率是 640x480镜头中心点光轴与图像的交点通常是 (u0,v0)=(320,240)。
1. 输入镜头中心点像素
2. 核心运算乘以逆矩阵
通过 4 个黑色三角形的角点已知真实坐标计算出了单应性矩阵 H现在使用它的逆矩阵 H1
3. 输出虚拟平面上的落点物理坐标
计算后你会得到(xhit,yhit)
这就是镜头中心点对应的靶纸上的真实位置单位毫米)。
4. 计算环数
由于虚拟平面原点 (0,0)就是靶纸圆心直接计算欧氏距离。​
这个 d就是箭着点偏离圆心的真实物理距离直接用于环数判定