Qt+openCV学习笔记(十二)Qt5.15.2+openCV4.5.5测试opencl加速

前言

前面已经记录了编译带opencl加速的库,本次记录下一个简单的测试,有需要的参考下

一、打印openCL设备基本信息

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

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

    qDebug() << context.ndevices() << " GPU devices are detected." ; //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);
        qDebug() << "name:              " << QString::fromStdString(device.name()) ;
        qDebug() << "available:         " << device.available() ;
        qDebug() << "imageSupport:      " << device.imageSupport() ;
        qDebug() << "OpenCL_C_Version:  " << QString::fromStdString(device.OpenCL_C_Version()) ;

    }

1.win10下mingw 64位编译器输出如下

 2.win10下vs2019 64位编译器输出如下

 3.鸿蒙平板下 输出如下

 二、测试运行时间

void calEdgesCPU() {
    cv::Mat cpuBw, cpuBlur, cpuEdges;
    QTime time; time.start();
    cv::Mat cpuFrame = cv::imread("test.jpg");
//    cv::Mat cpuFrame = cv::imread("/mnt/sdcard/Download/test.jpg");
    qDebug()<<"CPU read time"<

1.win10下mingw 64位编译器输出如下

Qt+openCV学习笔记(十二)Qt5.15.2+openCV4.5.5测试opencl加速_第1张图片

2.win10下vs2019 64位编译器输出如下

Qt+openCV学习笔记(十二)Qt5.15.2+openCV4.5.5测试opencl加速_第2张图片

3.鸿蒙平板下 输出如下

 Qt+openCV学习笔记(十二)Qt5.15.2+openCV4.5.5测试opencl加速_第3张图片

为方便看,笔者整理了一个表格

  mingw64 vs2019 64 android
次数 1 2 3 1 2 3 1 2 3
CPU read time 511     431     559    
CPU cvtColor time 148 345 245 24 112 113 30 250 176
CPU GaussianBlur time 20 6 5 9 5 6 26 5 5
CPU Canny time 322 222 216 99 100 91 234 160 160
                   
 次数  1 2  3   1  2  3  1  2  3
GPU read time 419     439     535    
GPU sentToGpu time 63 32 43 34 32 43 38 21 20
GPU cvtColor time 53 0 0 6 0 0 59 5 5
GPU GaussianBlur time 27 20 21 30 19 21 36 45 43
GPU Canny time 20 2 3 18 2 3 345 234 236

为了有效对比下,笔者用PS生成了一张10M的图片,分别使用不同编译器生成的程序处理。硬件加速的结果,有点让笔者意外,但效果还是有的

后记

笔者曾尝试查找,umat如何选择使用的哪一个openCL硬件。没有查找到方便的接口,只查到使用openCL的接口。若是有时间,确实应该进修一下了

你可能感兴趣的:(Qt+openCV,qt5.15.2,opencv4.5.5,msvc2019)