Channel order in OpenCV


February 2019


5k time


I have been reading in a few forums that OpenCV has the BGR channel order by default.

It is also possible that a cv::Mat may have RGB channel order.

A gray conversion would specify CV_BGR2GRAY or CV_RGB2GRAY as a parameter.

1) Are there any other options, than RGB and BGR ?

2) Is there any way to find out - through code - what the order of channels is ?

Thank you.

1 answers


Opencv always (AFAIK) uses BGR channel order, there are a few functions in the GPU module that use BGRA since opengl contexts work better with 32bit pixels.

BGR2Gray and RGB2Gray both call the same function.

The easiest way to check is to create an image in paint etc which has known R,G,B values and then examine the cv::Mat memory in the debugger