Image Processing in Python using opncv

Hola everyone,

We know that image is combination of multiple rows & columns i.e. multi-dimentional array. Black & white images are 2D arrays and coloured imges are the 3D.

🤔 What is image processing ?

Image processing is a method to perform some operations on an image, in order to get an enhanced image or to extract some useful information from it.

🤔Why we need image processing ?

This gives computer a vision to detect and recognize the things and take actions accordingly. Image processing has lot of applications like Face detection & recognition, thumb impression, augmented reality, OCR, Barcode scan and many more.

-Numpy and Scipy libraries − For image manipuation and processing.

-OpenCV −It is a huge open-source library for computer vision, machine learning, and image processing. Application are facial & gesture recognition, Human-computer interaction, Mobile robotics, Object identification and providing lots of tool .

First of all Install OpenCV run the following pip command on CMD

pip install opencv-python

now import the cv2 module.

import cv2

Let’s understand basic commands :

2. cv2.imshow('name', variable_name):This command is used to show the image .

3. cv2.waitKey():The waitkey() functions take time as an argument in milliseconds as a delay for the window to close. Here we an set the time to show the window forever until we close it manually.

4. cv2.destroyAllWindows():cv2.destroyAllWindows() function, pressing any key on keyboard is closing the image window.

5.img.shape :It displays the shape of image in (rows,columns,dimention)

6. cut_image = img[x1: x2, y1: y2]: you can crop the images using numpy slicing concept.

Let’s understand Image processing by performing few tasks.

🔅 Task 1
📌 Create image by yourself Using Python Code

Here I’m trying to create image of hut,

Input code

Output :

Image creation of hut…..

🔅 Task 2
📌 Take 2 image crop some part of both image and swap it.



Swapping of images……

🔅Task 3
📌 Take 2 image and combine it to form single image. For example collage


Thank you for your valuable time…