IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    [原]OpenCV RGB2LAB执行效率测试

    bendanban发表于 2016-03-31 20:00:41
    love 0

    代码

    #include <iostream>
    #include <vector>
    #include <opencv2/opencv.hpp>
    
    #define ERROR_OUT__ std::cerr<<"[ERROR][File:"<<__FILE__<<"][Line:"<<__LINE__<<"]"
    
    #ifndef _DEBUG
    #define TB__(A) int64 A; A = cv::getTickCount()
    #define TE__(A) std::cout << #A << " : " << 1.E3 * double(cv::getTickCount() - A)/double(cv::getTickFrequency()) << "ms" << std::endl
    #else
    #define TB__(A)
    #define TE__(A)
    #endif
    
    class Print{
    public:
        static void min_max_loc(cv::Mat &src){
            std::vector<cv::Mat> mats;
            cv::split(src, mats);
            for (size_t c = 0; c < mats.size(); c++){
                double min_val, max_val;
                cv::Point min_loc, max_loc;
                cv::minMaxLoc(mats[c], &min_val, &max_val, &min_loc, &max_loc);
                printf("channel %d, minv %6.6f, maxv %6.6f, minl [%6d, %6d], maxl [%6d, %6d]\n", \
                    c, min_val, max_val, min_loc.x, min_loc.y, max_loc.x, max_loc.y);
            }
        }
    };
    
    int main(){
        cv::Mat image, cielab, cielabf;
        image.create(720, 1280, CV_8UC3);
        TB__(__randomu);
        cv::randu(image, cv::Scalar::all(0), cv::Scalar::all(256));
        TE__(__randomu);
    
        // warming up
        cv::cvtColor(image, cielab, CV_BGR2Lab);
        TB__(__bgr2lab_8UC3);
        cv::cvtColor(image, cielab, CV_BGR2Lab);
        cielab.convertTo(cielabf, CV_32FC3);
        TE__(__bgr2lab_8UC3);
        Print::min_max_loc(cielabf);
    
    
        image.convertTo(image, CV_32FC3, 1. / 255.);
        // warming up
        cv::cvtColor(image, cielabf, CV_BGR2Lab);
        TB__(__bgr2lab_32FC3);
        cv::cvtColor(image, cielabf, CV_BGR2Lab);
        TE__(__bgr2lab_32FC3);
    
        Print::min_max_loc(cielabf);
    
        return 0;
    }

    测试平台及输出

    CPU : i5-4590 @3.3GHz

    输出:

    __randomu : 2.13923ms
    __bgr2lab_8UC3 : 5.99754ms
    channel 0, minv 0.000000, maxv 255.000000, minl [   460,    420], maxl [   410,    106]
    channel 1, minv 42.000000, maxv 226.000000, minl [   170,     27], maxl [  1260,     43]
    channel 2, minv 20.000000, maxv 222.000000, minl [    61,    223], maxl [   640,     10]
    __bgr2lab_32FC3 : 17.1545ms
    channel 0, minv 0.019787, maxv 99.877167, minl [   460,    420], maxl [   410,    106]
    channel 1, minv -86.124870, maxv 97.908821, minl [   826,    581], maxl [   181,    276]
    channel 2, minv -107.861755, maxv 94.271385, minl [   520,    399], maxl [   839,     96]


沪ICP备19023445号-2号
友情链接