1
00:00:00,090 --> 00:00:00,810
Hi, welcome back.

2
00:00:01,020 --> 00:00:09,480
In this video Over the Roads, a program which detects faces in a video, in an MP for video and then

3
00:00:09,480 --> 00:00:17,040
creates a new video based on the original video, but with rectangles added around the faces in the

4
00:00:17,040 --> 00:00:17,490
video.

5
00:00:18,120 --> 00:00:23,280
Now to understand these video, you should have watched two previous videos.

6
00:00:23,490 --> 00:00:31,950
One is where we detected faces in an image that is the code that we build through all that video.

7
00:00:32,100 --> 00:00:37,410
This is the video in the image processing section and also in the video processing section.

8
00:00:37,410 --> 00:00:47,700
We had a video where we extracted frames from a video file and this video in this program, we will

9
00:00:47,700 --> 00:00:51,570
combine the code of these two scripts.

10
00:00:51,900 --> 00:00:55,710
That's why I've pasted these two scripts in this report.

11
00:00:59,320 --> 00:01:02,380
So let's start how do we start this?

12
00:01:02,590 --> 00:01:09,820
Well, we want to first read the video video we will be working on is this one in here is three seconds

13
00:01:09,820 --> 00:01:10,270
long.

14
00:01:12,580 --> 00:01:16,390
And we will try to detect the face of the person here.

15
00:01:16,960 --> 00:01:19,150
So draw a rectangle around this with you.

16
00:01:20,750 --> 00:01:21,140
Right.

17
00:01:21,380 --> 00:01:24,200
So let's start by opening the video.

18
00:01:24,650 --> 00:01:33,800
I think this script should be the first one in here, so we import open S.U.V. and we capture a video

19
00:01:33,800 --> 00:01:42,620
file stoning that's in the video valuable and we get to the first frame of the video here.

20
00:01:42,620 --> 00:01:45,890
We just have a counter a that is equal to one.

21
00:01:46,070 --> 00:01:47,300
We don't need that, actually.

22
00:01:47,540 --> 00:01:48,760
Just delete the counter.

23
00:01:49,540 --> 00:01:55,490
And here we have success, which is equal to true if we were able to get.

24
00:01:56,630 --> 00:02:03,140
The video writes successfully so while true, we execute this block of codes.

25
00:02:04,580 --> 00:02:08,870
What we do here is we write an image to an image file.

26
00:02:08,900 --> 00:02:10,669
This is not what we're doing this time.

27
00:02:10,880 --> 00:02:12,140
So we delete that.

28
00:02:13,280 --> 00:02:20,990
What we do this time in each frame is we detect faces.

29
00:02:21,170 --> 00:02:27,950
So in this other script in here we are opening an image, a frame.

30
00:02:27,950 --> 00:02:32,000
We construct frames, using files, using image files.

31
00:02:32,450 --> 00:02:37,220
But this time we have those image objects.

32
00:02:37,370 --> 00:02:40,100
So that is an image object that is an image object.

33
00:02:40,340 --> 00:02:43,850
This comes from the video of this comes from an image file.

34
00:02:44,120 --> 00:02:48,080
But still, these two are the same types of objects.

35
00:02:48,410 --> 00:02:55,970
So what we do is once we have an object, a frame objects, we want to get the faces from that image

36
00:02:55,970 --> 00:02:56,360
object.

37
00:02:56,360 --> 00:02:59,630
You see that image object is passed in here.

38
00:02:59,840 --> 00:03:03,050
So I'm going to delete that.

39
00:03:03,350 --> 00:03:08,210
We don't need that and get this line face cascades and paste.

40
00:03:08,210 --> 00:03:14,930
It's above the loop outside the loop because we want to create a Cascades object first.

41
00:03:15,140 --> 00:03:21,230
So this is the blueprint that contains how a face a human face looks like.

42
00:03:22,430 --> 00:03:28,280
So then we get the faces in here in the wide loop.

43
00:03:28,790 --> 00:03:29,570
So indent.

44
00:03:30,710 --> 00:03:37,520
So the first sets of faces for that first frame rates.

45
00:03:37,880 --> 00:03:44,690
So we create the first frame here, the very first frame of the video, and we detect faces in that

46
00:03:44,700 --> 00:03:46,280
very first frame rates.

47
00:03:47,390 --> 00:03:56,090
Then what we do is that while we iterate so we get that block of codes, we paste it here and indent

48
00:03:56,540 --> 00:04:07,250
tab, you see four is under the wire loop and then you have this is intent on the before loop o seu

49
00:04:07,250 --> 00:04:10,520
for x y width and height in.

50
00:04:11,660 --> 00:04:20,690
Faces, we say it right, a rectangle around the frame, the current frame in the first iteration of

51
00:04:20,690 --> 00:04:25,490
the while loop, this will be the very first frame of the video we said that's already.

52
00:04:27,190 --> 00:04:33,280
So we draw a rectangle with these coordinates where the face is found.

53
00:04:34,000 --> 00:04:37,480
This is a white rectangle with a width of four.

54
00:04:37,750 --> 00:04:38,500
That's fine.

55
00:04:39,490 --> 00:04:41,740
And then what do we do with this frame?

56
00:04:42,070 --> 00:04:50,590
We want to ride that frame in a new video for that, we need to first create a new video on empty video.

57
00:04:51,220 --> 00:04:59,460
So let's do that outside the loop outputs as a variable name, a sequence of two dots VIDEO.

58
00:04:59,770 --> 00:05:11,170
Right to is the class that creates new videos and opens TV works well with a VIP video formats.

59
00:05:12,220 --> 00:05:19,600
So let's the right outputs does Aivi as the name of the video file a comma.

