How to determine the human readable type of cv :: Mat?

My current problem is that I would like to know the type of cv::Mat

-slices captured cv::VideoCapture

from a video file. The documentation doesn't state what (as is often the case, so even if I missed it in this particular case, it would still be helpful to get an answer to solve the problem in general).

Of course, I could open the corresponding OpenCV header file and step through the macros CV_64FC2

, ... to find the macro that Mat matches type()

. But it made me sick. There should be an easier way.

Isn't there some function that allows me to translate Mat type()

into human readable format? Like this:

cv::Mat myMatWithUnknownType;

// Some code modifying myMatWithUnknownType.
// ...

std::string readableType = myMatWithUnknownType.typeString();
std::cout << readableType; // Prints "CV_64FC3".

      

How do you deal with this?

+3


source to share


1 answer


First, the format of which comes from the cameras, only one: CV_8UC3

. This is hardcoded in OpenCV and any video format is converted to this before being sent to the user. So,

capture >> frame; 

      



Will always return an RGB image consisting of 8 bits per channel.

Now for the other types, you can create a function, keeping in the middle of that OpenCV is not supported by so many types: Mat can be of type char

, uchar

, short

, ushort

, int

, uint

, float

, double

, from 1 to 512 channels (according to the latest documents). Therefore, writing your own is type_to_string()

not difficult.

+1


source







All Articles