Java – opencv mat processing time

I want to know whether the SRC (source) and DST (destination) of OpenCV function have different variables that will affect the processing time I have the following two functions

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

And

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,mMattemp_ir);
    return mMattemp_ir;
}

Which two are better? What are the advantages of one over the other?

Solution

To know exactly, just clip your gety method call between opencv's built-in methods double gettickcount() and double gettickfrequency() (need to be converted to 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);

For best results, do this on multiple calls and evaluate the results

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>