回答

收藏

《2023 DigiKey 汽车应用创意挑战赛》2 #智能车载HUD

#竞赛 #竞赛 1784 人阅读 | 0 人回复 | 2024-01-29

一、项目名称:
        智能车载抬头显示系统HUD

二、项目概述:
        智能车载抬头显示系统HUD是一个以视频采集为主要输入端口的人机协同车载智能装置,能够提供智能化的辅助驾驶体验和人机交互体验。在本次项目开发中,是围绕ADAS自动驾驶系统,使用OpenVINO的框架,实现对于视野内的驾驶相关场景的分析,提供驾驶辅助。
        这个显示系统使用树莓派和7寸树莓派显示屏连接,固定在汽车遮阳板的支架上,可以协同驾驶,供电采用12V点烟器连接的车载USB充电头,不需要对汽车电气作改线工作。


三、作品实物图
3.1 主控树莓派,连接7寸屏如下
3.2 使用罗技摄像头采集图像并显示,其中包括罗技摄像头和用于识别的演示卡通人物
3.3 在显示屏的ipython界面显示摄像头采集的效果


四、演示视频

4.1 如下是树莓派启动后的视频演示效果,见压缩文件
ADAS_HUD.zip (11.42 MB, 下载次数: 0)
4.2在ipython中演示汽车驶入车道的照片如下

五、项目文档

5.1 源代码和adas模型打包如下
ADAS_HUD_codes.zip (10.38 MB, 下载次数: 0)

5.2 代码使用说明
5.2.1 需要安装OpenVINO for Raspbian OS,并在虚拟环境python环境启动,然后启动jupyter lab


5.2.2 启动adas_hub.ipython Notebook 文件

5.2.3 导入ada_0001模型,并是哟功能图片测试识别效果,可以识别出车道,路肩等并用渲染完成

5.2.4 使用webcam读取数据,并在线读取,不过哦显示速率不高,帧数FPS
在10帧以内,

5.2.5 参考python代码如下
  1. import cv2
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4. import openvino as ov
  5. from pathlib import Path
  6. import collections
  7. import time

  8. from IPython import display
  9. import ipywidgets as widgets

  10. import notebook_utils as utils
  11. from notebook_utils import segmentation_map_to_image, download_file


  12. base_model_dir = Path("./model").expanduser()
  13. model_name = "road-segmentation-adas-0001"
  14. model_xml_name = f'{model_name}.xml'
  15. model_bin_name = f'{model_name}.bin'
  16. model_xml_path = base_model_dir / model_xml_name


  17. core = ov.Core()
  18. device = widgets.Dropdown(
  19.     options=core.available_devices + ["AUTO"],
  20.     value='AUTO',
  21.     description='Device:',
  22.     disabled=False,
  23. )


  24. model = core.read_model(model=model_xml_path)
  25. compiled_model = core.compile_model(model=model, device_name=device.value)

  26. input_layer_ir = compiled_model.input(0)
  27. output_layer_ir = compiled_model.output(0)

  28. N, C, H, W = input_layer_ir.shape
  29. colormap = np.array([[68, 1, 84], [48, 103, 141], [53, 183, 120], [199, 216, 52]])
  30. alpha = 0.3

  31. # Main processing function to run object detection.
  32. def run_object_detection(source=0, flip=False, use_popup=False, skip_first_frames=0):
  33.     player = None
  34.     try:
  35.         # Create a video player to play with target fps.
  36.         player = utils.VideoPlayer(
  37.             source=source, flip=flip, fps=30, skip_first_frames=skip_first_frames
  38.         )
  39.         # Start capturing.
  40.         player.start()
  41.         if use_popup:
  42.             title = "Press ESC to Exit"
  43.             cv2.namedWindow(
  44.                 winname=title, flags=cv2.WINDOW_GUI_NORMAL | cv2.WINDOW_AUTOSIZE
  45.             )

  46.         while True:
  47.             # Grab the frame.
  48.             frame = player.next()
  49.             if frame is None:
  50.                 print("Source ended")
  51.                 break
  52.             # If the frame is larger than full HD, reduce size to improve the performance.
  53.             scale = 1280 / max(frame.shape)
  54.             if scale < 1:
  55.                 frame = cv2.resize(
  56.                     src=frame,
  57.                     dsize=None,
  58.                     fx=scale,
  59.                     fy=scale,
  60.                     interpolation=cv2.INTER_AREA,
  61.                 )
  62.                
  63.             input_img_resize = cv2.resize( src=frame, dsize=(W, H), interpolation=cv2.INTER_AREA )
  64.             input_img = np.expand_dims(  input_img_resize.transpose(2, 0, 1), 0)  #plt.imshow(rgb_image)            
  65.             # Create a batch of images (size = 1).
  66.             input_img = input_img[np.newaxis, ...]
  67.             f_height, f_width = frame.shape[:2]

  68.             
  69.             # Get the results.
  70.             result = compiled_model([input_image])[output_layer_ir]
  71.             segmentation_mask = np.argmax(result, axis=1)
  72.             rgb_image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
  73.             mask = segmentation_map_to_image(segmentation_mask, colormap)
  74.             resized_mask = cv2.resize(mask, (f_width, f_height))
  75.             image_with_mask = cv2.addWeighted(resized_mask, alpha, frame, 1 - alpha, 0)
  76.             
  77.             cv2.putText(
  78.                 img=image_with_mask,
  79.                 text=f"Keep Going...",
  80.                 org=(20, 40),
  81.                 fontFace=cv2.FONT_HERSHEY_COMPLEX,
  82.                 fontScale=f_width / 1000,
  83.                 color=(0, 0, 255),
  84.                 thickness=1,
  85.                 lineType=cv2.LINE_AA,
  86.             )

  87.             # Use this workaround if there is flickering.
  88.             if use_popup:
  89.                 cv2.imshow(winname=title, mat=image_with_mask)
  90.                 key = cv2.waitKey(1)
  91.                 # escape = 27
  92.                 if key == 27:
  93.                     break
  94.             else:
  95.                 _, encoded_img = cv2.imencode(
  96.                     ext=".jpg", img=image_with_mask, params=[cv2.IMWRITE_JPEG_QUALITY, 100]
  97.                 )
  98.                 i = display.Image(data=encoded_img)
  99.                 display.clear_output(wait=True)
  100.                 display.display(i)
  101.     # ctrl-c
  102.     except KeyboardInterrupt:
  103.         print("Interrupted")
  104.     except RuntimeError as e:
  105.         print(e)
  106.     finally:
  107.         if player is not None:
  108.             # Stop capturing.
  109.             player.stop()
  110.         if use_popup:
  111.             cv2.destroyAllWindows()

  112. USE_WEBCAM = False

  113. video_file = "./data/car-detection.mp4"

  114. cam_id = 0

  115. source = cam_id if USE_WEBCAM else video_file

  116. run_object_detection(source=source, flip=isinstance(source, int), use_popup=False)
复制代码

5.3 小结和**开发
      本次开发,选择使用树莓派4B,能够完成基于OpenVINO的人工智能ADAS 抬头显示开发,不过性能还是较弱,不能达到30FPS的最低视觉效果,显示效果不佳。
      不过,这个功能可以用于驾驶预警,提示开车偏离车道和侵入的其他车辆,能够实现报警功能。
      另外,新推出的树莓派5具有更强大的GPU和人工智能计算能力,在相同的代码下,可以无缝运行,预期能够达到设定的效果。
      因此,**开发,围绕功能精简和升级硬件两个方向,预期均能够实现可供实用的开发项目。再次感谢与非网和DigiKey提供的学习展示机会。


分享到:
回复

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /3 下一条