This is the code that we created in our previous lesson.
The code was set to read an image file.
In this lesson we will be using your laptop camera and detecting the face and eyes from the moving image
from the camera.
For those of you who do not have a camera connected to your laptop you wouldn't be able to do this part
of the lesson with your computer.
But the codes are simple.
So I want you to go through this lesson so you can understand how the process goes to capture the camera
image.
We'll set a variable cap and use the video capture method set number zero which is the device number
if you have multiple cameras set to your laptop.
You might want to adjust this number to 1 or 2 so that the open CV will recognize the other cameras
you wish to use.
Now let's delete the variable image we replaced the code to read.
Frame equals capped up read by setting this code we'll be able to receive the video image through the
camera and set it in the variable frame.
We need to replace the all the variable image to frame.
You see that the image has changed to frame once the image is captured.
We need to create a loop.
So we constantly receive the frame and livestream the video.
Let's choose all these codes and set an indent we said a while loop to true so we can go on and receive
the frame.
We also need to set that I am show and wait.
Key methods in the loop
when we set the image we set the weight key to zero.
To constantly show the image in case of using the frame we will set this to one millisecond.
So the loophole process every one millisecond to show the video.
We can also determine which key to hit to finish the process.
Let's set the key to Q if v dot wait key and 0 x F F equals equals or d q.
Then the loop will break 0 x f f means hexadecimal number f f will need to go into logical conjunction.
To understand this but that's too complicated.
You can just memorize this code as it is once the last byte of the waiting process equals to Q The process
will break when the loop breaks the windows will be destroyed and the process will finish.
Now we've completed the code so let's try running this code.
Once you run this code you may get a message asking if you accept pi charm to access your camera so
hit ok then run the code again.
Here is my actual video.
You can see that the rectangles are placed on my face and eyes.
So the system is successfully detecting the eyes.
Even if I move my face the rectangles will keep moving with me.
You might see a third square jumping around my face.
This means that the system is detecting something similar to my eyes.
If we want to get a better result we'll need to have to set the scale factor to a smaller number.
Let's see what happens if I put all my glasses.
You'll see that the system isn't detecting the eyes properly.
In this case we will need to set another example fall so we can also detect faces with glasses try running
this code on your computer and see how your system works.
To finish the process I want you to move your castle onto the video image and press cue on your keyboard.
Once you hit the cue the image will close and the process will finish.
That's how you do face recognition using a camera.
I want you to make sure you hang onto this code since we will be using it for our drone project.
We'll be setting this code so that the drone will detect faces using its camera.