OpenCV之OpenCL介绍

Intro

介绍

Open Computing Language (OpenCL) is an open standard for writing code that runs across heterogeneous platforms including CPUs, GPUs, DSPs and etc. In particular OpenCL provides applications with an access to GPUs for non-graphical computing (GPGPU) that in some cases results in significant speed-up. In Computer Vision many algorithms can run on a GPU much more effectively than on a CPU: e.g. image processing, matrix arithmetic, computational photography, object detection etc.

开放计算语言(OpenCL)是一种开放标准,用于编写跨异构平台(包括CPU、GPU、DSP等)运行的代码。尤其是,OpenCL为应用程序提供了对GPU的访问,以进行非图形计算(GPGPU),在某些情况下会显著提高速度。在计算机视觉中,许多算法可以在GPU上比在CPU上更有效地运行:例如图像处理、矩阵运算、计算摄影、目标检测等。

History

历史

Acceleration of OpenCV with OpenCL started 2011 by AMD. As the result the OpenCV-2.4.3 release included the new oclmodule containing OpenCL implementations of some existing OpenCV algorithms. That is, when OpenCL runtime and a compatible device are available on a client machine, user may call cv::ocl::resize() instead of cv::resize() to use the accelerated code. During 3 years more and more functions and classes have been added to the ocl module; but it has been a separate API alongside with the primary CPU-oriented API in OpenCV-2.x.

​AMD从2011年开始用OpenCL加速OpenCV。因此,OpenCV-2.4.3版本包含了新的OCL模块,其中包含一些现有OpenCV算法的OpenCL实现。也就是说,当客户端计算机上有OpenCL运行时和兼容设备时,用户可以调用cv::ocl::resize()而不是cv::resize()来使用加速代码。三年来,ocl模块中增加了越来越多的函数和类;但它与OpenCV-2中主要的面向CPU的API相关独立。​

In OpenCV-3.x the architecture concept has been changed to the so-called Transparent API (T-API). In the new architecture a separate OpenCL-accelerated cv::ocl::resize() is removed from external API and becomes a branch in a regular cv::resize(). This branch is called automatically when it’s possible and makes sense from the performance point of view. The T-API implementation was sponsored by AMD and Intel companies.

​在OpenCV-3.x中,架构概念已更改为所谓的透明API(T-API)。在新的体系结构中,一个单独的OpenCL加速cv::ocl::resize()从外部API中删除,并成为常规cv::resize()中的一个分支。在可能的情况下,会自动调用该分支,并且从性能角度来看,该分支是有意义的。T-API的实现是由AMD和英特尔公司赞助的。

Numbers

Some performance numbers are shown on the picture below:

一些性能数据如下图所示:

Code sample

代码示例

Regular CPU code

常规CPU代码

// initialization
VideoCapture vcap(...);
CascadeClassifier fd("haar_ff.xml");
Mat frame, frameGray;
vector<rect> faces;
for(;;){
  // processing loop
  vcap >> frame;
  cvtColor(frame, frameGray, BGR2GRAY);
  equalizeHist(frameGray, frameGray);
  fd.detectMultiScale(frameGray, faces, ...);
  // draw rectangles …
  // show image …
}

OpenCL-aware code OpenCV-2.x

支持OpenCL的代码OpenCV-2.x

// initialization
VideoCapture vcap(...);
ocl::OclCascadeClassifier fd("haar_ff.xml");
ocl::oclMat frame, frameGray;
Mat frameCpu;
vector<rect> faces;
for(;;){
  // processing loop
  vcap >> frameCpu;
  frame = frameCpu;
  ocl::cvtColor(frame, frameGray, BGR2GRAY);
  ocl::equalizeHist(frameGray, frameGray);
  fd.detectMultiScale(frameGray, faces, ...);
  // draw rectangles …
  // show image …
}

OpenCL-aware code OpenCV-3.x

支持OpenCL的代码OpenCV-3.x

// initialization
VideoCapture vcap(...);
CascadeClassifier fd("haar_ff.xml");
UMat frame, frameGray;
vector<rect> faces;
for(;;){
  // processing loop
  vcap >> frame;
  cvtColor(frame, frameGray, BGR2GRAY);
  equalizeHist(frameGray, frameGray);
  fd.detectMultiScale(frameGray, faces, ...);
  // draw rectangles …
  // show image …
}

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值