Gstreamer + OpenCV - www.deltavision.io

本文探讨了在嵌入式平台如ARM系统上,为何需要在OpenCV中使用Gstreamer,以减少图像处理中的数据拷贝,提高性能。通过Gstreamer,可以利用硬件加速、处理不同输入源和输出显示。文章指出,由于ARM系统内存操作速度较慢,特别是在处理uncached DMA Buffer时,应避免CPU拷贝,而OpenCV的某些函数如cvtColor和clone可能导致大量CPU资源消耗。虽然OpenCV支持OpenCL加速,但在实时图像处理中,由于数据加载到GPU内存的过程存在拷贝,这在嵌入式设备上并不理想。作者建议,在特定场景下,可以通过修改OpenCV或使用异步处理来解决拷贝问题,优化性能。

Gstreamer

首先,要先讨论下为什么需要在OpenCV上用上Gstreamer. 比如直接一个摄像头 v4l2 图像传给 OpenCV 不行吗?

Gstreamer是嵌入式平台处理Media的首选组件, 像Nvdia/TI/NXP/Rockchip平台, 都是使用Gstreamer来整合Media应用. 在Rockchip平台上, 已经有为Gstreamer开发了像Decode/Encode/ISP-Camera/2D加速器/DRM-Display-sink这些的Plugin.

所以OpenCV如果链接上Gstreamer, 输入源就不仅仅是摄像头, 还可以是RTSP/本地视频;输出显示的代码可以不用写, 让Gstreamer来显示; 转换格式让Gstreamer来转, 利用硬件加速; 处理的图像送回Gstreamer编码.

ARM

在ARM系统上做Media的开发, 有一个原则要很重要, 就是 : 避免拷贝.
如果你手边正好有一块ARM板子和Linux PC, 可以尝试在上面跑一些memcpy的Test. 一般来说, 测试的性能会相差5,6倍. 即时是DDR同频的两个系统, 性能也会差到3-4倍(不过也可能是DDR其他参数有影响?). 内存操作速度的劣势是RISC天生的, ARM也不列外. (虽然也没有研究过对应微处理器结构,道听途说 :-P)

还有一个更影响速度的就是, 这些Buffer一般都是uncached的DMA Buffer, 为了保证cpu和其他ip的内存一致性, 所以CPU读写速度就更慢了..

在开发OpenCV + Gstreamer的过程中, 一定要尽量避免拷贝的发生, 如果一定要有, 也不能是由CPU来做. (替代可以是2D加速器, GPU) (当然这里用2D加速拷出来后buffer,默认还是uncached的,还是不适合CPU直接在上面处理,就算改成cache的,cache刷新的时间也要10ms+。。不过如果你的算法需要CPU去实时处理每帧的话,一般的ARM CPU都做不到吧)

OpenCV

之前只在X86上

