Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

so, the correct way to access uchar, single channel image would have been:

mat.at<uchar>(y,x); // NOT int !

but the faster way to do it would be:

uchar *ptr = mat.ptr<uchar>(0); // pointer to row 0
// you can index it like ptr[0] ... ptr[mat.cols-1]

and the reason you see garbage, when printing it out is, that cout treats (u)chars as ascii symbols, so you need to cast it:

 cout << (int)value << endl;

but better, print out the whole Mat:

cout << mat << endl;

(no problem with types any more !)