Practical Python and OpenCV: An Introductory, Example Driven Guide to Image Processing and Computer Vision
Kindle Highlights
However, it’s important to note that OpenCV stores RGB channels in reverse order. While we normally think in terms of Red, Green, and Blue, OpenCV actually stores them in the order of Blue, Green, and Red. This is important to note since it could cause some confusion later.
Black: (0, 0, 0) White: (255, 255, 255) Red: (255, 0, 0) Green: (0, 255, 0) Blue: (0, 0, 255) Aqua: (0, 255, 255) Fuchsia: (255, 0, 255) Maroon: (128, 0, 0) Navy: (0, 0, 128) Olive: (128, 128, 0) Purple: (128, 0, 128) Teal: (0, 128, 128) Yellow: (255, 255, 0) Now that we have a good understanding
Normally, we think of images in the RGB color space – the red pixel first, the green pixel second, and the blue pixel third. However, OpenCV stores RGB images as NumPy arrays in reverse channel order. Instead of storing an image in RGB order, it instead stores the image in BGR order; thus we unpack the tuple in reverse order.
It’s important to draw your attention to the second argument of the np.zeros method: the data type, dtype. Since we are representing our image as an RGB image with pixels in the range [0, 255], it’s important that we use an 8-bit unsigned integer, or uint8. There are many other data types that we can use (common ones include 32-bit integers, and 32-bit or 64-bit floats), but we’ll mainly be using uint8 for the majority of the examples in this book.