1
00:00:02,029 --> 00:00:07,550
In this video, Olga writes a program which converts this video.

2
00:00:11,740 --> 00:00:13,390
Into this.

3
00:00:16,590 --> 00:00:22,860
So as you can see in the article, the video of the face of the person speaking is blurred.

4
00:00:23,670 --> 00:00:25,530
So this is a technique I'm going to use.

5
00:00:25,530 --> 00:00:31,140
I'm going to blur the area around the face so that it's not visible.

6
00:00:31,320 --> 00:00:38,430
You can also use other techniques, such as writing a rectangle, which is filled in.

7
00:00:39,360 --> 00:00:42,040
But this is a more standard practice.

8
00:00:42,050 --> 00:00:49,080
So let me show you how I can do this using, of course, open CV.

9
00:00:49,410 --> 00:00:52,380
So import quota and load the video.

10
00:00:52,390 --> 00:00:56,700
You can find the video attached in the lecture resources.

11
00:00:56,700 --> 00:01:04,110
So the input video, which is smile that's aimed before and this is the output VIDEO So I'm going to

12
00:01:04,290 --> 00:01:10,050
leave the output video and recreate it using open CV.

13
00:01:10,680 --> 00:01:18,060
You also have this face is the example, which is the Cascade Fire, which contains the blueprints.

14
00:01:18,060 --> 00:01:22,350
Oh, our face looks like in example code.

15
00:01:24,660 --> 00:01:31,470
So the program needs to have that file in order to recognize faces in a video.

16
00:01:31,980 --> 00:01:37,050
So video is legal to see to the video capture.

17
00:01:37,110 --> 00:01:44,250
What I'm doing is referring to Smile does MP Fool and creates a video object.

18
00:01:45,340 --> 00:01:53,740
In Python and then create two valuable success and frame a sequel to video reads.

19
00:01:54,040 --> 00:02:01,720
So what I'm doing here is I'm reading the first frame of the video just to check if the video is read

20
00:02:01,720 --> 00:02:02,350
correctly.

21
00:02:02,620 --> 00:02:09,580
So success will gets through or falls as a value and frame will give the first frame as a value.

22
00:02:10,360 --> 00:02:14,440
So if the frame is read successfully, success will be equal to true.

23
00:02:14,440 --> 00:02:16,690
Otherwise, it will be equal to falls.

24
00:02:17,170 --> 00:02:27,310
Then we have faced Cascade, a variable which points to servitude that cascade classifier, and that's

25
00:02:27,310 --> 00:02:32,020
points to faces that example the path of the XML file.

26
00:02:33,190 --> 00:02:38,680
So we have the video, we have the first frame, we have the face cascades object and then we create

27
00:02:38,680 --> 00:02:39,430
an output.

28
00:02:41,810 --> 00:02:43,340
Which is empty for now.

29
00:02:43,760 --> 00:02:46,010
So that's a sequel to video writer.

30
00:02:49,310 --> 00:03:02,420
Let's name this file outputs smile, MP, fool or blurred smile if you preferred or blur face.

31
00:03:02,660 --> 00:03:14,000
So that is the ultimate video now this requires also another argument here that is CV to dot video right

32
00:03:14,000 --> 00:03:23,960
to underscore for CC, which is a class by itself.

33
00:03:24,410 --> 00:03:31,340
It expects now this argument, which is the context of the video you want to create.

34
00:03:32,030 --> 00:03:34,840
The effects of this is what works.

35
00:03:34,850 --> 00:03:38,180
I've tried this and three frames.

36
00:03:38,900 --> 00:03:40,010
It's another argument.

37
00:03:41,310 --> 00:03:48,060
So we've got the path to the ultimate file, the context of the video as a second argument.

38
00:03:48,810 --> 00:03:51,810
The frames per second of the article, the video.

39
00:03:52,050 --> 00:03:59,670
And lastly, the dimensions of the output feed you know of this should be in the form of a tipple,

40
00:03:59,670 --> 00:04:03,510
which could be something like a three hundreds for hundreds of bullets.

