2025-05-28 23:07:58 +08:00
|
|
|
import cv2
|
|
|
|
import os
|
2025-05-31 10:07:37 +08:00
|
|
|
import sys
|
|
|
|
|
|
|
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
project_root = os.path.dirname(current_dir)
|
|
|
|
sys.path.append(project_root)
|
|
|
|
|
2025-05-28 23:07:58 +08:00
|
|
|
from utils.detect_dual_track_lines import detect_dual_track_lines, auto_detect_dual_track_lines
|
|
|
|
|
|
|
|
# 图片路径
|
2025-05-31 10:07:37 +08:00
|
|
|
# image_path = "res/path/image_20250514_024347.png"
|
|
|
|
image_path = "logs/res/1/dual_track_orig_20250531_012429_159526.jpg"
|
2025-05-28 23:07:58 +08:00
|
|
|
|
|
|
|
# 确保图片存在
|
|
|
|
if not os.path.exists(image_path):
|
|
|
|
print(f"图片 {image_path} 不存在!")
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
# 先尝试普通模式
|
|
|
|
print("正在使用普通模式检测...")
|
|
|
|
center_info, left_track_info, right_track_info = detect_dual_track_lines(
|
|
|
|
image_path,
|
|
|
|
observe=True, # 设置为True以查看处理过程和结果
|
|
|
|
delay=2000, # 增加显示时间以便观察
|
|
|
|
save_log=True,
|
|
|
|
stone_path_mode=False
|
|
|
|
)
|
|
|
|
|
|
|
|
if center_info:
|
|
|
|
print("\n普通模式检测结果:")
|
|
|
|
print(f"中心点: {center_info['point']}")
|
|
|
|
print(f"偏差: {center_info['deviation']:.2f}")
|
|
|
|
print(f"斜率: {center_info['slope']:.2f}")
|
|
|
|
print(f"轨道宽度: {center_info['track_width']:.2f}")
|
|
|
|
else:
|
|
|
|
print("普通模式检测失败")
|
|
|
|
|
2025-05-31 10:07:37 +08:00
|
|
|
|
|
|
|
exit(0)
|
|
|
|
|
|
|
|
|
2025-05-28 23:07:58 +08:00
|
|
|
# 再尝试石板路模式
|
|
|
|
print("\n正在使用石板路模式检测...")
|
|
|
|
center_info, left_track_info, right_track_info = detect_dual_track_lines(
|
|
|
|
image_path,
|
|
|
|
observe=True,
|
|
|
|
delay=2000,
|
|
|
|
save_log=True,
|
|
|
|
stone_path_mode=True
|
|
|
|
)
|
|
|
|
|
|
|
|
if center_info:
|
|
|
|
print("\n石板路模式检测结果:")
|
|
|
|
print(f"中心点: {center_info['point']}")
|
|
|
|
print(f"偏差: {center_info['deviation']:.2f}")
|
|
|
|
print(f"斜率: {center_info['slope']:.2f}")
|
|
|
|
print(f"轨道宽度: {center_info['track_width']:.2f}")
|
|
|
|
else:
|
|
|
|
print("石板路模式检测失败")
|
|
|
|
|
|
|
|
# 最后尝试自动检测模式
|
|
|
|
print("\n正在使用自动检测模式...")
|
|
|
|
center_info, left_track_info, right_track_info = auto_detect_dual_track_lines(
|
|
|
|
image_path,
|
|
|
|
observe=True,
|
|
|
|
delay=2000,
|
|
|
|
save_log=True
|
|
|
|
)
|
|
|
|
|
|
|
|
if center_info:
|
|
|
|
print("\n自动检测模式结果:")
|
|
|
|
print(f"中心点: {center_info['point']}")
|
|
|
|
print(f"偏差: {center_info['deviation']:.2f}")
|
|
|
|
print(f"斜率: {center_info['slope']:.2f}")
|
|
|
|
print(f"轨道宽度: {center_info['track_width']:.2f}")
|
|
|
|
print(f"使用石板路模式: {center_info['stone_path_mode']}")
|
|
|
|
else:
|
|
|
|
print("自动检测模式失败")
|
|
|
|
|
|
|
|
# 等待用户按键关闭窗口
|
|
|
|
print("\n按任意键退出...")
|
|
|
|
cv2.waitKey(0)
|
|
|
|
cv2.destroyAllWindows()
|