Playing with OpenCV library inside docker

Here, I’m about to show you how to use python library called OpenCV to create/manipulate images inside docker. This article contains three program of OpenCV inside docker ::

1. Create an image.

2. Take two images, crop some part of both images and swap it.

3. Take two images and combine it to form single image.

What is Docker?

Docker is an open platform for developing and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. It was developed by Solomon Hykes in 2013. Docker is written in Go Programming Language.

What is OpenCV library?

OpenCV is the huge open-source library for the computer vision, machine learning, and image processing and now it plays a major role in real-time operation which is very important in today’s systems. By using it, one can process images and videos to identify objects, faces, or even handwriting of a human.

1. Create an image.

Creating an image in OpenCV is pretty easy. Firstly, import all the necessary libraries then, create a grid using “numpy” and customize your image. Ex :

2. Take two images, crop some part of both images and swap it.

To do this, read two images using OpenCV. An image is set of pixels so, to crop images, apply array slicing and display it. Ex :

Img1 :: Before Swap
Img2 :: Before Swap
Img1 :: After Swap
Img2 :: After Swap

3. Take two images and combine it to form single image.

There are two ways to merge two images, i.e. horizontally and vertically. So, to do this, you can use numpy functions. “hstack()” function to combine images horizontally and “vstack()” for vertically (Note :: Dimensions must be same to merge two images). Ex :

Img1 :: Before Merge
Img2 :: Before Merge
Both Images merged horizontally
Both Images merged vertically

Video Link ::

Enjoy Coding !!

Thank You!