You can use cv::Mat::type()
to determine the data type of pixels stored in the cv::Mat
.
The type can be determined as follows:
int type = mat.type();
if(type == CV_8UC1)
unsigned char* ptr = mat.ptr<unsigned char>();
else if(type == CV_8UC3)
cv::Vec3b* ptr = mat.ptr<cv::Vec3b>();
else if(type == CV_16UC3)
unsigned short* ptr = mat.ptr<unsigned short>();
else if(type == CV_16UC3)
cv::Vec3w* ptr = mat.ptr<cv::Vec3w>();
else if(type == CV_32FC1)
float* ptr = mat.ptr<float>();
else if(type == CV_32FC3)
cv::Vec3f* ptr = mat.ptr<cv::Vec3f>();
else
printf("Unknown type\n");