2012-10-23 16 views
5

Mi piacerebbe sapere se avere variabili diverse per src (sorgente) e dst (destinazione) di una funzione OpenCV avrà un effetto sul tempo di elaborazione. Ho due funzioni sotto che fa la stessa cosa.Tempo di elaborazione OpenCV Mat

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; 
} 

VERSUS

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; 
} 

Quale dei due è migliore? Qual è il vantaggio di uno rispetto all'altro?

+0

http://codereview.stackexchange.com/ – ArtemStorozhuk

+0

Per quanto ne so, ciò che è meglio dipende da ciascuna funzione. Penso che tu possa presumere che usare un dst diverso (se non lo crei apposta) sarà uguale o migliore di dst == src. –

+0

Time it/profile it .. – volting

risposta

3

per sapere con certezza, solo panino il metodo getY chiamate tra i metodi built-in di OpenCV double getTickCount() e double getTickFrequency() come questo (sarà necessario tradurre in 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); 

Per ottenere i migliori risultati fare questo per più chiamate e media i risultati.