1
00:00:01,270 --> 00:00:04,710
This is the code that we created in our previous lesson.

2
00:00:04,750 --> 00:00:07,320
The code was set to read an image file.

3
00:00:07,720 --> 00:00:13,540
In this lesson we will be using your laptop camera and detecting the face and eyes from the moving image

4
00:00:13,540 --> 00:00:15,430
from the camera.

5
00:00:15,450 --> 00:00:20,850
For those of you who do not have a camera connected to your laptop you wouldn't be able to do this part

6
00:00:20,850 --> 00:00:23,460
of the lesson with your computer.

7
00:00:23,460 --> 00:00:24,780
But the codes are simple.

8
00:00:24,960 --> 00:00:31,280
So I want you to go through this lesson so you can understand how the process goes to capture the camera

9
00:00:31,310 --> 00:00:31,910
image.

10
00:00:31,910 --> 00:00:39,050
We'll set a variable cap and use the video capture method set number zero which is the device number

11
00:00:40,600 --> 00:00:43,610
if you have multiple cameras set to your laptop.

12
00:00:43,630 --> 00:00:50,230
You might want to adjust this number to 1 or 2 so that the open CV will recognize the other cameras

13
00:00:50,230 --> 00:00:53,890
you wish to use.

14
00:00:53,890 --> 00:00:58,680
Now let's delete the variable image we replaced the code to read.

15
00:00:58,750 --> 00:01:06,370
Frame equals capped up read by setting this code we'll be able to receive the video image through the

16
00:01:06,370 --> 00:01:09,620
camera and set it in the variable frame.

17
00:01:09,710 --> 00:01:14,500
We need to replace the all the variable image to frame.

18
00:01:14,840 --> 00:01:20,240
You see that the image has changed to frame once the image is captured.

19
00:01:20,260 --> 00:01:21,510
We need to create a loop.

20
00:01:21,540 --> 00:01:25,480
So we constantly receive the frame and livestream the video.

21
00:01:26,350 --> 00:01:35,600
Let's choose all these codes and set an indent we said a while loop to true so we can go on and receive

22
00:01:35,600 --> 00:01:36,980
the frame.

23
00:01:36,980 --> 00:01:40,130
We also need to set that I am show and wait.

24
00:01:40,130 --> 00:01:41,510
Key methods in the loop

25
00:01:44,390 --> 00:01:47,860
when we set the image we set the weight key to zero.

26
00:01:47,930 --> 00:01:54,140
To constantly show the image in case of using the frame we will set this to one millisecond.

27
00:01:54,140 --> 00:01:57,710
So the loophole process every one millisecond to show the video.

28
00:01:58,680 --> 00:02:02,530
We can also determine which key to hit to finish the process.

29
00:02:02,760 --> 00:02:12,770
Let's set the key to Q if v dot wait key and 0 x F F equals equals or d q.

30
00:02:13,230 --> 00:02:22,810
Then the loop will break 0 x f f means hexadecimal number f f will need to go into logical conjunction.

31
00:02:22,810 --> 00:02:25,770
To understand this but that's too complicated.

32
00:02:25,770 --> 00:02:34,510
You can just memorize this code as it is once the last byte of the waiting process equals to Q The process

33
00:02:34,510 --> 00:02:42,050
will break when the loop breaks the windows will be destroyed and the process will finish.

34
00:02:42,130 --> 00:02:45,370
Now we've completed the code so let's try running this code.

35
00:02:48,370 --> 00:02:54,260
Once you run this code you may get a message asking if you accept pi charm to access your camera so

36
00:02:54,280 --> 00:02:58,550
hit ok then run the code again.

37
00:02:58,560 --> 00:03:00,960
Here is my actual video.

38
00:03:00,960 --> 00:03:04,230
You can see that the rectangles are placed on my face and eyes.

39
00:03:05,010 --> 00:03:08,130
So the system is successfully detecting the eyes.

40
00:03:08,400 --> 00:03:13,290
Even if I move my face the rectangles will keep moving with me.

41
00:03:13,740 --> 00:03:17,240
You might see a third square jumping around my face.

42
00:03:17,250 --> 00:03:21,830
This means that the system is detecting something similar to my eyes.

43
00:03:21,870 --> 00:03:28,640
If we want to get a better result we'll need to have to set the scale factor to a smaller number.

44
00:03:28,770 --> 00:03:32,550
Let's see what happens if I put all my glasses.

45
00:03:32,550 --> 00:03:36,870
You'll see that the system isn't detecting the eyes properly.

46
00:03:36,870 --> 00:03:44,860
In this case we will need to set another example fall so we can also detect faces with glasses try running

47
00:03:44,860 --> 00:03:48,780
this code on your computer and see how your system works.

48
00:03:50,300 --> 00:03:57,760
To finish the process I want you to move your castle onto the video image and press cue on your keyboard.

49
00:03:58,160 --> 00:04:03,520
Once you hit the cue the image will close and the process will finish.

50
00:04:03,570 --> 00:04:07,710
That's how you do face recognition using a camera.

51
00:04:07,710 --> 00:04:14,400
I want you to make sure you hang onto this code since we will be using it for our drone project.

52
00:04:14,400 --> 00:04:19,580
We'll be setting this code so that the drone will detect faces using its camera.
