Reputation: 660
I have this code:
Mat Marker = Mat::zeros(MarkerSize, MarkerSize, CV_8UC1);
cout << "Marker:" << endl;
for (int row=0; row<MarkerSize; row++)
{
for (int col=0; col<MarkerSize; col++)
cout << Marker.at<int>(row, col)<<", ";
cout << endl;
}
where MarkerSize=6
and CV_8UC1
is preferably not changeable (for solution).
But I get this output:
Marker:
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 65536, -1664876544,
0, 0, 0, 1, 1141152964, 289879,
0, 65536, -1664876544, 1817658372, 1531445252, 2147447774,
How come and how can I fix it?
Upvotes: 1
Views: 1280
Reputation: 227418
Your Mat
object is instantiated with CV_8UC1
, that is, containing MarkerSize*MarkerSize
8 bit unsigned elements. But you iterate over it as if it container int
s, going out of bounds in the iteration. For example, by accessing the elements with
Marker.at<uint8_t>(row, col)
Note that to print this you may have to cast to a different integer type, because uint8_t
could be interpreted by std::cout
as a char
. For example
cout << static_cast<int>(Marker.at<uint8_t>(row, col)) <<", ";
Upvotes: 4