OpenCV(Open Source Computer Vision Library) is an open source computer vision and machine learning software library generally used to interpret data in the form of image or video.

It works in C,C++ and python. In this tutorial we will use OpenCV with python.

As it is an open source library, hence you can find it’s complete official documentation at the given

How Images are represented in Computers:

Typically, Digital images are stored in the form of multi-dimensional matrix where the information of every pixel of that image is kept.

Based on the information that we are using to describe any pixel, we can categorize the digital images into two types:

  1. Grey-scale image: Only one channel of color is used.
  2. Colored image: 3-channels are used (RGB color combination).

Now let’s starts with the practical:

How to read an image with OpenCV:

cv2.imread(path, flag) method is used to read the image from the given path. It has two arguments:

  1. path: path of the image
  2. flag: it is used to specify the way in which the image should be read. It has three variants.

-1: cv2.IMREAD.UNCHANGED, load an image with alpha channel.

0: cv2.IMREAD_COLOR, load a colored image.

1: cv2.IMREAD_COLOR, load an image in grayscale mode.

Default value of flag is 0.

How to display an image with OpenCV:

cv2.imshow(window_name, image) method is used to display the image on a window. It has two arguments:

  1. window_name: it specifies the name of the window where the image is going to be displayed.
  2. image: it is the image which has to be displayed.

Implemented code in python:

#import openCV library
import cv2

#imread() is a function in cv2 to read images
img = cv2.imread('test.jpg',0);

#imshow() is a function in cv2 to display images

#waitKey() function to create a delay for 5 sec

That’s all I have and thanks a lot for reading. Please let us know if any corrections/suggestions. Please do share and comments if you like the post. Thanks in advance…

Thanks Rishika Gupta for helping us to grow day by day. She is an expert in Machine Learning and Image processing tools.


Brianadmip · March 24, 2020 at 10:24 pm

Sustain the incredible job !! Lovin’ it!

Brianadmip · April 4, 2020 at 11:41 am

You’ve got good info here.

Leave a Reply

Your email address will not be published. Required fields are marked *

Insert math as
Additional settings
Formula color
Text color
Type math using LaTeX
Nothing to preview