Image Processing Operations using OpenCV Library in Python

First let’s understand, what is an image according to the computer?

Image according to the computer is just a numpy array which are multi-dimensional. Images are NumPy arrays which can be 2D if it is a black and white image or 3D if it is a colored image.

The smallest unit of this 3D array in a colored image is called pixel and each pixel is filled with some color which is actually an combination of three color channels i.e. red, green and blue. In OpenCV, images are stored in BGR(Blue, Green and Red) format.

So, for computers, Image is nothing but just a data, a data arranged in some kind of structure or arrangement called array which combined together appears to us an image. All operations performed on an array can also be performed on the image.

What is Computer Vision?

Computer vision is a field of artificial intelligence that trains computers to interpret and understand the visual world. Using digital images from cameras and videos and deep learning models, machines can accurately identify and classify objects — and then react to what they “see.”

Now, this much knowledge is sufficient to go ahead and try creating our own image.

So, first let’s create the background for our image using:

This helps us to create a numpy array of size 500 x 500 in which each element is filled with black color. The value of black color in BGR format is (0,0,0).

Now, let’s try to create a cup using opencv. Using opencv2 library we can create different images using line, circle, rectangle,eclipse function.

Task 4.2

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

Task 4.3

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