We successfully finish receiving video from the drone camera and streaming it on the webcam.
In this lesson we will be creating the face recognition part.
First I want you to go to the tools folder where we set the hard cascade example.
Right click on the file and copy this next go pasted in the model's folder and press OK.
You can see that the hard cascade excel file has been set under the model's folder.
Now go to the drone manager p y will be using the excel file to create the face recognition function.
Let's start by setting the example path on the top set face detect XM alpha with Slash drone app slash
models slash since the file name is long let's right click on the Excel file choose refactor and rename
once you see the file name.
Copy that and paste it to the path.
Next we want to receive an error.
If the example file doesn't exist so let's set a class named error.
No face deduct XM Alpha as an exception followed by a message.
Error no phase detect XM Alpha.
Here I said exception class to be inherited with the straightforward class name so we can easily detect
what the area is now scroll down to send command.
We can also add if not statement.
If not the OS path exist for the XM Alpha raisin error with the message that there is no XM Alpha.
Let's go on and set self face cascade to see V cascade classifier and set the XM Alpha.
We also want to set a flag to determine if we will enable the face detection or not.
Initially we will set to false.
Now scroll down so we can add some codes to the video method.
Here we see the video JPEG generator will add the face detection method in here before we go into the
face detection.
We need to enable the face detection set that is enable face detect to true.
Also let's add a disabled face to tech method so we can switch off the face detect.
Here we need to set the self is enable face deductibles.
Now let's go onto the video JPEG generator go into the video binary generator and add an if statement.
If the face detectors enable if the patrol is on we need to stop the patrol.
We've done this part in the open CV but we'll set it again.
Grey will be set with CV CBT color first argument with the frame followed by CV color BGR to Gray next
faces will be set to sell face cascade detect multi scale and the color gray followed by one point three
and five which was determined in the sample code.
If the face was detected we need to get the x y point width and height to set and faces
once the face is detected we want to enclose it with the square.
So we set the CV rectangle function and set the frame with x y x plus width and Y plus height followed
by the color blue which will be 2 5 5.
Come on 0 come on 0.
The line thickness will be 2.
In this example we will detect just one face.
So once a face is detected we will break the for loop.
Next go to server P Why go to where the patrol command is under the stop patrol command.
Let's set the face detect.
Command this command will be faced detect and track command.
We still haven't set the tracking method but we'll get to it later on set to run drone enable face detect.
Copy this command to create the stop face detect and track set to run drone disable face detect
once we set the server IP why.
Let's go to the controller HDMI out go to the events mode and copy the stop patrol button code and paste
to twice change the button word to face detect and track and stop face detect and track.
Remember to change the content to face detect and track and stop face detect and track
now we've finished the code.
So let's run the script and go for a test fly.
Once we run the code go to the controller site let's press take off and wait until the video stream
starts
you can see that the camera is too low so I'll press on up to fly the drone so the height of my face
once the camera fits my face I'll press the face detect and track button.
Let me turn around so you can see the blue rectangles set on my face.
I can move my face around and the rectangle will follow me.
We've succeeded in setting the face detect function to our system.
Now let's hit the stop phase detect and track button.
I'm going to turn around again this time.
You can see that the blue rectangle doesn't show up as the face detectors disabled press the land button
to finish the process.
Okay.
Great job.
Next we will go on to setting the tracking part see at the next lesson.