How to set up opencl in opencv for android

asked 2016-05-22 11:08:03 -0500

Heng gravatar image

hi,everyone, I want to use opencl module in opencv in my android application. I use native C++ and the version of opencv is 3.1.0. I first run the following code in win32 console application on my computer, the opencl module works, but when I directly use this code on android platform, I find that "haveOpenCL" return 0. The question is:

  • How can opencv find the openCL lib path, for example, the path of in my android device is


Where can I set this lib path in my program?

  • Is any tutorial for building opencl module on opencv for android?

Any suggestions are welcome!

#include <opencv2/opencv.hpp>
#include <opencv2/core/ocl.hpp>

using namespace cv;
using namespace std;
int main(int argc, char** argv)

cout << cv::ocl::haveOpenCL() << endl;
if (cv::ocl::haveOpenCL())
cout << "OpenCL IS avaiable ..." << endl;
//return 0;

UMat img;
img = imread("test.jpg").

UMat result;
cv::Mat H = cv::Mat::eye(3, 3, CV_64FC1);

for (int i=0;i<800;i++)
warpPerspective(img, result, H, img.size());

return 0;
edit retag flag offensive close merge delete


I have the same issue. In my app I'm using useOpenCL() that behaves correctly on Ubuntu but not in my Android app. When I compare an warpAffine() using Mat or UMat, the Android app transform is 7 xs faster using UMat irregardless if I use ocl::setUseOpenCL(false); or ocl::setUseOpenCL(true). It does however make a big difference if I do this on Ubuntu. I'm using opencv 3.2 and the Android Opencv manager.

epatton gravatar imageepatton ( 2017-08-18 20:14:16 -0500 )edit