Hey guys welcome to Intellipaat. So computer vision is a field of artificial
intelligence that trains computers to interpret and understand visual world
from recognizing faces to processing live action of a football game, computer
vision surpasses human visual abilities in many areas. So in this video we have
come up with this project on face recognition using computer vision. To
help you get started in this very interesting field. Now before we start do
subscribe to Intellipaat's YouTube channel so that you never miss out on
our upcoming videos. Also guys if you are looking for an end-to-end certification
course on artificial intelligence then Intellipaat provides just the right
course to help you become the master in this field. Now before any further delay
let's get started. So, suppose you are a computer vision engineer and the client
has approached you with the problem statement in which you have to detect
the faces from a set of images that they will be providing and you have taken up
this project and these are the following steps that you have to follow a while
building up this project. So, these are the images that they have provided to
you these are some of the images that have taken from their data set and here
we'll be working on Python with OpenCV in this project we will be using the
HAR casket classifier for detecting the faces from multiple images so firstly
you have to perform the downloading part for the HAR cascade system. So, here I have
written download her casket frontal face default dot XML and this raw github code
these are the raw datas for the HAR casket you have to just simply save as
and you can save it as desktop and you have, now you have the HAR casket
classifier. So, now next we will be just importing the CV to and globe. So, now we
will be practicing it in the Jupiter notebook so so firstly you have to
import the CV tool ability and globe. So, I want to tell you that globe is
the function which returns us the array of those file name which we will write
in the next line like we just have to perform face detection on those images
which have dot jpg extension. So, for that I will be writing G image equals to glob
dot glob. So, here I am calling the object glob and
with the function in glob and here inside the function I will be writing
the star dot jpg. So, it will take up all the images that have extension dot jpg
so after that, we will detect after the getting the glob images now we'll create
cascade classifier so that we can so as it helps us in getting the face
detection it contains all the features of the images like nose, ears, face, object
these are some of the features of the image. So, here we'll be writing detect
equals to C v2 dot cascade classifier then inside the braces we will
be writing which classifier, we have downloaded the HAR cascade frontal
face default classifier so we will be mentioning the same name HAR cascade. okay,
cascade frontal face default dot XML. So, now after creating the HAR cascade
frontal face default XML file, then what we will do, we will now reverse the globe
images. so that, we can detect the faces. So, for traversing, we will be creating a
for loop for traverse or you can also write t image, t image for traversing
the image t image in G image the globe image okay. So, now it will take one image
at a time. Now, in the for loop, we will read the image a particular image. So, for
reading the image we will write like I have taken image equals to C v2 dot I am
lead and what is this reading the T image. Okay so,
after reading the particular image from the G image now we will convert the
images these are the colored images. The image that it has the red it is the
colored images. So for so in this phase detection we will first have to convert
the colored image into the greyscale image. So, it is easier for the classifier
to handle the image and detect the faces from it.
So, for converting the image to confirm converting the colored image to
greyscale image we will write grey image I have written this grey image
equals to C v2 dot cvt Color and in the braces, it will have this
image that you have to convert it into grayscale, this image comma D we will
write C v2 dot color and underscore BGR2GREY. Okay so after
converting it to grayscale now we will detect the faces from the images. So, for
detecting the faces I will be writing the face equals to detect dot detect.
I am calling this object here and with the function detect multi scale and it
has three parameters. So, the first one is in which image you want to detect the
face. So, we will be writing this grey image,
this gray image here and the next parameter is the scale factor. So, we will be more.
So, we have to see the value of the scale factor. As this scale factor is that
value which decreases the volume of the whole greyscale image by five percent
until the face is detected so it basically what does it is it
decreases the value of the image so that it can find the face from the image. So, I
am writing one point two five the smaller the value is the greater will be
the accuracy. So, I am writing one point two five and the next parameter is the
minimum neighbor so we don't have to bother this value. Now, after that after
detecting the face now we will be describing the rectangle shape for the
face. So, for that create a for loop for now in this braces we will be writing
all the dimensions for the rectangle like X comma Y comma W comma H, length
breadth, height and width. Okay so, after the parameter, now in what, in face we
are actually detecting the, we have detected the face but now we have to
define that face with a rectangle shape. So, for that, we will be using the dot
rectangle function. So here I am writing C v2 dot rectangle okay rectangle now in
this we have four parameters the first one is the image that you have to detect
the face image, this image that we have read it here okay.
The second parameter is the RGB value RGB value means the colored value. So, here I
am writing the X comma Y and then the other parameters for the rectangle. We
are basically defining the parameters of the rectangle how it will look on the
image so we will be writing X
plus W comma
Y plus, sorry Y plus H, okay so after defining the parameters of the rectangle now
we'll be look at the color of the rectangle so here I am just taking the
green color So, this is the code for green color okay
0 comma 2 5 5 comma 0 okay so now after that we will, the last parameter is the
thickness of that tangle so I am giving 2.
So, now after defining the rectangle now we will just show the image. So, for
displaying the image CV to dot M show in the parentheses we will be writing
detect any message you can write like detect images okay and coma which image
this image so image. Okay so, after displaying the images now we will be
defining the wait key function what does wait key does is we will
define some intervals between the images it's just a time period diet what will
be the intervals between the images so CV to dot wait key and how many I am taking
200 milliseconds sorry 2,000 milliseconds and we will be writing C v2
dot destroy all windows. So, destroy all windows will close as all the windows
based on the wait for key parameter. So, here I am writing the 2,000 milliseconds
so it will destroy it for that. So, here okay so I am running this code so here
you can see that all the faces are being detected.
Okay so, I hope you have liked this session so guys I hope you found this
video informative if you have any queries, do let us know in the comment
section below, thank you for watching.