OpenCV: Concurrent GetSubImage to extract a portion of an image

By : J.CSF
Source: Stackoverflow.com
Question!

I've implemented a GetSubImage function in order to extract a portion of an image. I use SetROI, Copy, and ResetROI. But this not works when Parallel Tasks are using the same image because of the SetROI is not parallelizable.

Any other way to extract portion of an image that can run concurrent?

By : J.CSF


Answers

You can create a temporary matrix header that only points to a part of the matrix. Then you can use the copyTo() member function on that header. Example in C :

Mat GetSubImage(const Mat
By : ypnos


Finally, to extract a portion of an image, I'm using this function. Used on C# and with the OpenCVSharp wraper:

    static public IplImage GetSubImage(IplImage ipl, CvRect r)
    {
        CvMat submat;
        CvMat mat = ipl.GetSubRect(out submat, r);
        IplImage i = new IplImage(r.Width, r.Height, ipl.Depth, ipl.NChannels);
        Cv.Copy(mat, i);

        mat.Dispose();
        submat.Dispose();           

        return i;
    }
By : J.CSF


This video can help you solving your question :)
By: admin