Image processing using openCV python library

Here in this article we will do some image processing operations like creating our own image, swapping two images and concatenating two images to form a collage by using opencv python library.

Introduction to Digital image processing

OpenCV python library

Now we will do some image processing operations:-

Firstly We will create our own image

Import cv2

Import bumpy

Now we will write our code as:-

In this we had first created an image by using zeros function of cv2 module.

Then drawn some shapes according to our image Using line,circle, rectangle functions.

Then we displayed the image using
Imshow() ,waitkey() and destroyAllWindows() function.

So here is our own created image

Now we will swap two images

Now we will first crop the faces of both images just like slicing of arrays as array_name[y1:y2,x1:x2]

Now in place of Dhoni’s face we put Raina’s face by just swapping the face variable of both images.

Here imread() function will read the images and put it in dhoni and raina variables respectively

And by

Dhoniface = dhoni[20:240,290:470]

We crop dhoni’s face.similarly,we do for raina’s face as

Rainaface = raina[30:250,160:340]

Now we will swap both the faces and our image will look like

Now we will concatenate two images

Now we will resize them to make the two images equal in size because can’t concatenate two different sized arrays by using slicing operator.

After that we will import numpy module because for concatenating two images we will use hstack() function of numpy module

Our desired results would be--

Now our task is done .

Thankyou for reading