Cv2.Cvtcolor

Cv2.Cvtcolor Designer Dresses

Conversion is performed using the cv2.cvtColor function, which takes the original image and the value of the conversion direction. The directions are cv2.COLOR_BGR2RGB, cv2.COLOR_BGR2YUV, and so on. The first abbreviation shows in which color profile the original image is located, and the second, after the number 2, in which we want to translate it.
2021-11-21, by ,

#CV2 || #Computer Vision || #Python ||

Table of contents:



Opencv (Open Source Computer Vision Library) is a Python module used to solve problems with computer vision. This is a huge module with exceptional capabilities. Using computer vision, we can solve a wide variety of problems. An example of such tasks would be face and motion recognition.

Today we will learn how to write code for detecting faces in images, videos, and for motion recognition.

Face recognition in images

The OpenCV GitHub file has a subdirectory (opencv-master samples data) named data, which provides sample images and videos to work with. We will use photos and videos from this directory. Specifically, let's take the lena.jpg file. Copy and paste it into your working directory in PyCharm (or any other editor). Now let's start recognizing faces in this image.

Our next goal is to turn the photo into grayscale. We will do this using the cv2.cvtColor () method.

This method takes two arguments. The first is the name of the file to be converted and the second is the format to which the file is to be converted. In this case, we will use the cv2.COLOR_BGR2GRAY format.

cv2.cvtcolor

Then we will use the detectMultiScale () function to detect objects (in our case, faces). Here we will write face_cascade.detectMultiScale (), which will detect faces (this is specified by the face_cascade parameter).

The detectMultiScale () function takes several arguments: image, scaling factor, minimum number of neighbors, flags, minimum and maximum size. We'll only list the first 3 arguments.

To place a rectangular frame around the face, we need to use the cv2.rectangle () method. It takes multiple arguments. The first is our image, the second is the start point of the rectangle, the third is the end point of the rectangle, the fourth is the color of the rectangle, and the fifth is its thickness. In this case, w is the width, h is the height, and x and y are the coordinates of the starting point.

Finally, we display the image on the screen using the cv2.imshow () method. We also use cv2.waitKey (0) to set an infinite timeout and cv2.destroyAllWindows () to close the window.