Image Processing using OpenCV and Numpy in Python

aman behl
3 min readJun 9, 2021

--

OpenCV provides many drawing functions to draw geometric shapes and write text on images. Let’s see some of the drawing functions and draw geometric shapes on images using OpenCV.

Images is a 3D array if it is colourful. Since computers are not intelligent they do not understand colours. They store this data in the form of data in a array format.

Images is a combination of multiple pixels in other words Pixels is the smallest unit of a Image. Values put in this array are in the form of RGB(Red,Green,Blue) ranging from 0 to 255.

OpenCV library, cv2 module stores the value in BGR format (Blue,Green,Red)

In a pixel, they store no(255,0,0) for red colour.This how image is stored internally

Same way Video is like clicking mutiple photos continously in a flash mode in a particular time frame. So basically we just have to click the photo and display it continously in infinte loop.

Task 1 : Create image by yourself Using Python Code

Python code to draw triangle.
output

I’ve Also created an image of hut using numpy array & cv2.

Task 2 : Take 2 image crop some part of both image and swap it

Make sure you have 2 images you want to work on. Here I have taken two images of Shahrukh khan just for an example to show you.

Output
Crop Faces

Below images shown are the cropped images

Swapping faces

The final output:

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

These are the two images we are taking for this task.

Final Step : Creating COLLAGE

The Final Output :

Thankyou for Reading and Do share !!!

--

--