kiltek
kiltek

Reputation: 3211

Method performance comparison

Which method is faster for retrieving a submat, adjustROI() or submat() ? I want to know it because im working with java and i got a loop over many images of size 1600*1200.

Thanks in advance.

P.S.: For anyone, who has noticed that the same post exists in the OpenCV Q&A Forum: Since nobody was able to answer the question, I decided to put it on Stackoverflow to increase the chance of someone answering it.

Upvotes: 1

Views: 102

Answers (1)

Bull
Bull

Reputation: 11941

The best idea is benchmarking as suggested by @Ilya Kurnosov. However I predict virtually no difference based on the source below. It would seem that Mat creation and JNI call overhead would be big compared to the work that actually occurs, but a benchmark may prove me wrong.

A big issue with both methods, if you are sliding a rectangle around pixel by pixel, is that you will create almost two million objects. (OTOH you can do this in c++ without creating any new objects, so if its gotta be fast ...)

public Mat submat(int rowStart, int rowEnd, int colStart, int colEnd)
{

    Mat retVal = new Mat(n_submat_rr(nativeObj, rowStart, rowEnd, colStart, colEnd));

    return retVal;
}

public Mat adjustROI(int dtop, int dbottom, int dleft, int dright)
{

    Mat retVal = new Mat(n_adjustROI(nativeObj, dtop, dbottom, dleft, dright));

    return retVal;
}

Upvotes: 1

Related Questions