1
00:00:00,540 --> 00:00:08,010
In this lesson we will start our Python project launch pi charm and open the main dot P. wide file which

2
00:00:08,010 --> 00:00:11,100
we created earlier in the file.

3
00:00:11,100 --> 00:00:13,740
We set some codes to test pi term.

4
00:00:13,920 --> 00:00:16,470
You can clear all the test codes.

5
00:00:16,860 --> 00:00:21,270
We will be using the main dot P Why file for operating the drone.

6
00:00:21,510 --> 00:00:26,580
So I want to create a different folder for the sample codes that we make in this lesson.

7
00:00:26,580 --> 00:00:30,360
Right click on P Y Tello and choose new.

8
00:00:30,510 --> 00:00:35,700
Then choose directory we'll set the directory name to tools and hit.

9
00:00:35,720 --> 00:00:42,900
OK you can see that the tools directory has been created under P Y Tello.

10
00:00:42,920 --> 00:00:50,440
Now I want you to grab that to XM Mal files and the image data which we saved onto our desktop drag

11
00:00:50,450 --> 00:01:00,670
the three files into the tools directory and save next right click on tools and choose new then click

12
00:01:00,670 --> 00:01:02,480
on python file.

13
00:01:03,010 --> 00:01:05,710
We'll name this file image based detect

14
00:01:09,220 --> 00:01:11,620
I'll expand the window so you can see better.

15
00:01:12,130 --> 00:01:15,080
For this lesson we will be using the new file.

16
00:01:15,400 --> 00:01:22,450
Choose the file go to the go tab and click the black triangle next to the word go juice choose edit

17
00:01:22,450 --> 00:01:28,900
configurations in our previous lesson we chose main up y as our path.

18
00:01:28,900 --> 00:01:37,130
This time we need to choose the X AML file we imported click on the folder icon choose tools and go

19
00:01:37,130 --> 00:01:44,680
to the image face detect dot P Y that we just created press open and confirm.

20
00:01:44,740 --> 00:01:52,500
Okay let's print test to see if we set the path correctly as we run this code.

21
00:01:52,570 --> 00:01:59,080
You can see that the test has been successfully printed I usually have my results on the right side

22
00:01:59,080 --> 00:02:07,690
of the screen click on the settings icon on the right center Jews move to and select right you'll see

23
00:02:07,690 --> 00:02:09,280
that the layout changed.

24
00:02:09,280 --> 00:02:13,940
If you prefer to have it on the bottom you don't need to make this change.

25
00:02:13,990 --> 00:02:16,330
Now we are prepared to write some codes.

26
00:02:18,370 --> 00:02:21,530
Start by importing c v two as C V.

27
00:02:21,550 --> 00:02:24,600
So we can import the open C V.

28
00:02:24,670 --> 00:02:34,650
Next we'll get the example files we downloaded create a variable face cascade and set c v choose the

29
00:02:34,650 --> 00:02:43,600
cascade classifier method this will be followed by the and mail phone name go to the heart cascade frontal

30
00:02:43,600 --> 00:02:49,840
face X and mail file and right click choose refactor and rename.

31
00:02:50,140 --> 00:02:52,420
Here we will see the full file name.

32
00:02:52,420 --> 00:02:53,410
So copy it.

33
00:02:53,420 --> 00:02:57,910
I'll close this window and paste the name between the quotation mark.

34
00:02:59,110 --> 00:03:01,210
We will do the same with the HA cascade.

35
00:03:01,390 --> 00:03:12,510
I exemplified create another variable and paste the excel file name change the variable name to I cascade.

36
00:03:12,650 --> 00:03:18,880
Now we've completed setting the two XM l file to be used in the script.

37
00:03:18,890 --> 00:03:29,870
Next we need to prepare the image data create a variable I AMG and set CB dot I m r e a d method.

38
00:03:29,870 --> 00:03:33,170
This method will enable us to read the image.

39
00:03:33,200 --> 00:03:39,880
This will be followed by the image file name which is image dot JP G.

