如何在OpenCV中使用Umat执行OpenCL代码时如何更改设备?

Ale*_*lex 1 opencv x86-64 image-processing opencl opencv3.0

众所周知,OpenCV 3.0支持新类cv::Umat,它提供透明API(TAPI)以自动使用OpenCL,如果它可以:http://code.opencv.org/projects/opencv/wiki/Opencv3#tapi

cv::UmatTAPI 有两个简介:

但如果我有:

  1. Intel CPU Core i5(Haswell)4xCores(OpenCL Intel CPU,支持SSE 4.1,SSE 4.2或AVX)
  2. 英特尔集成高清显卡,支持OpenCL 1.2
  3. 第一款支持OpenCL 1.2 和CUDA的nVidia GPU GeForce GTX 970(Maxwell)
  4. 第二款nVidia GPU GeForce GTX 970 ......

如果我在OpenCV中打开OpenCL,那么如何在OpenCL代码执行时更改设备:在8核CPU,集成高清显卡上,在第一个nVidia GPU或第二个nVidia GPU上?

如何选择这4个设备中的每个设备使用OpenCL进行并行执行算法cv::Umat

例如,如何在4xCore的CPU Core-i5上使用OpenCL加速cv::Umat

Mar*_*rKS 5

我使用这样的东西来检查用于OpenCL支持的版本和硬件.

ocl::setUseOpenCL(true);
if (!ocl::haveOpenCL())
{
    cout << "OpenCL is not available..." << endl;
    //return;
}

cv::ocl::Context context;
if (!context.create(cv::ocl::Device::TYPE_GPU))
{
    cout << "Failed creating the context..." << endl;
    //return;
}

cout << context.ndevices() << " GPU devices are detected." << endl; //This bit provides an overview of the OpenCL devices you have in your computer
for (int i = 0; i < context.ndevices(); i++)
{
    cv::ocl::Device device = context.device(i);
    cout << "name:              " << device.name() << endl;
    cout << "available:         " << device.available() << endl;
    cout << "imageSupport:      " << device.imageSupport() << endl;
    cout << "OpenCL_C_Version:  " << device.OpenCL_C_Version() << endl;
    cout << endl;
}
Run Code Online (Sandbox Code Playgroud)

然后,您可以使用此设置要使用的首选硬件

cv::ocl::Device(context.device(1));
Run Code Online (Sandbox Code Playgroud)

希望这对你有所帮助.