Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

peculiar matrix reference behaviour

Hi there, So this could very well be due to my lack of understanding of the matrix data type in opencv, so please let me know if that is the case. I have two vectors of Mat types and I am looping through all elements of all these matrices to find their respective norms as such:

    for (k = 0; k < inp.size(); k++)
{
    for (i = 0; i < inp[k].rows; i++)
    {

        for (j = 0; j < inp[k].cols; j++)
        {
            Vec2f& elem = inp[k].at<Vec2f>(i, j);

            a = elem[0];
            b = elem[1];
            c = elem[0];
            d = -elem[1]; 
            xx+= (a*c - b*d);


             elem = modelp[k].at<Vec2f>(i, j);

            a = elem[0];
            b = elem[1];
            c = elem[0];
            d = -elem[1];
            yy += (a*c - b*d);
        }

    }
}

So this should be a fairly simple operations. However, after this loop the two matrices become equal! I think I am messing up the references somehow and make each pixel in one matrix to point to that of the other matrix. But I dont see how this is happening! please help me out because I am very confused. Of course the problem is fixed if I make a new reference for the calculation of the norm of the second matrix, but I still need to know why this is happening.

Thank you J