40
00:03:40,010 --> 00:03:42,980
Here we've set all the files we need.

41
00:03:42,980 --> 00:03:46,630
First we will need to create the image into a grayscale.

42
00:03:46,970 --> 00:03:52,340
Create a variable Gray and set C V dot CBT color.

43
00:03:52,400 --> 00:04:00,950
Set the image as a first argument then set CV dot color B G are two gray.

44
00:04:01,040 --> 00:04:05,090
Next we want to detect the face of this gray image.

45
00:04:05,150 --> 00:04:12,890
Create a variable faces and set the face cascade detect multi scale method followed by the variable

46
00:04:12,890 --> 00:04:15,570
Gray as the first argument.

47
00:04:15,670 --> 00:04:19,850
The second argument will be the scale factor as in the sample code.

48
00:04:19,870 --> 00:04:26,470
We will set the scale to one point three by changing this number to a smaller number.

49
00:04:26,470 --> 00:04:32,830
You will be able to detect the image in smaller pieces but keep in mind that the more smaller the scale

50
00:04:32,830 --> 00:04:36,270
becomes the more time it takes to process.

51
00:04:36,370 --> 00:04:43,240
So I will suggest that one point three will be a good number just start off with for the next argument

52
00:04:43,270 --> 00:04:48,340
will be the men neighbors which we will set to 5.

53
00:04:48,400 --> 00:04:53,310
This is clarifying how the system would detect faces that are overlapping.

54
00:04:53,470 --> 00:04:58,960
Don't think too much and try to understand what all the argument stands for and simply use the values

55
00:04:58,960 --> 00:05:01,000
in the sample code.

56
00:05:01,000 --> 00:05:07,300
Now we've set the code to detect the face I'll set to print out the number of faces detected by printing

57
00:05:07,300 --> 00:05:09,500
length of the faces.

58
00:05:09,520 --> 00:05:17,350
Next we set a for loop to get the x y coordinate and also the width and height point of the faces based

59
00:05:17,350 --> 00:05:20,640
on the data we want to set a square on the face.

60
00:05:21,040 --> 00:05:28,510
We can use the c v dot rectangle method and set the image as the first argument the next argument will

61
00:05:28,510 --> 00:05:39,050
be all the points of the face which is x y and x plus width and Y plus height the next argument will

62
00:05:39,050 --> 00:05:41,340
be the color of the rectangle.

63
00:05:41,510 --> 00:05:49,330
Here we'll use to fifty five point zero point zero which will be the color blue last.

64
00:05:49,330 --> 00:05:54,390
We set the thickness of the lines here let's set it to two.

65
00:05:54,400 --> 00:05:58,440
Now let's talk about what the x and y points mean.

66
00:05:58,490 --> 00:06:05,660
Here is the sample image the left top corner will be the beginning of the coordinate going down the

67
00:06:05,660 --> 00:06:12,300
image the Y point goal is higher going right the X point goes higher.

68
00:06:12,440 --> 00:06:21,050
In this case the first point to be detected will be the left top corner the value for x and y will be

69
00:06:21,050 --> 00:06:26,740
set as the second argument to determine how large the rectangle will be.

70
00:06:26,750 --> 00:06:32,540
We need to add the width of the face to X and the height of the face to Y.

71
00:06:32,550 --> 00:06:36,590
Here we have created a rectangle that frames the face.

72
00:06:36,750 --> 00:06:39,660
Next we set the color of the rectangle to be blue.

73
00:06:40,890 --> 00:06:48,490
Lastly we set the thickness of the line to be 2 which is the thickness you will see in this image.

74
00:06:48,500 --> 00:06:54,950
Next we will go on and change the color inside this rectangle to gray so we can detect where the eyes

75
00:06:54,950 --> 00:06:56,260
are.

76
00:06:56,330 --> 00:07:05,570
Let's create a variable ie Gray and set the variable Gray with the size to y as Y plus H an X as x plus

77
00:07:05,690 --> 00:07:06,680
W.

78
00:07:06,740 --> 00:07:10,960
This means we are cutting out the face image and setting it into variable ie.

