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, to understand the basic functionalities of Python OpenCV module, we will cover the most basic and important concepts of OpenCV in an intuitive manner:
- 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.Â
Input Image
Let’s start with the simple task of reading an image using OpenCV.Â
For the implementation, we need to install the OpenCV library using the following command:
pip install opencv-python
Reading an ImageÂ
First of all, we will import cv2 module and then read the input image using cv2’s imread() method. Then extract the height and width of the image.
Python3
# Importing the OpenCV library
import cv2
# Reading the image using imread() function
image = cv2.imread('image.jpg')
# Extracting the height and width of an image
h, w = image.shape[:2]
# Displaying the height and width
print("Height = {}, Width = {}".format(h, w))