Fun Task using Cv2 module of Python.

Rahul Keshari
3 min readJun 9, 2021

--

What we are going to see in this blog?

  1. Creating one drawing using cv2 module.
  2. Will swap few part of two images with each other.
  3. Will learn to combine images.

How can we draw image using cv2?

Well there are many function in cv2 which has the capability to draw line circle, rectangle, lines, etc. I have used few of those function to draw a house and a person. Below is image of my code snippet and the output.

Code snippet and output

How to swap few part of two images with each other?

There is one good thing about image is that it is an array of number and whatever operation we can do with the numpy array in python we can do with the images also. Here I have taken two pictures and have swapped the eyes of the two emojis. Below are the two images which I have used for swapping.

I have used the concept of numpy array and cropped the eyes of both the images and swapped it. below is image of code snippet and the output image:

code snippet and the output Images

Now how can we make a collage of images?

As I said Images are just a array of number so we can perform all the operation on images which e can perform on numpy. Here I will add the two image arrays and the output will be a combination of both the images. Here are the code snippet and the output of the code.

These are two images which will be combined.
Code Snippet and the output image.

Conclusion:

Cv2 is really amazing and we can perform many amazing thing by using it. The task I have perform is just a small things we can perform many other tasks too.

--

--

Rahul Keshari
Rahul Keshari

No responses yet