Why OpenCV
using BGR
colour space instead of RGB
. We all know that RGB
is the convenient colour model for most of the computer graphics and also the human visual system works in a way that is similar to a RGB
colour space. Is there any reason behind OpenCV
BGR
colour space?.
-
3possible duplicate of [BGR Color Space](http://stackoverflow.com/questions/367449/bgr-color-space) – Kate Gregory Jan 28 '13 at 19:56
-
1[here](http://www.learnopencv.com/why-does-opencv-use-bgr-color-format/) you can find an information about the question – sturkmen Nov 08 '15 at 01:11
-
6@KateGregory, it not a dup. That question is a *what*. This question is a *why*. – Ricardo Magalhães Cruz Jul 18 '16 at 11:37
-
1The human visual system does not work like RGB at all. – Robin De Schepper May 11 '21 at 09:14
3 Answers
"The reason why the early developers at OpenCV chose BGR color format is probably that back then BGR color format was popular among camera manufacturers and software providers. E.g. in Windows, when specifying color value using COLORREF they use the BGR format 0x00bbggrr.
BGR was a choice made for historical reasons and now we have to live with it. In other words, BGR is the horse’s ass in OpenCV."

- 912
- 9
- 7
-
4http://meta.stackoverflow.com/questions/304126/is-it-correct-to-answer-copying-from-comments-by-other-users – sturkmen Nov 22 '15 at 22:22
-
17That doesn't explain why BGR was (then) popular in the first place. – nerdfever.com Aug 18 '18 at 18:51
-
2Windows has only ever worked on little-endian machines. 0x00bbggrr is stored as R, G, B in memory. It seems to me that OpenCV’s choice was based on a misunderstanding. – Cris Luengo Apr 26 '21 at 14:29
-
8It is quoted from https://learnopencv.com/why-does-opencv-use-bgr-color-format. State your sources – Robin De Schepper May 11 '21 at 09:13
-
i think BGR was popular because the characters follow alphabet order. – Lei Yang Sep 01 '21 at 14:38
-
1
-
I wish they just rolled that back. "now we have to live with it" is how most of us feel when using it. – Miquel Canal May 24 '22 at 16:35
-
1
OpenCV reads in images in BGR format (instead of RGB) because when OpenCV was first being developed, BGR color format was popular among camera manufacturers and image software providers. The red channel was considered one of the least important color channels, so was listed last, and many bitmaps use BGR format for image storage. However, now the standard has changed and most image software and cameras use RGB format, which is why, in programs, it's good practice to initially convert BGR images to RGB before analyzing or manipulating any images.

- 184
- 1
- 5
-
1Do you have a reference for this? As far as I know, it has always been RGB. – Cris Luengo Apr 26 '21 at 14:30
Why? For historical reasons. In 1987, Microsoft Windows ran on the IBM PS/2, and an early IBM video display controller, VGA, made use of the INMOS 171/176 RAMDAC chip, which was easier to use when images were stored in BGR format.
See details at Why BGR color order - Retrocomputing Stack Exchange

- 12,479
- 7
- 66
- 91
-
This still doesn’t explain why OpenCV stores blue in the first byte. The linked Q&A specifically talks about storing x0bgr such that red is the first byte read. On a little endian machine, x0bgr has red in the first byte, OpenCV stores blue in the first byte. – Cris Luengo Apr 26 '21 at 14:36