2024-11-21 14:16:10 +08:00
|
|
|
|
## Yolov5s+SORT(卡尔曼+匈牙利)
|
|
|
|
|
|
|
|
|
|
利用目标跟踪对检测框进行预测的技术,对目标检测任务进行加速,在yolov5检测的帧之间穿插使用卡尔曼滤波进行目标检测框的预测,减少对模型的调用,实现目标检测帧率提升的目的。
|
|
|
|
|
|
|
|
|
|
#### 代码运行环境:
|
|
|
|
|
|
|
|
|
|
| 开发环境 | rk3588 |
|
|
|
|
|
| -------- | -------------------- |
|
|
|
|
|
| OpenCV | opencv-3.4.3-windows |
|
|
|
|
|
| 调用模型 | YOLOv5s.rknn |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### 主要代码设置:
|
|
|
|
|
|
|
|
|
|
环境配置:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
进入到ROS环境主目录中
|
|
|
|
|
catkin_make #编译程序
|
|
|
|
|
source devel/setup.bash #更新ROS工作环境变量
|
|
|
|
|
rosrun sort_test sortmain #运行SORT加速检测代码
|
|
|
|
|
sudo cat /sys/kernel/debug/rknpu/load #查看npu占用
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 消耗时间分析
|
|
|
|
|
|
|
|
|
|
对于摄像头显示的画面(双目摄像头)
|
|
|
|
|
|
|
|
|
|
读取摄像头画面需要花费1~3ms,60~100ms,(两种极端,忽快忽慢)
|
|
|
|
|
|
2024-11-21 15:39:07 +08:00
|
|
|
|
检测需要花费40ms(40ms上下幅度,±不超过5ms)
|
|
|
|
|
|
|
|
|
|
使用跟踪加速的情况下,跟踪算法花费时间15ms(根据目标框数量,±5ms)
|
2024-11-21 14:16:10 +08:00
|
|
|
|
|
|
|
|
|
标记检测框需要花费0.05ms(多个putText的操作,消耗时间可忽略不计)
|
|
|
|
|
|
|
|
|
|
双目匹配花费50~140ms(出现波动)
|
|
|
|
|
|
|
|
|
|
帧率显示大约花费0.03ms(单个putText的操作,消耗时间可忽略不计)
|
|
|
|
|
|
|
|
|
|
imgshow大约花费3.5ms(单帧图像imgshow的操作)
|
|
|
|
|
|
2024-11-21 21:16:50 +08:00
|
|
|
|
#### 视频读取分析
|
2024-11-21 14:16:10 +08:00
|
|
|
|
|
2024-11-21 21:16:50 +08:00
|
|
|
|
使用python opencv读取一段视频,仅进行读取,消耗时间在25ms左右。
|
2024-11-21 14:16:10 +08:00
|
|
|
|
|
2024-11-28 12:58:19 +08:00
|
|
|
|
```
|
|
|
|
|
while True:
|
|
|
|
|
frame_time = time.time()
|
|
|
|
|
ret, frame = cap.read()
|
|
|
|
|
|
|
|
|
|
if not ret:
|
|
|
|
|
print("End of video or failed to read frame.")
|
|
|
|
|
break
|
|
|
|
|
# 显示当前帧
|
|
|
|
|
cv2.imshow("Video Playback", frame)
|
|
|
|
|
frame_time = time.time() - frame_time
|
|
|
|
|
print(f"frame cost: {1000*frame_time:.2f} ms")
|
|
|
|
|
```
|
|
|
|
|
|
2024-11-21 21:16:50 +08:00
|
|
|
|
![1](./image/1.jpg)
|
2024-11-21 14:16:10 +08:00
|
|
|
|
|
2024-11-21 21:16:50 +08:00
|
|
|
|
使用c++ opencv读取一段时间,仅进行读取,消耗时间在30ms左右,但也有40ms+和50ms+以及10ms的情况,不太稳定。
|
2024-11-21 14:16:10 +08:00
|
|
|
|
|
2024-11-28 12:58:19 +08:00
|
|
|
|
```
|
|
|
|
|
while (true) {
|
|
|
|
|
int64 t = getTickCount();
|
|
|
|
|
// 读取视频帧
|
|
|
|
|
cap >> frame;
|
|
|
|
|
// // 显示当前帧
|
|
|
|
|
// cv::imshow("Video Playback", frame);
|
|
|
|
|
int64 t1 = getTickCount()-t;
|
|
|
|
|
std::cout << frame_num << " frame cost:"<< t1*1000/cv::getTickFrequency()<< "ms" << std::endl;
|
|
|
|
|
frame_num++;
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2024-11-21 21:16:50 +08:00
|
|
|
|
![2](./image/2.jpg)
|
2024-11-21 14:16:10 +08:00
|
|
|
|
|
2024-11-21 21:16:50 +08:00
|
|
|
|
c++不添加指定帧率(cap.set(cv::CAP_PROP_FPS, 30)),读取帧率速度花费时间会很长,不添加指定帧率的情况下读取一帧需要200ms。
|
2024-11-21 14:16:10 +08:00
|
|
|
|
|
2024-11-21 21:16:50 +08:00
|
|
|
|
![3](./image/3.jpg)
|