Initial commit: SmartCar Framework v0.1 — 龙芯2K0300智能车开发框架\n\n- HAL: GPIO/PWM/Encoder/Framebuffer 驱动\n- Control: PID/IMU/Motor/Servo 控制\n- Vision: HSV双Otsu→4点标定IPM→洪泛填充→逐行搜线\n- Strategy: 三区前瞻偏差+速度策略\n- Debug: 文件热调参+LCD预览+cv截帧\n- Scheduler: 5ms timerfd+epoll 中央调度器
This commit is contained in:
43
tools/calibrate.py
Normal file
43
tools/calibrate.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import cv2
|
||||
import sys
|
||||
|
||||
img = cv2.imread(sys.argv[1] if len(sys.argv) > 1 else "_capture.jpg")
|
||||
if img is None:
|
||||
print("找不到图片")
|
||||
sys.exit(1)
|
||||
|
||||
H, W = img.shape[:2]
|
||||
points = []
|
||||
labels = ["A 近左", "B 近右", "C 远左", "D 远右"]
|
||||
|
||||
def on_click(event, x, y, flags, param):
|
||||
if event == cv2.EVENT_LBUTTONDOWN and len(points) < 4:
|
||||
points.append((x, y))
|
||||
cv2.circle(img, (x, y), 4, (0, 0, 255), -1)
|
||||
cv2.putText(img, labels[len(points)-1], (x+8, y-8),
|
||||
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 255), 1)
|
||||
print(f" {labels[len(points)-1]}: ({x:4d}, {y:4d})")
|
||||
if len(points) == 4:
|
||||
print("\n--- 标定数据 ---")
|
||||
for i, p in enumerate(points):
|
||||
print(f"{labels[i]}: ({p[0]:4d}, {p[1]:4d})")
|
||||
# 换算到 80x60
|
||||
sx, sy = 80/W, 60/H
|
||||
print(f"\n80x60 处理分辨率:")
|
||||
for i, p in enumerate(points):
|
||||
print(f"{labels[i]}: ({int(p[0]*sx):3d}, {int(p[1]*sy):3d})")
|
||||
print("\n按任意键退出...")
|
||||
|
||||
cv2.namedWindow("calib", cv2.WINDOW_NORMAL)
|
||||
cv2.setMouseCallback("calib", on_click)
|
||||
|
||||
print(f"图片 {W}x{H},按 A B C D 顺序点击 4 个点:")
|
||||
print(" A=近处左边界 B=近处右边界 C=远处左边界 D=远处右边界\n")
|
||||
|
||||
while True:
|
||||
cv2.imshow("calib", img)
|
||||
if cv2.waitKey(20) != -1 or len(points) >= 4:
|
||||
break
|
||||
|
||||
cv2.waitKey(0)
|
||||
cv2.destroyAllWindows()
|
||||
Reference in New Issue
Block a user