|
一、项目名称: 智能车载抬头显示系统HUD
二、项目概述: 智能车载抬头显示系统HUD是一个以视频采集为主要输入端口的人机协同车载智能装置,能够提供智能化的辅助驾驶体验和人机交互体验。在本次项目开发中,是围绕ADAS自动驾驶系统,使用OpenVINO的框架,实现对于视野内的驾驶相关场景的分析,提供驾驶辅助。
这个显示系统使用树莓派和7寸树莓派显示屏连接,固定在汽车遮阳板的支架上,可以协同驾驶,供电采用12V点烟器连接的车载USB充电头,不需要对汽车电气作改线工作。
三、作品实物图 3.1 主控树莓派,连接7寸屏如下
3.2 使用罗技摄像头采集图像并显示,其中包括罗技摄像头和用于识别的演示卡通人物 3.3 在显示屏的ipython界面显示摄像头采集的效果
四、演示视频
4.1 如下是树莓派启动后的视频演示效果,见压缩文件
4.2在ipython中演示汽车驶入车道的照片如下
五、项目文档
5.1 源代码和adas模型打包如下
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代码如下
- import cv2
- import matplotlib.pyplot as plt
- import numpy as np
- import openvino as ov
- from pathlib import Path
- import collections
- import time
- from IPython import display
- import ipywidgets as widgets
- import notebook_utils as utils
- from notebook_utils import segmentation_map_to_image, download_file
- base_model_dir = Path("./model").expanduser()
- model_name = "road-segmentation-adas-0001"
- model_xml_name = f'{model_name}.xml'
- model_bin_name = f'{model_name}.bin'
- model_xml_path = base_model_dir / model_xml_name
- core = ov.Core()
- device = widgets.Dropdown(
- options=core.available_devices + ["AUTO"],
- value='AUTO',
- description='Device:',
- disabled=False,
- )
- model = core.read_model(model=model_xml_path)
- compiled_model = core.compile_model(model=model, device_name=device.value)
- input_layer_ir = compiled_model.input(0)
- output_layer_ir = compiled_model.output(0)
- N, C, H, W = input_layer_ir.shape
- colormap = np.array([[68, 1, 84], [48, 103, 141], [53, 183, 120], [199, 216, 52]])
- alpha = 0.3
- # Main processing function to run object detection.
- def run_object_detection(source=0, flip=False, use_popup=False, skip_first_frames=0):
- player = None
- try:
- # Create a video player to play with target fps.
- player = utils.VideoPlayer(
- source=source, flip=flip, fps=30, skip_first_frames=skip_first_frames
- )
- # Start capturing.
- player.start()
- if use_popup:
- title = "Press ESC to Exit"
- cv2.namedWindow(
- winname=title, flags=cv2.WINDOW_GUI_NORMAL | cv2.WINDOW_AUTOSIZE
- )
- while True:
- # Grab the frame.
- frame = player.next()
- if frame is None:
- print("Source ended")
- break
- # If the frame is larger than full HD, reduce size to improve the performance.
- scale = 1280 / max(frame.shape)
- if scale < 1:
- frame = cv2.resize(
- src=frame,
- dsize=None,
- fx=scale,
- fy=scale,
- interpolation=cv2.INTER_AREA,
- )
-
- input_img_resize = cv2.resize( src=frame, dsize=(W, H), interpolation=cv2.INTER_AREA )
- input_img = np.expand_dims( input_img_resize.transpose(2, 0, 1), 0) #plt.imshow(rgb_image)
- # Create a batch of images (size = 1).
- input_img = input_img[np.newaxis, ...]
- f_height, f_width = frame.shape[:2]
-
- # Get the results.
- result = compiled_model([input_image])[output_layer_ir]
- segmentation_mask = np.argmax(result, axis=1)
- rgb_image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
- mask = segmentation_map_to_image(segmentation_mask, colormap)
- resized_mask = cv2.resize(mask, (f_width, f_height))
- image_with_mask = cv2.addWeighted(resized_mask, alpha, frame, 1 - alpha, 0)
-
- cv2.putText(
- img=image_with_mask,
- text=f"Keep Going...",
- org=(20, 40),
- fontFace=cv2.FONT_HERSHEY_COMPLEX,
- fontScale=f_width / 1000,
- color=(0, 0, 255),
- thickness=1,
- lineType=cv2.LINE_AA,
- )
- # Use this workaround if there is flickering.
- if use_popup:
- cv2.imshow(winname=title, mat=image_with_mask)
- key = cv2.waitKey(1)
- # escape = 27
- if key == 27:
- break
- else:
- _, encoded_img = cv2.imencode(
- ext=".jpg", img=image_with_mask, params=[cv2.IMWRITE_JPEG_QUALITY, 100]
- )
- i = display.Image(data=encoded_img)
- display.clear_output(wait=True)
- display.display(i)
- # ctrl-c
- except KeyboardInterrupt:
- print("Interrupted")
- except RuntimeError as e:
- print(e)
- finally:
- if player is not None:
- # Stop capturing.
- player.stop()
- if use_popup:
- cv2.destroyAllWindows()
- USE_WEBCAM = False
- video_file = "./data/car-detection.mp4"
- cam_id = 0
- source = cam_id if USE_WEBCAM else video_file
- run_object_detection(source=source, flip=isinstance(source, int), use_popup=False)
复制代码
5.3 小结和**开发
本次开发,选择使用树莓派4B,能够完成基于OpenVINO的人工智能ADAS 抬头显示开发,不过性能还是较弱,不能达到30FPS的最低视觉效果,显示效果不佳。
不过,这个功能可以用于驾驶预警,提示开车偏离车道和侵入的其他车辆,能够实现报警功能。
另外,新推出的树莓派5具有更强大的GPU和人工智能计算能力,在相同的代码下,可以无缝运行,预期能够达到设定的效果。
因此,**开发,围绕功能精简和升级硬件两个方向,预期均能够实现可供实用的开发项目。再次感谢与非网和DigiKey提供的学习展示机会。
|