mi-task/test/task-arrow/test_arrow.py
Havoc cfcdf24a4c feat(task_5): 添加箭头方向检测与运动控制
- 初始化箭头检测器并获取图像
- 根据检测到的箭头方向调整运动方向
- 更新运动参数,包括速度和步态
- 添加资源清理逻辑以确保检测器正常关闭
2025-05-13 09:44:34 +08:00

36 lines
934 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
import cv2
import sys
import os
# 添加父目录到路径以便能够导入utils
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from utils.decode_arrow import detect_arrow_direction, visualize_arrow_detection
def main():
# 检查命令行参数
if len(sys.argv) < 2:
print("使用方法: python test_arrow.py <图像路径>")
sys.exit(1)
# 获取图像路径
image_path = sys.argv[1]
# 检查文件是否存在
if not os.path.exists(image_path):
print(f"错误: 文件 '{image_path}' 不存在")
sys.exit(1)
print(f"正在处理图像: {image_path}")
# 检测箭头方向
direction = detect_arrow_direction(image_path)
print(f"检测到的箭头方向: {direction}")
# 可视化检测过程
visualize_arrow_detection(image_path)
if __name__ == "__main__":
main()