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

标签 opencv image-processing opencl x86-64 opencv3.0

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

cv::Umat 和 TAPI 有两个介绍:

但是如果我有:

  1. 英特尔 CPU 酷睿 i5 (Haswell) 4xCores (OpenCL Intel CPUs with SSE 4.1, SSE 4.2 or AVX support )
  2. Intel 集成高清显卡 supports OpenCL 1.2
  3. 第一个 nVidia GPU GeForce GTX 970 (Maxwell) supports OpenCL 1.2 和CUDA
  4. 第二个 nVidia GPU GeForce GTX 970 ...

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

我如何选择这 4 种设备中的一种来将 OpenCL 与 cv::Umat 并行执行算法?

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

最佳答案

我使用类似这样的东西来检查用于 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;
}

然后你可以使用这个设置你喜欢的硬件

cv::ocl::Device(context.device(1));

希望对你有帮助。

关于opencv - 如何更改在 OpenCV 中使用 Umat 执行 OpenCL 代码的设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33417451/

相关文章:

c++ - 卡尔曼滤波器没有给出正确的结果

python - 在形态学打开和闭合产生相同结果的情况下?

image - Rust + Rust 图像 - 私有(private) 'Associated Type' ?

c++ - OpenCL,一半与 float 性能

c++ - 错误 : clBuildProgram(CL_BUILD_PROGRAM_FAILURE)

c++ - 使用光流的 OpenCV 跟踪

python - 使用sobel滤波器进行边缘检测后提取每个对象

python - 在 drawChessboardCorners 上使用排序函数时出现打印问题

python - 导入skimage导入数据报错,过滤器

floating-point - OpenCL 归约中 min() 和 max() 的中性元素