60
00:05:20,020 --> 00:05:23,980
Then you have to give some parameters, such as video writer.

61
00:05:26,900 --> 00:05:27,440
That's one.

62
00:05:28,990 --> 00:05:33,460
This is the context of the video, so you have to write it like this.

63
00:05:35,590 --> 00:05:45,250
Then outside the parentheses goes the number of frames per second and also the dimensions of the new

64
00:05:45,250 --> 00:05:45,790
video.

65
00:05:45,820 --> 00:05:55,720
You want to have the dimensions we can gather those using actually, we can use it hides a single to

66
00:05:56,110 --> 00:06:03,910
frame the shape zero and width is equal to frame the shape.

67
00:06:04,240 --> 00:06:09,970
So we're getting the dimensions of the original video because we want to have the new video using the

68
00:06:09,970 --> 00:06:12,040
same width and height.

69
00:06:13,480 --> 00:06:19,900
So for width and then height, the resolution of the video and we have 30 frames per second.

70
00:06:21,060 --> 00:06:27,810
So once we have an empty video file video objects, we don't have a file yet, then we want to create

71
00:06:27,810 --> 00:06:30,270
a file on disk.

72
00:06:30,870 --> 00:06:39,600
So we say under the while loop outside the full loop, just here, actually outside the full loop.

73
00:06:40,080 --> 00:06:51,330
So once we drew rectangles in the current frame, then we want to access the empty output video and

74
00:06:52,320 --> 00:06:57,560
use the right methods and right the frame, the current frame to the video.

75
00:06:58,750 --> 00:07:01,630
So we detect face in the frame.

76
00:07:02,170 --> 00:07:08,320
We iterate over all the faces because there could be more than one face in the video.

77
00:07:08,470 --> 00:07:15,160
We are right rectangles around the face and then we ride the frame in the outward video.

78
00:07:15,610 --> 00:07:21,460
Then what we do is we again get to the next frame.

79
00:07:21,640 --> 00:07:29,140
So when we execute this, the next frame will be stored in the frame variable and the loop will run

80
00:07:29,140 --> 00:07:29,650
again.

81
00:07:30,670 --> 00:07:36,100
So this time with a second frame, we detect faces with the second frame.

82
00:07:36,670 --> 00:07:38,320
We iterate through those phases.

83
00:07:38,710 --> 00:07:43,150
We arrive the second frame in the video, which is currently open and so on.

84
00:07:43,150 --> 00:07:48,880
We repeat the process until all the frames have been exhausted.

85
00:07:49,480 --> 00:07:56,860
Then outside the wire loop, you have to indent your axis, outputs the video and you release it to

86
00:07:57,190 --> 00:08:00,610
generate the video and store its on disk.

87
00:08:01,990 --> 00:08:03,520
So we don't need that's code.

88
00:08:06,150 --> 00:08:07,470
This is all we need.

89
00:08:11,710 --> 00:08:17,710
Let me split this line in here because it's too long and we are ready to run this.

90
00:08:19,580 --> 00:08:30,050
So, Ron, we see that output does a the eye has been generated, but you have to wait for about two

91
00:08:30,050 --> 00:08:33,830
minutes or so because video processing takes long.

92
00:08:33,980 --> 00:08:40,010
So we have three seconds, but we have 90 frames and a rifle is not that fast.

93
00:08:40,820 --> 00:08:42,020
So you have to wait a while.

94
00:08:43,960 --> 00:08:48,790
So my run button is green again, that means the processing finished.

95
00:08:49,120 --> 00:08:56,140
So let me download this article to Aivi file because I don't think it's is able to open API files.

96
00:08:57,070 --> 00:09:00,520
The way you can open them is by using.

97
00:09:01,060 --> 00:09:04,240
I tried the VLCC program works well.

98
00:09:05,750 --> 00:09:06,050
Yeah.

99
00:09:06,260 --> 00:09:07,460
So this is a video.

100
00:09:09,160 --> 00:09:10,030
It's three seconds.

101
00:09:11,060 --> 00:09:14,280
You see the rectangle there for some moments.

102
00:09:14,300 --> 00:09:15,470
We also see.

103
00:09:17,010 --> 00:09:21,810
A false positive in here in the hands of the person is detected as a phase.

104
00:09:22,590 --> 00:09:31,650
Perhaps you can fix that by experimenting with these values in here so you can try that on your own.

105
00:09:32,310 --> 00:09:38,340
You can try to do 1.2 and increase and decrease the other value as well.

106
00:09:38,730 --> 00:09:45,210
We discussed these values when we detected faces in images in the image processing section.

107
00:09:45,870 --> 00:09:52,980
If you want to visually see the artifacts here, you could add a counter such as can't equal to zero

108
00:09:53,020 --> 00:10:00,720
of you say here counts increased by one and print counts.

109
00:10:00,960 --> 00:10:04,020
So that way you can see what's going on here.

110
00:10:04,500 --> 00:10:05,430
So one, two three.

111
00:10:05,460 --> 00:10:08,700
There's a number of the frames they started from one.

112
00:10:11,190 --> 00:10:14,220
Sometimes I noticed that this was far slower.

113
00:10:14,880 --> 00:10:16,920
This time it was faster the processing.

114
00:10:17,250 --> 00:10:20,900
So 90 frames in total in output.

115
00:10:20,940 --> 00:10:22,290
That's a V file.

116
00:10:23,830 --> 00:10:33,120
And that is all you can get the frames of a video modify them, such as writing rectangles around faces

117
00:10:33,120 --> 00:10:36,540
as we did, and then write back the frames in a new video.

118
00:10:37,200 --> 00:10:39,450
Thank you for following I'll talk to you in the next videos.

