Starting with OpenCV in Jupyter

I was doing a project related to machine learning and came across the OpenCV library for image and video processing and researched about it.
We are using OpenCV with jupyter. So, to start with OpenCV we have to first install jupyter.


Why are we using jupyter ?

The Jupyter Notebook is an open-source web application that we can use to create and share documents that contain live code, equations, visualizations, and text.

For download and installation of jupyter refer to this video,

Now, after completing the installation of jupyter, to install OpenCV go to command prompt and then type the following command:

pip install opencv-python


OpenCV Functions

  1. imread : It is used to read an image
  2. imshow : It is used to display an image in a window.

3. cvtColor : It is used to convert an image from one color space to another.

4. resize : Image resizing refers to the scaling of images.

5. transpose : It rotate the image 90 degrees Counter clockwise.

After the library is downloaded open jupyter notebook and create a new file for checking if it is successfully installed and write the following command:

import cv2

To run the command in jupyter we need to use shift+enter

The output should be like this:

Now, we will start with the capturing of video from camera


In the above figure

  1. we have imported the library.
  2. Then define a variable as video to get the video capture object for the camera.
  3. Setting up an infinite while loop and use the read() method to read the frames using the above-created object.
  4. Then use cv2.imshow() method to show the frames in the video.
  5. If press ‘q’ then it will close the window after the loop breaks it will release the object and destroy all the windows if any is open.

After running the code the web camera will get started and it captures the video.

Great you have successfully completed.

Thank you for keeping up with me till the last word.