79
00:07:10,970 --> 00:07:12,510
Great.

80
00:07:12,650 --> 00:07:19,310
We also want to cut out the color of the eyes so we set a variable eye color and cut out the image by

81
00:07:19,310 --> 00:07:27,010
setting y as Y plus H and x as x plus W to detect where the eyes are.

82
00:07:27,020 --> 00:07:33,230
We will set the variable eyes and set the eye cascade detect multi scale method.

83
00:07:33,230 --> 00:07:39,680
The argument will be set to ie Gray which we just create and now we can set the rest of the arguments

84
00:07:39,740 --> 00:07:42,140
but I'll skip that for now.

85
00:07:42,270 --> 00:07:46,350
Again we will be setting a for loop to get the four points.

86
00:07:46,560 --> 00:07:52,350
Let's set the points t e x E Y E W and H.

87
00:07:52,350 --> 00:07:59,670
This should loop as many times the process detects size we then create a rectangle by using the c v

88
00:07:59,670 --> 00:08:03,160
a rectangle method onto the eye color image.

89
00:08:04,410 --> 00:08:06,710
Followed by the four points as argument.

90
00:08:07,340 --> 00:08:14,250
E x e y e x plus E W E Y plus E H.

91
00:08:14,250 --> 00:08:21,570
This time we will set the color to zero to fifty five point zero to make a green rectangle.

92
00:08:22,500 --> 00:08:29,940
Lastly the line thickness will be the same two it'll be easier to understand how the process ran through

93
00:08:29,970 --> 00:08:32,140
by looking at the final image.

94
00:08:32,280 --> 00:08:40,190
So we set C V I am show method to show the new image we created as I am G.

95
00:08:40,380 --> 00:08:44,540
Then we set C the weight t to 0.

96
00:08:44,610 --> 00:08:51,360
The process will go into a loop to show the image and wait for the next action to occur on the keyboard.

97
00:08:51,480 --> 00:08:54,800
Once an action occurs we want to finish showing the image.

98
00:08:55,230 --> 00:09:00,000
So we set c v destroy all windows.

99
00:09:00,000 --> 00:09:03,190
Now it's the moment to see how the process goes.

100
00:09:03,360 --> 00:09:07,780
Once we run this code you will see the number one as the result.

101
00:09:07,890 --> 00:09:13,860
I have to drive the image in since it popped out of the screen the number one is showing the number

102
00:09:13,860 --> 00:09:15,720
of faces detected.

103
00:09:15,720 --> 00:09:22,850
Since we set to print out the length of the faces as you see we've successfully detected the face in

104
00:09:22,850 --> 00:09:24,320
the eyes.

105
00:09:24,650 --> 00:09:29,970
A blue rectangle is placed on my face and two green rectangles on my eyes.

106
00:09:30,320 --> 00:09:37,350
With these simple codes you manage your program of face recognition system to delete the image hit any

107
00:09:37,350 --> 00:09:39,300
key on your keyboard.

108
00:09:39,300 --> 00:09:45,300
Once you hit a key on the keyboard the image will disappear and the process has been finished.

109
00:09:45,300 --> 00:09:51,840
As we set the weight key method here the system went into a loop showing you the image.

110
00:09:52,530 --> 00:09:56,860
I'm going to run this code again to properly finish showing this image.

111
00:09:56,910 --> 00:10:00,790
You need to be selecting the image before you hit the keyboard.

112
00:10:00,840 --> 00:10:04,770
If the image isn't selected nothing will happen.

113
00:10:04,770 --> 00:10:07,640
Remember to select the image and hit a key.

114
00:10:08,280 --> 00:10:13,080
Then the process will go onto the destroy all windows and finish the process.

115
00:10:15,790 --> 00:10:22,000
I want you to try downloading some images and setting it into this script to see if your face recognition

116
00:10:22,000 --> 00:10:25,780
system works some other images in our next lesson.

117
00:10:25,780 --> 00:10:28,120
We will be detecting faces in videos.
