Starting with OpenCV in Jupyter

Bhavikagupta
3 min readMar 15, 2021

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.

Jupyter

The Jupyter Notebook is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations, and narrative text. Uses include data cleaning and transformation, numerical simulation, statistical modeling, data visualization, machine learning, and much more.

Why are we using jupyter ?

We are using jupyter because for machine learning algorithms we need faster processing. Jupyter helps to process the algorithms faster.

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

OpenCV is a cross-platform library using which we can develop real-time computer vision applications. It mainly focuses on image processing, video capture, and analysis including features like face detection and object detection.

OpenCV Functions

There are some of the functions mentioned:

  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

capture.ipynb

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.

--

--