Accessing and manipulating pixels in OpenCV with BGR images

Now, we are going to see how we can work with BGR images in OpenCV. OpenCV loads the color images so that the blue channel is the first, the green channel is the second, and the red channel is the third. Please see the Accessing and manipulating pixels in OpenCV with grayscale images section to fully understand this concept.

First, read the image to work with using the cv2.imread() function. The image should be in the working directory, or a full path to the image should be provided. In this case, we are going to read the logo.png image and store it in the img variable:

# The function cv2.imread() is used to read an image from the the working directory# Alternatively, you should ...

Get Mastering OpenCV 4 with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.