Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hi,

I don't know if it is particularly efficient but you can do the following using repeat

Mat src ...;  // your 3XN matrix
Mat lastRow = src.row( 2 );
Mat tmp;
repeat(lastRow, tmp, 3, 1 );  // create a tmp matrix of 3xN whose elements are repeated elements of the last row of src
src = src / tmp;

This is like doing

src = src./repmat(src(3,:), 3, 1)

in matlab. Otherwise another way to do it is to pass element by element and do the division

for(int i =0; i<src.cols; ++i )
{
     // you should first check that the last element is !=0 !!!
     src.at<float>(0, i) /= src.at<float>(2, i);
     src.at<float>(1, i) /= src.at<float>(2, i);
}

and replace <float> with the correct type of your matrix.

Hope it helps.

S.