How to get pixel format of a Mat()?

asked 2015-10-13 21:26:20 -0600

realkill gravatar image

I need to detect the pixel format of a cv::Mat() object, BGR or RGB or BGRA or RGBA or YUV or some else.

I know OpenCV use BGR/BGRA by default, but you can use cvtColor to change it, what I need is going to detect the pixel format for any cv::Mat() object.

Thanks a lot.

edit retag flag offensive close merge delete

Comments

you can't. there's a lot of cases even, where a Mat does not hold 'pixels' but something completely different, like complex values, transformations, SIFT features, etc..

berak gravatar imageberak ( 2015-10-13 23:04:44 -0600 )edit

You can just see if the mat has 4 (RGBA, BGRA) or 3 (RGB, BGR, YUV) channels

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-10-14 02:19:46 -0600 )edit