Build OpenCV with OpenCL Enabled and ON

孤街浪徒 提交于 2019-12-30 11:38:34

问题


I'm trying to run simple code with OpenCL enabled on OpenCV.

I've read the intro to OCL documentation and, as instructed, I built opencv with this flag: WITH_OPENCL=ON.

I did this by doing cmake -DWITH_OPENCL=ON and then built opencv on Mac (OS X Yosemite).

I then tried to run my code, but, according to my code, haveOpenCL() is false.

#include <iostream>
#include <fstream>
#include <string>
#include <iterator>
#include <opencv2/opencv.hpp>
#include <opencv2/core/ocl.hpp>

using namespace std;

int  main ()
{
        cv::ocl::setUseOpenCL(true);
        cout << cv::ocl::haveOpenCL() << endl;
        if  ( ! cv::ocl::haveOpenCL ())
        {
                cout  <<  "OpenCL IS not avaiable ..."  <<  endl ;
                return 0;
        }

Does anybody know how to get OpenCV-OpenCL up and running?

UPDATE:

I checked my cvconfig.h file in opencv/build and this is what it says about OpenCL: /* OpenCL Support / / #undef HAVE_OPENCL / / #undef HAVE_OPENCL_STATIC / / #undef HAVE_OPENCL_SVM */

I'm assuming that if OpenCL is really enabled, then the second line should be something like #define HAVE_OPENCL 1

This is auto-generated, so how can I fix this so that HAVE_OPENCL is 1?


回答1:


That is how I installed OpenCV 3.0 and that is also how I checked that it was working. Checking the documentation here : http://docs.opencv.org/modules/ocl/doc/introduction.html

To correctly run the OCL module, you need to have the OpenCL runtime provided by the device vendor, typically the device driver.

To enable OCL support, configure OpenCV using CMake with WITH_OPENCL=ON. When the flag is set and if OpenCL SDK is installed, the full-featured OpenCV OCL module is built. Otherwise, the module may be not built.

So I would try to make sure you have GPU that supports it and then make sure you have the drivers (SDK?) I actually did some work with OpenCL first before installing OpenCV to make sure I had some understanding of how they worked independently.



来源:https://stackoverflow.com/questions/31257688/build-opencv-with-opencl-enabled-and-on

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!