41
00:04:04,290 --> 00:04:08,160
You can just declare these numbers like that.

42
00:04:08,520 --> 00:04:18,660
You want to have the same width and height as the original video so that you don't end up with a distorted

43
00:04:18,660 --> 00:04:19,050
video.

44
00:04:19,920 --> 00:04:25,260
Therefore, we need to get the dimensions of the original video.

45
00:04:25,950 --> 00:04:32,400
So what I'm going to do is after we create the video object, after we get the first frame, we get

46
00:04:32,400 --> 00:04:34,500
the dimensions of that first frame.

47
00:04:35,220 --> 00:04:43,410
It's a single to frame dot shape and we get the first item of that table.

48
00:04:43,410 --> 00:04:51,120
So that's creates a table with the height and the width, and the width is equal to frame its shape.

49
00:04:53,840 --> 00:04:54,440
One.

50
00:04:56,160 --> 00:05:01,560
So then we can specify here the width which comes first and the height.

51
00:05:02,430 --> 00:05:05,760
So those are the dimensions of the ultimate video.

52
00:05:07,110 --> 00:05:09,840
Then we were ready to build the wire loop.

53
00:05:10,240 --> 00:05:14,070
Well, success, for example, which is equal to true.

54
00:05:14,100 --> 00:05:26,160
So if success is true, then we build the while loop and ride frames in this output video object.

55
00:05:26,580 --> 00:05:32,610
So while success, we did take the faces from using face cascades.

56
00:05:33,780 --> 00:05:43,770
So that object, which has a detect multi scale glass and this gets a frame as inputs.

57
00:05:44,340 --> 00:05:46,200
So we were working on the first frame.

58
00:05:46,200 --> 00:05:50,010
For now, we detect faces in the first frame.

59
00:05:50,260 --> 00:05:52,170
And these are the coefficients.

60
00:05:52,280 --> 00:05:58,350
And so I've covered those one point one and four is a good set of numbers.

61
00:05:59,130 --> 00:06:05,970
So if you change these, you can make the algorithm more sensitive or less sensitive.

62
00:06:06,390 --> 00:06:13,230
So if you make it over sensitive, it means you will detect false positives.

63
00:06:13,380 --> 00:06:17,340
So false faces objects which which are not faces, but.

64
00:06:18,520 --> 00:06:27,070
Are classified as faces from this algorithm, so that will give us a list of faces because we might

65
00:06:27,070 --> 00:06:29,650
have more than one faces in the frame.

66
00:06:30,310 --> 00:06:35,260
But then we can iterate over the faces for.

67
00:06:36,600 --> 00:06:37,680
X or Y?

68
00:06:37,710 --> 00:06:41,790
So each face has an X and Y and the width and height.

69
00:06:42,870 --> 00:06:46,680
So these are the dimensions of the rectangle around the detected phase.

70
00:06:47,520 --> 00:06:50,010
So we see for that to pull interfaces.

71
00:06:51,540 --> 00:06:54,870
And then we modify the current frame.

72
00:06:55,570 --> 00:07:04,680
So the current frame, but we only modify a particular slice of the frame that is a slice, the portion

73
00:07:04,680 --> 00:07:06,000
where the face is.

74
00:07:06,210 --> 00:07:12,200
So with this coordinate, so y so from y until y plus h.

75
00:07:12,930 --> 00:07:20,520
So that means where the rectangle of the face towards and until somewhere in here.

76
00:07:21,390 --> 00:07:24,810
So we get that portion and then we get the other portion as well.

77
00:07:25,200 --> 00:07:31,080
So we go again from X to X plus width.

78
00:07:31,380 --> 00:07:33,240
So that will give us basically that.

79
00:07:33,240 --> 00:07:38,130
And that's so it will give us the entire rectangle where the face is.

80
00:07:38,580 --> 00:07:42,540
So the entire frame is something like this, right?

81
00:07:43,170 --> 00:07:45,810
And the phase has these coordinates.

82
00:07:46,170 --> 00:07:59,070
So now what we do to this portion of the frame here is we apply a CV to the blur methods and this goes