错误:事务测试失败: file /usr/sbin/alternatives from install of chkconfig-1.19.1-1.el8.x86_64 conflicts with file from package alternatives-1.24-2.el9.x86_64 file /usr/share/man/man8/alternatives.8.gz from install of chkconfig-1.19.1-1.el8.x86_64 conflicts with file from package alternatives-1.24-2.el9.x86_64 file /usr/lib/rpm/macros.d/macros.systemd from install of systemd-239-51.el8_5.2.x86_64 conflicts with file from package systemd-rpm-macros-252-57.el9.noarch file /usr/sbin/service from install of initscripts-10.00.15-1.el8.x86_64 conflicts with file from package initscripts-service-10.11.8-4.el9.noarch file /usr/share/man/man8/service.8.gz from install of initscripts-10.00.15-1.el8.x86_64 conflicts with file from package initscripts-service-10.11.8-4.el9.noarch file /usr/lib/udev/rename_device from install of initscripts-10.00.15-1.el8.x86_64 conflicts with file from package initscripts-rename-device-10.11.8-4.el9.x86_64 file /usr/lib64/girepository-1.0/GstInsertBin-1.0.typelib from install of gstreamer1-plugins-bad-free-1.16.1-1.el8.x86_64 conflicts with file from package gstreamer1-plugins-bad-free-libs-1.22.12-4.el9.x86_64 file /usr/lib64/girepository-1.0/GstMpegts-1.0.typelib from install of gstreamer1-plugins-bad-free-1.16.1-1.el8.x86_64 conflicts with file from package gstreamer1-plugins-bad-free-libs-1.22.12-4.el9.x86_64 file /usr/lib64/girepository-1.0/GstPlayer-1.0.typelib from install of gstreamer1-plugins-bad-free-1.16.1-1.el8.x86_64 conflicts with file from package gstreamer1-plugins-bad-free-libs-1.22.12-4.el9.x86_64 file /usr/lib64/girepository-1.0/GstWebRTC-1.0.typelib from install of gstreamer1-plugins-bad-free-1.16.1-1.el8.x86_64 conflicts with file from package gstreamer1-plugins-bad-free-libs-1.22.12-4.el9.x86_64 file /usr/lib64/libgstadaptivedemux-1.0.so.0 from install of gstreamer1-plugins-bad-free-1.16.1-1.el8.x86_64 conflicts with file from package gstreamer1-plugins-bad-free-libs-1.22.12-4.el9.x86_64 file /usr/lib64/libgstbadaudio-1.0.so.0 from install of gstreamer1-plugins-bad-free-1.16.1-1.el8.x86_64 conflicts with file from package gstreamer1-plugins-bad-free-libs-1.22.12-4.el9.x86_64 file /usr/lib64/libgstbasecamerabinsrc-1.0.so.0 from install of gstreamer1-plugins-bad-free-1.16.1-1.el8.x86_64 conflicts with file from package gstreamer1-plugins-bad-free-libs-1.22.12-4.el9.x86_64 file /usr/lib64/libgstcodecparsers-1.0.so.0 from install of gstreamer1-plugins-bad-free-1.16.1-1.el8.x86_64 conflicts with file from package gstreamer1-plugins-bad-free-libs-1.22.12-4.el9.x86_64 file /usr/lib64/libgstinsertbin-1.0.so.0 from install of gstreamer1-plugins-bad-free-1.16.1-1.el8.x86_64 conflicts with file from package gstreamer1-plugins-bad-free-libs-1.22.12-4.el9.x86_64 file /usr/lib64/libgstisoff-1.0.so.0 from install of gstreamer1-plugins-bad-free-1.16.1-1.el8.x86_64 conflicts with file from package gstreamer1-plugins-bad-free-libs-1.22.12-4.el9.x86_64 file /usr/lib64/libgstmpegts-1.0.so.0 from install of gstreamer1-plugins-bad-free-1.16.1-1.el8.x86_64 conflicts with file from package gstreamer1-plugins-bad-free-libs-1.22.12-4.el9.x86_64 file /usr/lib64/libgstphotography-1.0.so.0 from install of gstreamer1-plugins-bad-free-1.16.1-1.el8.x86_64 conflicts with file from package gstreamer1-plugins-bad-free-libs-1.22.12-4.el9.x86_64 file /usr/lib64/libgstplayer-1.0.so.0 from install of gstreamer1-plugins-bad-free-1.16.1-1.el8.x86_64 conflicts with file from package gstreamer1-plugins-bad-free-libs-1.22.12-4.el9.x86_64 file /usr/lib64/libgstsctp-1.0.so.0 from install of gstreamer1-plugins-bad-free-1.16.1-1.el8.x86_64 conflicts with file from package gstreamer1-plugins-bad-free-libs-1.22.12-4.el9.x86_64 file /usr/lib64/libgsturidownloader-1.0.so.0 from install of gstreamer1-plugins-bad-free-1.16.1-1.el8.x86_64 conflicts with file from package gstreamer1-plugins-bad-free-libs-1.22.12-4.el9.x86_64 file /usr/lib64/libgstwayland-1.0.so.0 from install of gstreamer1-plugins-bad-free-1.16.1-1.el8.x86_64 conflicts with file from package gstreamer1-plugins-bad-free-libs-1.22.12-4.el9.x86_64 file /usr/lib64/libgstwebrtc-1.0.so.0 from install of gstreamer1-plugins-bad-free-1.16.1-1.el8.x86_64 conflicts with file from package gstreamer1-plugins-bad-free-libs-1.22.12-4.el9.x86_64 file /usr/bin/jcat-tool from install of fwupd-1.5.9-1.el8_4.x86_64 conflicts with file from package libjcat-0.1.6-3.el9.x86_64 file /usr/lib64/libjcat.so.1.0.0 from install of fwupd-1.5.9-1.el8_4.x86_64 conflicts with file from package libjcat-0.1.6-3.el9.x86_64 file /usr/share/man/man1/jcat-tool.1.gz from install of fwupd-1.5.9-1.el8_4.x86_64 conflicts with file from package libjcat-0.1.6-3.el9.x86_64 file /usr/share/man/man5/oci-hooks.5.gz from install of podman-3.3.1-9.module_el8.5.0+988+b1f0b741.x86_64 conflicts with file from package containers-common-4:1-134.el9.x86_64 file /usr/share/man/man7/bpf-helpers.7.gz from install of bpftool-4.18.0-348.7.1.el8_5.x86_64 conflicts with file from package man-pages-6.04-7.el9.noarch 我在linux上下载samba软件包后先显示了这些
最新发布
11-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值