Compile OpenCV with OpenCL ON



I flash the debian with prebuild tensorflow to my Hikey 970 board and try to use GPU acceleration for my OpenCV (3.4.3) project.
When build cmake WITH_OPENCL=ON, OpenCV build with default OpenCL 1.2 not the Mali 2.0, so I changed the cmake to:
-D OPENCL_LIBRARIES=/usr/lib/aarch64-linux-gnu/

The compilation is ok, but when i use a small example to test GPU performance,

#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);
return 0;
the excution time is 4 times slower than the cpu version and it should be 5 times faster.
Does somebody already use OpenCV and OpenCL for GPU acceleration with hikey970 and can give me some advices?


I’ve never tried working with OpenCV on this board (or any other to be honest) but I’m curious how big the image is and whether the performance ratio between CPU and GPU remains the same if you make the image very large or very small.


The image is 1280*720 from my UVC camera and i have not yet tried with bigger or smaller image.
My goal is to do stereo vision with two camera with OpenCL acceleration. I already tried my project with or without OpenCL, the excution time is similar.


GPU is normally more expensive to set up than CPU so for small single images the CPU may win due to being cheaper to initialize. Benefit of GPU may only emerge for large images or for streams of images (which can share setup costs between images).