resize

功能介绍

实现图像缩放功能,暂时只支持NV12格式。

代码仓库:https://c-gitlab.horizon.ai/HHP/box/hobot_cv

支持平台

平台 运行方式 示例功能
旭日X3派 Ubuntu 20.04 读取图片,进行缩放

准备工作

旭日X3派

  1. 旭日X3派已烧录好地平线提供的Ubuntu 20.04系统镜像。

  2. 旭日X3派已成功安装TogetheROS.Bot。

使用介绍

旭日X3派

# 配置TogetheROS环境
source /opt/tros/setup.bash

# 从TogetheROS的安装路径中拷贝出运行示例需要的模型和配置文件。
cp -r /opt/tros/lib/hobot_cv/config/ .

# 启动launch文件
ros2 launch hobot_cv hobot_cv_resize.launch.py

结果分析

resize

[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [resize_example-1]: process started with pid [3083]
[resize_example-1] [INFO] [1655951649.930987924] [example]:
[resize_example-1] source image config/test.jpg is 1920x1080 pixels
[resize_example-1] [INFO] [1655951649.931155799] [example]: resize image to 960x540 pixels, time cost: 297 ms
[resize_example-1] [INFO] [1655951650.039223757] [example]: resize image to 960x540 pixels, time cost: 15 ms
[INFO] [resize_example-1]: process has finished cleanly [pid 3083]

根据log显示,测试程序完成了对本地1920x1080分辨率图片resize的处理。接口调用两次,两次耗时分别如下。

图片处理 第一次运行耗时 第二次运行耗时
1920x1080 resize到960x540 297ms 15ms

因为第一次运行,需要对vps硬件进行配置所以耗时较多,如果不再更改硬件配置属性,硬件直接进行处理,耗时就会显著降低。

本地原图1920x1080、resize后960x540图片如下:

../../_images/ori-resize.png

性能对比

使用top命令查看cpu占用,cpu占用为测试进程cpu占比。 耗时统计单位为ms,循环处理1000次取平均值。 测试时锁定cpu频率:

sudo bash -c 'echo performance > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor'
src wxh dst wxh vps耗时 vps接口
cpu占用
bpu耗时 bpu接口
cpu占用
opencv耗时 opencv处理
cpu占用
512x512 128x128 1.53789 25.9 1.11054 89 1.71119 100.3
640x640 320x320 2.48536 28.5 1.82232 88 1.82384 338.9
896x896 384x384 4.54422 24.6 2.81954 79.7 7.84396 273.1
1024x1024 512x512 6.01103 25.2 3.89325 81.7 2.55761 381.7
1920x1088 512x512 11.0406 20.6 5.8513 71.1 8.19324 380.1
1920x1080 960x544 11.1562 22.3 7.09085 77.7 15.2978 382.4