Ouster雷达实现障碍物分类检测
发布时间:2026-09-08 16:43:32.94 文章来源:AiSoftCloud 浏览次数:19 下载次数:1 

环境准备

操作系统:ubuntu 22.04

安装依赖

安装ouster-sdk

  1. pip install ouster-sdk==0.14.0

安装yolo5:

  1. pip install ultralytics

Demo下载

github地址:https://github.com/ouster-lidar/ouster-yolov5-demo/tree/main

  1. git clone https://github.com/ouster-lidar/ouster-yolov5-demo.git
  2. git clone https://github.com/ouster-lidar/yolov5-ouster-lidar-data.git

安装依赖

  1. cd ouster-yolov5-demo
  2. pip install -r requirements.txt

下载数据

  1. cd yolov5-ouster-lidar-data
  2. sudo apt install git-lfs
  3. git lfs install
  4. git lfs pull
  5. cp -r Ouster-YOLOv5-sample.* ../ouster-yolov5-demo

修改 yolo5_opencv.py(否则运行的时候会报错):

主要修改get_scan_size_and_fps函数:
修改前:

  1. def get_scan_size_and_fps(sensor_info: client.SensorInfo):
  2. """extract the scan width x heigh x fps information from the json file"""
  3. w = sensor_info.mode.cols
  4. h = len(sensor_info.beam_altitude_angles)
  5. fps = sensor_info.mode.frequency

修改后:

  1. def get_scan_size_and_fps(sensor_info: client.SensorInfo):
  2. """extract the scan width x heigh x fps information from the json file"""
  3. print(sensor_info)
  4. lidar_mode = sensor_info.config.lidar_mode
  5. w = sensor_info.format.columns_per_frame
  6. h = sensor_info.format.pixels_per_column
  7. print(lidar_mode)
  8. #w = sensor_info.mode.cols
  9. #h = len(sensor_info.beam_altitude_angles)
  10. mode_str = str(lidar_mode).split('.')[-1]
  11. fps = int(mode_str.split('x')[-1])
  12. print(w, h, fps)
  13. return w, h, fps

cv2.imshow对应的行也注释掉(如果用的docker,会无法显示):

  1. #cv2.imshow('Lidar Detection', stacked_images)

变动如下:

  1. ubuntu@708caa27696a:~/ouster/ouster-yolov5-demo$ git diff
  2. diff --git a/yolo5_opencv.py b/yolo5_opencv.py
  3. index 221841f..7691dad 100644
  4. --- a/yolo5_opencv.py
  5. +++ b/yolo5_opencv.py
  6. @@ -59,9 +59,16 @@ def get_frame_from_scan(scan, channel):
  7. def get_scan_size_and_fps(sensor_info: client.SensorInfo):
  8. """extract the scan width x heigh x fps information from the json file"""
  9. - w = sensor_info.mode.cols
  10. - h = len(sensor_info.beam_altitude_angles)
  11. - fps = sensor_info.mode.frequency
  12. + print(sensor_info)
  13. + lidar_mode = sensor_info.config.lidar_mode
  14. + w = sensor_info.format.columns_per_frame
  15. + h = sensor_info.format.pixels_per_column
  16. + print(lidar_mode)
  17. + #w = sensor_info.mode.cols
  18. + #h = len(sensor_info.beam_altitude_angles)
  19. + mode_str = str(lidar_mode).split('.')[-1]
  20. + fps = int(mode_str.split('x')[-1])
  21. + print(w, h, fps)
  22. return w, h, fps
  23. @@ -107,7 +114,7 @@ def run():
  24. stacked_images = cv2.vconcat(images)
  25. converted_image = cv2.convertScaleAbs(stacked_images * 255)
  26. - cv2.imshow('Lidar Detection', stacked_images)
  27. + #cv2.imshow('Lidar Detection', stacked_images)
  28. out.write(converted_image)
  29. key = cv2.waitKey(1) & 0xFF

运行:

  1. python3 yolo5_opencv.py

会自动生成output.avi文件,转换成mp4文件:

  1. ffmpeg -i output.avi -c copy output.mp4

使用vlc播放mp4文件,查看结果:

  1. # sudo apt install vlc
  2. vlc output.mp4

参考文章

Ouster雷达Wiki

更多文章可关注公众号
aisoftcloud