83
00:07:59,070 --> 00:07:59,580
like this.

84
00:07:59,700 --> 00:08:01,620
So frame again, y.

85
00:08:02,730 --> 00:08:04,170
Y plus h.

86
00:08:05,410 --> 00:08:09,520
And ex until X plus width.

87
00:08:10,390 --> 00:08:16,120
And then we also provides the intensity of the blurriness.

88
00:08:16,570 --> 00:08:18,520
So 50 50 is a good number.

89
00:08:18,670 --> 00:08:25,090
You can go less than that if you want the face to be more visible and you can increase these if you

90
00:08:25,090 --> 00:08:27,850
want the blurring effect to be more intense.

91
00:08:28,600 --> 00:08:29,320
And that's it.

92
00:08:29,800 --> 00:08:34,840
So now we have modified that portion of the frame by blurting it out and.

93
00:08:36,520 --> 00:08:46,540
Then we exit the loop and we say, Oh, foods dot right frame, so we are right, that's current frame

94
00:08:46,810 --> 00:08:49,780
that's modified frame into the outputs.

95
00:08:49,780 --> 00:08:56,680
VIDEO Then what we do is so far we worked on the very first frame of the video, then we want to give

96
00:08:56,690 --> 00:08:57,880
the other frames.

97
00:08:58,750 --> 00:09:05,440
So we say again, success that and frame is sequel to VIDEO That's right.

98
00:09:06,190 --> 00:09:13,290
So that we'll read the next frame of the video, and that's it.

99
00:09:14,090 --> 00:09:22,780
So the while loop will be repeating itself and we exit the loop and we say outputs that release.

100
00:09:24,400 --> 00:09:31,030
To release the video and make it able for writing it on disc.

101
00:09:31,480 --> 00:09:33,400
So I'm going to execute this now.

102
00:09:42,500 --> 00:09:48,950
Now, if you get this error, there is some mismatch between the formats, the video formats.

103
00:09:49,280 --> 00:09:57,290
That means you want to change the outputs from MP for to delete a VR and run again.

104
00:09:58,220 --> 00:10:06,710
You can see that blur smile the same before it's created, but the script has not ended execution yet.

105
00:10:06,980 --> 00:10:10,460
So we want to wait until this file is written.

106
00:10:11,030 --> 00:10:17,300
And of course, for the next time, you can improve the experience, the execution, the program execution

107
00:10:17,300 --> 00:10:26,780
experience by writing here a variable count is equal to zero and then you do see counts as increased

108
00:10:26,780 --> 00:10:32,570
by one and then you print the cones so that you can see some outputs here.

109
00:10:32,750 --> 00:10:37,940
So you see the while loop being executed, so you see these numbers.

110
00:10:39,840 --> 00:10:45,180
Actually, I can stop this and Ronnie's again so that we can see some outputs in here.

111
00:10:45,390 --> 00:10:50,130
So now we see the cones, which basically represent each frame.

112
00:10:52,400 --> 00:10:54,930
So every frame now is being processed.

113
00:10:54,950 --> 00:10:57,950
We are in the eighth frame, nine, 10 and so on.

114
00:11:00,480 --> 00:11:06,750
There will be 90 frames in total because the video is three seconds long.

115
00:11:08,280 --> 00:11:10,470
So there are 30 frames per second.

116
00:11:10,950 --> 00:11:13,050
Three times three, it's 90.

117
00:11:16,780 --> 00:11:24,670
Yes, of the execution has finished, I can download the Lord's mine, that's a AIVI file.

118
00:11:27,010 --> 00:11:27,820
And here it is.

119
00:11:28,030 --> 00:11:36,760
So you can only open this, at least in my case, I can only open it with VLCC program VRC Media Player.

120
00:11:37,450 --> 00:11:39,970
So the other ones might not work.

121
00:11:42,570 --> 00:11:45,570
And yeah, that's the outputs, and that's the final codes.

122
00:11:46,830 --> 00:11:49,450
Thanks for following this, and I'll talk to you the next videos.

123
00:11:49,450 --> 00:11:49,770
So you.

