So now let's move on to the lesson on face and eye detection using horror cascade classifiers.
So this is a pretty cool and fun project.
We're getting into the more nifty areas of open TV.
So in this lesson, what we're going to do?
We're going to go through how you detect faces using a hard cascade classifier that's been previously
trained to detect faces and also one that can detect eyes.
And just in case you're wondering, you actually can access your webcam in club, and I'm going to show
you how to do that and you can use your webcam picture assuming your laptop or desktop has a webcam.
Get a snapshot of yourself and you can run your face detection and eye detection on that image.
So that's pretty cool.
So now let's just look at our libraries and ensure function as well as download.
We're downloading not just images.
This time we're downloading the horror cascade classifier from my Google Drive.
So these these classifiers are basically models, and these are models that have been trained on data
previously, which I will explain briefly a bit how it's trained.
It's been trained to identify faces in one instance and in the other model detects eyes.
So let's go ahead and do that actually already run this code.
So it's going to ask me to rename or to suppress a.
OK, so firstly, what is object detection?
Object detection is the ability of an algorithm, a computer vision algorithm to identify individual
objects in an image like this and correctly classify the object class.
So this is a picture illustrates what I'm trying to say.
Instead of seeing this entire image is a bicycle dog and and tree and a porch, which some classifies
which image classifiers do.
This one is actually going to draw bounding boxes over individual objects, which is a much harder thing
to do for for computer vision and then draw these boxes around it with a class label.
So this is a pretty cool and pretty useful.
And currently this is actually a picture for your detector and not a hard cascade classifier, which
is currently state of the art.
So, but why are we talking about higher cascade classifiers?
Well, they were the first real working optical textures detectors that worked fairly well and very
efficiently.
They were developed by Viola and Jones in 2001, and it was.
It's probably been used in so many camera systems and better systems for face detection just because
it's so fast.
And I'll explain briefly how it works.
So what it does, it uses a concept of sliding windows to basically slide these these images across.
Is that this a picture like this and it does a convolution on top of this image and extracts those features
and those features.
It's we have lots of different edge features, line features for rectangle features and a bunch of others.
Those features will correspond to a fierce like.
Combinations of those features together correspond to a face, and those classifiers are trained to
identify what what the different sequence.
I can probably describe it as that the sequence of values that correspond to a person's face, at least
whatever it's trained on.
And to train this, you basically just need a bunch of positive images.
That's images where the object is present and negative images.
So that's how it learns to differentiate when a face is there and when a face isn't there.
So let's start using Ohara Cascade classifier in open CVI.
So the first thing we do, we use CBT with our cascade classifier, and we pointed that the path where
we where we have a similar model.
So you can see here where we don't look at it, you can see it's created a folder and it's towards these
models where we actually have one for cause as well as as well as a full human body.
So we can just point to the path of that animal model next to a LoDo image, which we've done previously
before we converted to Grayscale.
Now this step isn't necessary.
However, Schakowsky classify classification does work a lot faster when the grayscale image.
And there's one thing I should note it's kind of annoying, but her her cascade classifier isn't an
image classifier, which you learn when we go onto convolutional neural nets.
What a classifiers classifier tends to classify the entire image, feed an input image in and it tells
you what's in that image or what class an image belong to.
I should say so.
Object detector, though, is what her cascade really is.
It should be called the higher cascade object detector.
But nevertheless, it's called RKC classifiers who will go with it.
So we've created our first classifier object here and now that has a function called Detect Multi Skill.
This is where we feed in the input image.
The first parameter we can set scale factor, as well as a minimum neighbors.
So the skill factor and minimum Labor's configuration parameters that adjust the sensitivity.
So if you load this, you can get more boxes on the face and skill factor as well.
If you live with this or increased as you can.
Depends on the type of image and type of face or size of the faces in the image.
You will get probably more sensitive, more sensitive detection.
So that's just this line, and this line basically grabs two faces and extracts into an array.
So if the faces is basically none, this is what this means.
Here is none can use that as well.
And then it will print new faces found.
So at least we know no faces have been found, and we want wonder if all of the is working or not.
If it does detect faces, do we just iterate through it and this here x y it w and h width and height?
That's the bounding box dimensions for.
Well, not really demanding boxes is the X and Y starting points.
And this is the width and height.
So, you know, let's say this is X and Y is this point here where I'm pointing.
And the.
It is this direction and the height is destruction down, so we use that to destroy the key to using
the CBD rectangle function to draw the bounding box over it, and we just try to get a pink light.
That's what this rgv bgr, I should say.
Color scheme is corresponds to this of thickness and we just use to improve function.
Look, we've done many times before to show the final image.
So that's it working for Mr. Donald Trump.
So now let's move on to face and eye detection.
So what's different in this good?
In this good, we're creating two objects here first classifier and AI classifier next what we do.
We just run it and get the faces as well.
If new faces are found, that should mean no eyes are found.
However, if a face has been found, we do draw a box around it like we did previously.
However, these new lines have good.
Let's see what they do.
What is this doing here?
This is actually cropping freezing to grayscale image we've created here with Lauderhill.
It's cropping the face out and then it's actually doing it similarly for the color image as well.
So we can test it either on the color or gray.
But what we do, we'll use degree and I'll show you why we crop the color out afterward.
So, no, we just feed the arrow.
I agree.
That's the region of the face only into the eye classifier here because we notice the face.
So what we do, we just feed our face input that extracted face into a classifier detector.
And then for the eyes, if we get any ice, we just loop through the eyes and draw rectangles around
them.
So that's what this would give us, and you can see how badly it thinks Donald Trump has two left,
which is actually actually that's his right eye to right eyes.
And that's because the parameters were probably set too sensitive.
That said, we use the default parameters here, so we can perhaps set something different.
Let's try one point five and let's try seven.
So let's see what that gives us.
OK.
And it actually eliminated ICE, which is probably not what we wanted.
So let's be reduced to minimum neighbors.
Firstly, that didn't help.
Let's go back to one point three.
That didn't help again.
So actually, I think I'm not sure if these are the V4 values, but we can just leave it and go back
to the default here.
So let's see, let's try something else.
That's right.
One point one entry.
There we go.
So we know that these are lower values means it's more sensitive.
So let's see if we can get it to us.
Get two ways.
And there we go.
So these are the settings to use.
Hopefully, you can get a feel of what these settings do.
You can read the open CV documentation to get the explicit definition of what they do.
I already told you that this is the skill factor and this isn't the minimum neighbors.
They may have a deeper explanation on to how to interpret those things for your images here.
In the meantime, though, this is the result of playing with those parameters.
So, no, let's take a look at Google collapse.
This is a code here for using Google.
Call up to take snapshots from a camera.
Now, I'm not going to go through this good because actually, I probably haven't actually inspected
the school properly before.
But what it does it basically it's a boilerplate function that Google provided to use collab.
That's do you know what code that is?
That's what we're using right now to use called up to get snapshots from a webcam.
So let's run this code and say, Well, see this function, take a photo.
And now let's use to take for the function right here.
So I'm going to run this block of code, and it's going to ask you for permission to access your webcam.
So what do you do?
You hit a low, which gives the browser the permission to use a webcam, and it should pop up here.
Yes.
Here it is.
So let's capture a picture.
You stay still.
OK, not the best picture, but we got a picture of myself.
So, no, let's reduce the code.
We both are using my photo, which is has been saved as football right here.
You can see.
Let's run, OK?
OK, Hardcastle classifier on that image and you can see things that my pimple is I, which is unfortunate.
But we I showed you how to adjust the sensitivity scale of this here.
So that concludes this lesson.
I've also put in some boarding school here.
So if you wanted to use your local webcam to do it in a live video, you can run this code here.
This could actually opens a webcam here.
And while true, which means that a while the webcam is open and receiving images, it loads the images
here and runs his face detector function that we create here.
This feature that detect function is basically the same code right here.
However, we've put this no into a function, and that function basically just plots the image on your
live webcam.
So if you have OpenCV installed locally on your machine, probably using Conda or one of the other bindings
that that has opened so many, many different ways to install it on many different systems, which is
why I avoided that messy install setup in this course, because CoLab is actually just super nice and
easy to use.
I use CoLab, many of my computer vision and data science colleagues use CoLab or Jupyter notebooks,
which connected to virtual machine, so it's roughly the same thing.
So instead of using local machines.
So that's it for this lesson.
Hope you enjoyed it, and we're going to move on now to vehicle and pedestrian detection, also using
our cascade classifiers.
So welcome.
I'll see you in the next lesson.
Thank you.