3.6. HobotCV
功能介绍
HobotCV为应用开发提供类似OpenCV接口。目前实现了图片的crop,resize,crop&resize以及gaussian filter功能,暂时只支持nv12格式。
准备工作
旭日X3派已烧录好地平线提供的Ubuntu20.0.4或Linux系统镜像。
旭日X3派已成功安装TogetherROS。
使用介绍
crop&resize
Ubuntu
# 配置TogetherROS环境
source /opt/tros/setup.bash
# 从TogetherROS的安装路径中拷贝出运行示例需要的模型和配置文件。
cp -r /opt/tros/lib/hobot_cv/config/ .
# 启动launch文件
ros2 launch hobot_cv hobot_cv_crop_resize.launch.py
Linux
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/opt/tros/lib/
# 从TogetherROS的安装路径中拷贝出运行示例需要的模型和配置文件。
cp -r /opt/tros/lib/hobot_cv/config/ .
# 启动测试程序
/opt/tros/lib/hobot_cv/example
guassian filter
当前版本支持的参数范围如下:
滤波类型:高斯滤波
支持的数据类型:int16
支持的分辨率:320x240。
滤波核:高斯3x3
sigmax: 0.
sigmay: 0.
package中提供了简单测试程序,输入为本地的tof图片,调用hobot_cv中接口实现高斯滤波功能。具体接口说明可参考hobot_cv pakcage中的README.md进一步了解。
运行命令:
Ubuntu
# 配置TogetherROS环境
source /opt/tros/setup.bash
# 从TogetherROS的安装路径中拷贝出运行示例需要的模型和配置文件。
cp -r /opt/tros/lib/hobot_cv/config/ .
# 启动测试程序pkg
ros2 launch hobot_cv hobot_cv_gaussian_blur.launch.py
Linux
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/opt/tros/lib/
# config中为示例使用的模型,根据实际安装路径进行拷贝
cp -r /opt/tros/lib/hobot_cv/config/ .
# 启动测试程序pkg
/opt/tros/lib/hobot_cv/test_gaussian_blur
结果分析
crop&resize
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [example-1]: process started with pid [396814]
[example-1] [BPU_PLAT]BPU Platform Version(1.3.1)!
[example-1] [HBRT] set log level as 0. version = 3.13.27
[example-1] [DNN] Runtime version = 1.8.4_(3.13.27 HBRT)
[example-1]
[example-1] source image config/test.jpg is 1920x1080 pixels
[example-1] resize image to 960x540 pixels, time cost: 30 ms
[example-1] crop image to 960x540 pixels, time cost: 2 ms
[example-1] crop image to 960x540 pixels and resize image to 1920x1080 pixels, time cost: 20 ms
[example-1]
[INFO] [example-1]: process has finished cleanly [pid 396814]
根据log显示,测试程序完成了对本地1920x1080分辨率图片resize,crop,crop&resize的处理。
从1920x1080分辨率图片resize到960x540分辨率,耗时为35 ms。
从1920x1080分辨率图片crop出960x540分辨率的图片,耗时为2 ms。
从1920x1080分辨率图片先crop出960x540分辨率的图片,再将crop出的图片resize到1920x1080分辨率,耗时为22 ms。
本地原图1920x1080、resize后960x540、crop后960x540和crop&resize后1920x1080分辨率图片如下:
gaussian filter
输出结果:
===================
image name :images/frame1_4.png
infe cost time:1314
guss_time cost time:2685
hobotcv save rate:0.510615
analyse_result start
---------GaussianBlur
out_filter type:2,cols:320,rows:240,channel:1
cls_filter type:2,cols:320,rows:240,channel:1
out_filter minvalue:96,max:2363
out_filter min,x:319,y:115
out_filter max,x:147,y:239
cls_filter minvalue:96,max:2364
cls_filter min,x:319,y:115
cls_filter max,x:147,y:239
diff diff diff
mat_diff minvalue:0,max:2
mat_diff min,x:2,y:0
mat_diff max,x:110,y:14
error sum:8.46524e+06,max:2,mean_error:0.439232
analyse_result,time_used_ms_end:2
analyse_result end
-------------------------
其中:
infe cost time:1314 //表示hobotcv加速的高斯滤波耗时1314微秒.
guss_time cost time:2685 //表示opencv的高斯滤波耗时2685微秒.
hobotcv save rate = (guss_time cost time - infe cost time)/ guss_time cost time = 0.510615
从以上比较结果,经过hobotcv加速后性能提升50%。
error sum:8.46524e+06,max:2,mean_error:0.439232 //单张图片总误差是:8.46524e+06,单个像素最大误差是:2,平均误差:0.439232
平均误差 = sum / (width * height) = 8.46524e+06 / (320 * 240)