print comparison matrix elements
I want to know why trying to access (and print) test matrix results in showing garbage:
Mat A = (Mat_<double>(3,3) << 0, -1.4, 0.2, -1, 5.4, -1, 0.1, -1.4, 0);
cout << "A = " << endl << " " << A << endl << endl;
Mat B = (Mat_<double>(3,3) << 0, -1.4, 0.4, -2, 5.4, -11, 0, -1.42, 0);
cout << "B = " << endl << " " << B << endl << endl;
Mat test = Mat(3,3,CV_64F);
test = ( A == B );
for ( int i = 0; i < 3; i++ )
{
for (int j = 0; j < 2; j++ )
{
cout << test.at<int>(i,j) << endl;
}
}
If I use just cout << test
it is ok ,but I want to know why the previous doesn't work.
Thanks!
the comparison returns a CV_8U Mat, so use:
(int)test.at<uchar>(i,j)
@berak: Hmm, so even though I am declaring test matrix to be double , the comparison results in uchar.But the type of
test
matrix remains double?Thanks! ( make that an answer please)no, the test Mat will get re-allocated with a new type.
please avoid pre-allocating result Mat's in general, as you will only fool yourself
@berak sorry I'm answering while you are typing :)
@pklab, sorry, i was typing, while you were answering ;)