本文首发于个人博客https://kezunlin.me/post/59afd8b3/,欢迎阅读最新内容!

speed up opencv image processing with OpenCL

Guide

config

cmake config by default for compiling OpenCV:

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;
}

Reference

History

  • 20190626: created.

Copyright

05-11 21:53