OpenCV Mat处理时间

5
我想知道在OpenCV函数中将src(源)和dst(目的地)设为不同的变量是否会影响处理时间。我有以下两个函数,它们完成相同的工作。
public static Mat getY(Mat m){
    Mat mMattemp = new Mat();
    Imgproc.cvtColor(m,mMattemp,Imgproc.COLOR_YUV420sp2RGB);
    Imgproc.cvtColor(mMattemp,mMattemp, Imgproc.COLOR_RGB2HSV);
    Core.inRange(mMattemp, new Scalar(20, 100, 100), new Scalar(30, 255, 255), mMattemp);
    return mMattemp;
}

对比

public static Mat getY(Mat m){
    Mat mMattemp_rgb = new Mat();
    Mat mMattemp_hsv = new Mat();
    Mat mMattemp_ir = new Mat();
    Imgproc.cvtColor(m,mMattemp_rgb,Imgproc.COLOR_YUV420sp2RGB);
    Imgproc.cvtColor(mMattemp_rgb,mMattemp_hsv, Imgproc.COLOR_RGB2HSV);
    Core.inRange(mMattemp_hsv, new Scalar(20, 100, 100), new Scalar(30, 255, 255), mMattemp_ir);
    return mMattemp_ir;
}

这两个中哪一个更好?它们之间有什么优劣势呢?


http://codereview.stackexchange.com/ - ArtemStorozhuk
据我所知,哪种更好取决于每个函数。我认为您可以假设使用不同的dst(如果您没有特意创建它)将等于或优于dst == src。 - Rui Marques
1个回答

3
为了确保准确性,只需将您的getY方法调用嵌套在OpenCV内置方法double getTickCount()double getTickFrequency()之间即可。请使用以下方式(需要转换为java):
//first uniquely name the algorithms to compare (here just getY_TypeA and getY_TypeB)
double durationA = cv::getTickCount();

getY_TypeA(image); // the function to be tested

durationA = cv::getTickCount()-durationA;
durationA /= cv::getTickFrequency(); // the elapsed time in ms

//now call the other method

double durationB = cv::getTickCount();

getY_TypeB(image); // the function to be tested

durationB = cv::getTickCount()-durationB;
durationB /= cv::getTickFrequency(); // the elapsed time in ms

printf("Type A runtime: "+durationA+" Type B runtime: "+durationB);

为了获得最佳结果,请多次调用并平均结果。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接