Reputation: 669
Does there exist some methods that I can use to determine the data type(such as uchar,cv::Vec3b...)of the element stored in Mat structure in OpenCV?
Upvotes: 0
Views: 1052
Reputation: 16796
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");
Upvotes: 5