使用OpenCL提高OpenCV圖像處理性能 | speed up opencv image processing with OpenCL

本文首發於我的博客kezunlin.me/post/59afd8…,歡迎閱讀最新內容!api

speed up opencv image processing with OpenCL less

Guide

OpenCL is a framework for writing programs that execute on these heterogenous platforms. The developers of an OpenCL library utilize all OpenCL compatible devices (CPUs, GPUs, DSPs, FPGAs etc) they find on a computer / device and assign the right tasks to the right processor.ide

Keep in mind that as a user of OpenCV library you are not developing any OpenCL library. In fact you are not even a user of the OpenCL library because all the details are hidden behind the transparent API/TAPI.post

config

cmake config by default for compiling OpenCV:ui

WITH_OPENCL ON複製代碼

example

Mat

#include "opencv2/opencv.hpp"
using namespace cv;
 
int main(int argc, char** argv)
{
    Mat img, gray;
    img = imread("image.jpg", IMREAD_COLOR);
     
    cvtColor(img, gray, COLOR_BGR2GRAY);
    GaussianBlur(gray, gray,Size(7, 7), 1.5);
    Canny(gray, gray, 0, 50);
     
    imshow("edges", gray);
    waitKey();
    return 0;
}複製代碼

UMat

#include "opencv2/opencv.hpp"
using namespace cv;
 
int main(int argc, char** argv)
{
    UMat img, gray;
    imread("image.jpg", IMREAD_COLOR).copyTo(img);
     
    cvtColor(img, gray, COLOR_BGR2GRAY);
    GaussianBlur(gray, gray,Size(7, 7), 1.5);
    Canny(gray, gray, 0, 50);
     
    imshow("edges", gray);
    waitKey();
    return 0;
}複製代碼

UMat with transparent API/TAPIthis

Reference

History

  • 20190626: created.

Copyright

相關文章
相關標籤/搜索