Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
669 views
in Technique[技术] by (71.8m points)

opencv - What exactly is BGR color space?

An RGB color is composed of three components: Red (0-255), Green (0-255) and Blue (0-255).

What exactly is BGR color space? How is it different from RGB color space?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Its about endianness.

RGB is a byte-order. But a deliberate implementation choice of most vanilla Graphics libraries is that they treat colours as unsigned 32-bit integers internally, with the three (or four, as alpha is typically included) components packed into the integer.

On a little-endian machine (such as x86) the integer 0x01020304 will actually be stored in memory as 0x04030201. And thus 0x00BBGGRR will be stored as 0xRRGGBB00!

So the term BGR (and BGRA etc) is a leaky abstraction where the graphics library is explaining how the integer is logically ordered, so as to make your code that is directly accessing the colour components individually more readable.

Remember that bitmaps are usually accessed by more parts of the hardware than your processor, and the endian that is specified by, say, conventional display adapters, is not necessarily the same as the endian of your CPU. At the level of manipulating the channels in the pixel its no problem for a CPU to extract the fields whatever their order; its purely a programmer understanding the labelling thing.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...