Ask Your Question

Revision history [back]

Every Mat object has an pointer to its data, for example with Mat img; the data pointer is img.data. Based on your image type (when declaring or reading from image file), that pointer can be cast to unsigned char * (for CV_8U or CV_8UC1, grayscale image and other CV_8Uxx), float * (for CV_32F and other CV_32FCxx), double * (for CV_64F or other CV_64Fxx). Based on your image datatype, you will know how many bytes it needs to store a single cell.

Every Mat object has an pointer to its data, for example with Mat img; the data pointer is img.data. Based on your image type (when declaring or reading from image file), that pointer can be cast casted to unsigned char * (for CV_8U or CV_8UC1, grayscale image and other CV_8Uxx), float * (for CV_32F and other CV_32FCxx), double * (for CV_64F or other CV_64Fxx). Based on your image datatype, you will know how many bytes it needs to store a single cell.