Welcome fellow readers! Today in this article we are going to explain to you about how the computer sees the image with Open CV Python.

Open CV is the Python programming language library. It was developed to solve the problems of computer vision. Open CV mainly created to proffer the main structure to the computer vision programs and the applications. Open CV supports and focuses on many of the computer languages like Java, C, C++ and many more. But in this article, we will tell you mainly about the Open CV Python.

Open CV is an open-source library and initiative that welcomes all to make changes the contributions in the library. And furthermore, the new modules are added to the Open CV python library. It is considered quite challenging and tough to attain. It manages precisely with the terms of the images in computer vision.

New modules are added to this library. The way Open CV works is that for developers will check your all the pull requests, they give you the valuable feedback and it will be merged into the open CV library. Building a deep learning pipeline for the image classification found as interesting, but isn’t hard as it used to be.  

Process of reading images in Open CV

We are going to show you the process of reading an image with Open CV in Python. Below, we provided an image through which you can get an idea about its functions and channels used in the image.

After seeing the image and its channel functions, don’t you think it looks weirder?

In this section, you will learn how the image color converts into another. In the Open CV, BGR used as a primary function. The function to read an image in OpenCV is imread() reads as a NumPy array ndarray of row (height) x column (width) x color (3)

The OpenCV function imwrite() that saves an image assumes that the order of colors is BGR, so it is saved as a correct image.

Do you know, the main purpose of our team is to provide you the accurate knowledge about such changing colorspaces like BGR into RGB.  

Below, you can perceive easily with each of the color spaces turned the BGR into RGB form. Have a look:    

Why we need Gray scale images?

As we all know, in a deep learning model the main thing is data. Suppose we are building a deep learning model to classify keyboard and mouse image.

In that case, we need the data to train our machine because here the data is a set of images.

As we discussed, there are two types of images i.e. color images and the grayscale images. Initially, we have to identify the purpose of our deep learning model. As we are building the image classification model for (keyboard & mouse).

In this concept, we only need grayscale images because the grayscale image performs quite well in edge detection and shape base feature detection.

And in a gray image, grayscale or a gray value, the image assign with the value from 0 (black) to 255 (white). For each pixel of the grayscale image if its value is lesser than the normal then we do usually assign such values of gray 0 (black) & 255 (white).

The images that come under grayscale vary with the shape base feature and data of the specific image. We use gray value images because they are quite easy to recognize for the computer to detect the images.

And in a gray image, grayscale or a gray value, the image assign with the value from 0 (black) to 255 (white). For each pixel of the grayscale image if its value is lesser than the normal then we do usually assign such values of gray 0 (black) & 255 (white).

Look at the function and you will get easily what we are trying to explain.


Now, after attaining about the functions of the gray image, you might be wondering how many channels hold a gray image? The channels in a gray image preserved on each image’s function (arrays & pixels). But the same image is assigned within the values from 0–255 only. The pixel or the intensity of an image is equal to 2n — 1 where “n” is bit resolution. Moreover how the computer sees the image in values are mentioned in the below image.

Take a look and get the channels that come under this scale and the height, width as well.

The gray-scale

How does the computer see the Image?

How to write an image in opencv?

To write an image in the Open CV library the function would be:  cv2.imwrite('/path/to/destination/image.png',image)

What is a canny filter?

Canny is an edge detector that mainly uses a multi-stage algorithm. It works to detect the images wide edges. We used the canny filter in our image that we have provided in the below section. It's just to show you how to detect the edges in an image but in our further tutorials, we will explain with a wide explanation.

How to read video in an Open CV?

We took local videos link of popular programming language only to make you understand and introduced as the video-CV2 capture video. You can read through the webcam as well but for reading through webcam, the code would be implied as CV2.VideoCapture(0).

To read a video in this library you have to look over the below structure that we have provided. In that image, we have presented the ret (status) and frame (image). We have resized the pop-up size and displayed the frames.  

And further in the second image, the pop- up will be performed as:

Source code

You can get in more detail and download complete code from our own GitHub repositories https://github.com/puneet-kaushal/Basic-openCv-operations-with-python

References

https://docs.opencv.org/trunk/d9/df8/tutorial_root.html

https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_setup/py_intro/py_intro.html

https://www.learnopencv.com/