ephraim
ephraim

Reputation: 436

Correlation between two images using EMGU

I'm already searching for some hours... couldn't find any help..

I'm using EMGU (beginner with that) and found here:(How to calculate the correlation between two images in EMGU?) the way to PERFORM the correlation:

Image<>.MatchTemplate() 

My question is how can I get the x,y shifts.

Thanks a lot in advance.

Upvotes: 0

Views: 679

Answers (2)

Hakan Usakli
Hakan Usakli

Reputation: 592

writing your own loops to find the min/max values and x/y points is not needed and your own code will run much slower than the build in and highly optimized c++ version

the function you are looking for is a one liner

res.MinMax(minValue, maxValue, pointMin, pointMax)

http://www.emgu.com/wiki/files/1.3.0.0/html/a6a35810-2a33-f1a7-ea9a-27371688fd77.htm

here MinMax in use How to find the max occurred color in the picture using EMGU CV in C#?

Upvotes: 1

ephraim
ephraim

Reputation: 436

Gosh... Found out finally + maxVal gives the quality of the Match.

var res = img1.MatchTemplate(img2, TemplateMatchingType.CcoeffNormed);
        int maxXIdx = 0, maxYIdx = 0;
        float maxVal = float.MinValue;
        var dat = res.Data;
        int numChanels = dat.GetLength(2),
            numCols = res.Cols, numRows = res.Rows;
        for (int i = 0; i < numChanels; i++)
        {
            for (int x = 0; x < numCols; x++)
            {
                for (int y = 0; y < numRows; y++)
                {
                    var val = dat[y, x, i];
                    if (val > maxVal)
                    {
                        maxVal = val;
                        maxXIdx = x;
                        maxYIdx = y;
                    }
                }
            }
        }
        int shiftX = maxXIdx, shiftY = maxYIdx;

Upvotes: 0

Related Questions