Ask Your Question

sangohan42's profile - activity

2013-03-14 02:39:00 -0500 asked a question Mat Image data access problem

Hello everyone,

First please forgive my english, i'm not native so i may write in a strange manner :S

I recently had to work with openCV for a research project, so i'm quite new and have quite strange problems with it.

My current problem is when I'm trying to use the at function of the Mat class:

Mat cameraTransform(4,4,CV_32F); // I filled this matrix
Mat homogeneousVector1 = (Mat_<double>(4,1)<< projection1->x, projection1->y, projection1->z, 1.0);
Mat coord4DInCurrentFrame1(4,1,CV_32FC1);
 double sum = 0;

            for(int i = 0; i < cameraTransform.rows; i++)
            {
                for(int k = 0; k<homogeneousVector1.cols; k ++)
                {
                    for(int j = 0; j< cameraTransform.cols; j++)
                    {
                        sum += cameraTransform.at<double>(i,j)*homogeneousVector1.at<double>(j,k);
                    }
                    coord4DInCurrentFrame1.at<double>(i,k) = sum;
                    cout << coord4DInCurrentFrame1.at<double>(i,k) << endl; //(2)
                    sum = 0;
                }
            }
cout << coord4DInCurrentFrame1.at<double>(0,0) << ", " << coord4DInCurrentFrame1.at<double>(1,0) << ", " << coord4DInCurrentFrame1.at<double>(2,0) << ")"; //(1)

The values of coord4dInCurrentFrame1 at the point (0,0), (1,0), (2,0), evaluated outside of the for loop(1) are not the same as it is when I evaluated them in the for loop(2).

I've made this little program for test purpose, I know there is more simple way to do matrix multiplication but the error I got here seems very strange to me and I really want to understand where I am wrong in my program.

Thanks for your help