Hi and welcome to our lesson on fees and detection.
So we're finally going to use some Caskie classifiers to detect Buddh faces and eyes and pictures and
an even video streams.
So we're going to use some preachy and classifiers that have been provided by open C-v and you can access
them to this link here.
Although I have given given them to you on the course files there are supposed to be in your excuse
folder.
So anyway we can take a look at open see if you like to see to classify as the provider.
It's actually quite quite a few of them.
And today we're going to use a hair cascade and full frontal vs default I believe which is here.
Yes.
So you may have just notice actually go by quickly.
That is classify as XML files and SML stands for basically Extensible Markup Language.
It's basically a language we use to store vast amounts of data could even store data be and XML file.
However it's designed to be human readable.
So it's not too much you need to know about this format when using Harke ASCII classifiers just need
to know what it's doing.
As an XML file and I'll give you a simple overview of the flow of how we actually use these Kusiak classify
as an open CV.
So simply like using Sifton some of these other algorithms before we load or initialize our classifier
and then we pass the image or video frame to detect or classify a method and that method typically returns
and our way or region of interests which is location of the face here or eyes perhaps and then simply
Once we have that region we can actually draw a rectangle over it feels like we have done in this sample
image here or you can actually use the fiest you can crop it and maybe apply some sort of face mask
or filter.
So that's pretty cool.
So let's actually look at implementing this and detection using open Zeevi.
All right let's go ahead and open our code section 6.2 face and eye detection.
Bring it up here.
OK.
And we have a few blocks of code.
So let's look at the first block here.
This one is just doing this detection.
So let's quickly run this.
And there we go it successfully successfully run.
We have a pink square or rectangle around Donald Trump's face.
That's pretty cool.
So let's see exactly what's happening here.
So let's look at the first line of this code here.
So we're using the to cascade classifier dysfunction which we point to a cascade ossified.
We would be using here for detection.
That's a cascade frontal thius default.
And that would have been one to classify as a give you in the IG files for discourse.
It's in the Cascades folder under a tree.
Other classify as C as well.
So what this does this creates our fears classify object here.
And then what we do know is we LoDo image.
So this is the image of Donald Trump that we just that you just saw actually.
And then we find a grayscale of an image which is pretty much standard right.
Now you may have noticed a lot of open C-v functions required images to be in grayscale and then we
use this method that's in the classify object detect multi-skilled and you see the tree parameters here
in that image and I'll get to these two parameters right after.
And what does this actually gives us the region of interests that for each of the tasks.
So this faces files actually Inori.
It's not the not the location of one fiest but the location of many faces.
So similarly you saw previously how we had a list of this to give it as that as basically locations
for different offices would have located or detected it in the file so similarly if the file is empty
that means no visas have been found.
So we actually print that here.
So if you're using pite on point all this website entry point for actually skip it's done.
OK.
So then we simply have to draw offices over that image and that's what this loop is about.
So as you can see we have four values here in our offices.
So what we're doing we're stepping through each of these four values in this industry by using a for
loop.
And what we're doing we're plotting or drawing I should see a rectangle.
And this is the color pink here.
I guess you're wondering just plugging it here is in your tangle function and then issuing it here.
So it's simple.
Let's run this one more time.
There we go.
Let's go combining this in either direction.
So let's move on to the second block of code here.
So what's different here is no we're not we're looking to classify as we're Firstly loading thius classify
as we did before but now we're also creating an I classify object here.
So again we LoDo image default image here greyscale image and initialize all of these classifier here.
So similarly as well if no faces have been found we print notices found actually just changes quickly
to be compatible with two and three point four.
So what happens when faeces are found is that we're actually drawing rectangles again over the face
showing that image waiting for a key to be pressed and once a key is pressed we cropped that fierce.
So remember how we cropped images using umpires array indexing.
So we have cropped the fees out of it.
These are from to co-ordinate the locations of the feast that was stored in faeces here.
And we actually feed that image.
No.
2 0.
I classify you what we actually feed degree image in here.
So we feed it to gasifier and then we have eyes.
It eyes that were stored in image and you know most humans should have two eyes.
So we'll see if Donald Trump has two eyes just now.
And we actually draw his eyes over here.
So each time someone clicks key here and he on the image it plots each eye at a time.
So let's go ahead and run this school.
There we go.
It reads.
Let's see if it picks up the ice.
Yep first has been found.
Second day has been found.
Excellent.
All right.
So we've actually made a fierce and I did action successfully here.
Let's see if we can do it with a live video stream from a webcam so let's scroll down to that block
of code here.
And this is where we actually do to see him face an eye detection.
However we're doing it now from a video stream from a webcam and would have done differently here.
Usually in most applications you actually find you fill a rectangle of the fierce highlighted image.
However what I've done I've actually cropped my face of the image.
So let's run the code and I'll give you an idea what's going on.
So there we go.
My fears cropped out of the image and only my face so you can run this good I mean it's just the novelty
effects.
No big deal.
If you wanted differently like if you actually showed a Bactrim with a face you can actually try something
different to anyone but editing this into the same code here.
So what's going on here is that again reloading our classify has however created a function that we
feed the webcam image in and dysfunction basically takes the webcam image finds forces using the similar
crude that we did before.
Krups So it does this and finds that I again as we did previously here.
But instead of drawing a rectangle for the face although it is being done here we actually just crop
that rectangle out and once we have cropped that image of all of this we detect eyes in that image right
here and we draw the rectangle colored rectangle over each of your eyes.
We don't have any weird keys here because we wanted to do it at the same time.
And then we simply flip that image here.
So it's you know in sync like a mirror image for yourself and read in that image.
So let's roll it one more time.
There we go.
It's pretty simple.
So I invite you to actually keep playing and tuning does all the things you can make some cool little
apps with these images with his fist and detections.
So have fun.
So what am actually know about to do though is actually show you what these parameters indetectable
the scale here.
So you may have noticed we use detect multi-skilled in our eye and fiefs classify your radio and your
two parameters here 1.3 and five which is what we used we use typically for physics.
But I'll explain why and explain the effects of increasing and decreasing numbers.
So let's go along to some notes I left here.
So as I said detectability skill as tree input parameters your input image a scale factor and minimum
neighbors.
So what does skill factor do.
First the skill factor specifies how much we want to reduce the image is shown with skill.
So what that means is that when you're pyramiding how many times like by what factor are we increasing
or decreasing to permit image by setting it at one point means we're increasing or decreasing the image
by 80 percent each time it's killed.
So you know if you're doing if you're bigger value smaller live closer to 1.0 of five or valiance close
to one but not exactly one because one is not going to do anything.
You actually have a lot more competitions to do because you're actually scaling a smaller and smaller
increments.
So now let's discuss the minimum neighbors setting.
So quickly let's read this here.
It specifies a number of numbers.
Each potential window as her mother's heart cascaded windows should have in order to be considered positive
detection.
So typically we set a tree in six.
What this means if you think about it is that let's run this first first ossify of Trump.
So what's going to happen here is that usually when there's a window the size the window that's right
next it like if we draw an image right here is also going to fix.
And similarly again.
So you may have multiple windows over to see him face.
So how do we know that's one piece and not many faces.
Well we don't.
But what we do is actually set this value here.
So if we got a minimum of say tree faces in that same region then we know that's one fix that's there
with minimum neighbors indicates.
So a low value will actually detect multiple pieces of a single thius and a high is actually reduce
the sensitivity of our detection units or algorithm.
So typical ranges are between 3 and 6.
If you want to reduce your false false positive I suggest you said this value may be higher maybe even
10 if you want.
And if you wanted to be very sensitive in picking up this is that something that maybe one or even two.
So that brings us to the end of season detection.
Hope you learned a art in this lesson and you're not ready to implement.
Pretty cool and actually very simple.
Many projects on pedestrian and car detection.