OpenCV is one of the most popular computer vision libraries. If you want to start your journey in the field of computer vision, then a thorough understanding of the concepts of OpenCV is of paramount importance.
In this article, I will try to introduce the most basic and important concepts of OpenCV in an intuitive manner.
This article will cover the following topics:
- Reading an image
- Extracting the RGB values of a pixel
- Extracting the Region of Interest (ROI)
- Resizing the Image
- Rotating the Image
- Drawing a Rectangle
- Displaying text
This is the original image that we will manipulate throughout the course of this article.

Let’s start with the simple task of reading an image using OpenCV.
Reading an image
Importing the OpenCV library
import cv2
Reading the image using imread() function
image = cv2.imread('image.png')
Extracting the height and width of an image
h, w = image.shape[:2]
Displaying the height and width
print("Height = {}, Width = {}".format(h, w))
Now we will focus on extracting the RGB values of an individual pixel.
Note – OpenCV arranges the channels in BGR order. So the 0th value will correspond to Blue pixel and not Red.
Extracting the RGB values of a pixel
Extracting RGB values.
Here we have randomly chosen a pixel
by passing in 100, 100 for height and width.
(B, G, R) = image[100, 100]
Displaying the pixel values
print("R = {}, G = {}, B = {}".format(R, G, B))
We can also pass the channel to extract
the value for a specific channel
B = image[100, 100, 0]
print("B = {}".format(B))
