Search code examples
python-2.7opencvyuv

Python 2.7 opencv Yuv/ YPbPr


So I've heard that the YUV and YPbPr colour system is essentially the same.

When I convert BGR to YUV, presumably to the Color_BGR2YUV opencv command, what are the ranges for the values that return for Y, U and V? Because on Colorizer.org, the values seem to be decimals, but I haven't seen opencv spit out any decimal places before.

So basically what I'm asking (in a very general, but hopefully easily answerable way)

What does YUV look like in an array? (ranges and such comparable to the Colorizers.org)


Solution

  • You should take care of how YUV is arranged in memory. There are various formats involved. The most common being YUV NV12 and NV21. In general, data is stored as unsigned bytes. While the range of Y is from 0~255, it is -128~127 for U and V. As both U and V approach 0, you have less saturation and approach grayscale. In the case of both NV12 and NV21, it is cols * rows of Y followed by 0.5 * cols * rows of U and V. Both NV12 and NV21 is a semi-planar format, so U and V are interleaved. The former starts with U and the latter with V. In the case of a planar format, there is no interleaving involved.