1
00:00:00,660 --> 00:00:07,410
In this video, we will write a program which opens a computer webcam, and it shows the video of life,

2
00:00:07,410 --> 00:00:08,670
as you can see in here.

3
00:00:09,180 --> 00:00:15,990
So in addition, we also see a rectangle around the face of humans in the video.

4
00:00:16,770 --> 00:00:18,600
So let's do this in this video.

5
00:00:21,820 --> 00:00:30,700
So I'd like to start this program from the previous script, and I'm going to build upon this.

6
00:00:31,690 --> 00:00:33,220
So the previous program?

7
00:00:34,430 --> 00:00:39,500
Was able to open the computer webcam and to record the video.

8
00:00:40,550 --> 00:00:43,580
Using that webcam, but we didn't see the video live.

9
00:00:43,850 --> 00:00:51,830
We just got a final video file at the end in this program, we want to see what is being captured alive

10
00:00:52,580 --> 00:00:57,170
and the way you do that is by using a method called CV.

11
00:00:57,170 --> 00:01:02,000
To that, I am show a let me explain you where we put that methods.

12
00:01:02,450 --> 00:01:09,380
So here we create the video, we capture it from the webcam and we get the first frame and then we get

13
00:01:09,380 --> 00:01:10,430
behind the width.

14
00:01:11,420 --> 00:01:20,150
We create a face cascades a blueprint for detecting faces, and then we create an output file where

15
00:01:20,150 --> 00:01:23,660
the video will be stored when we close the program.

16
00:01:24,230 --> 00:01:29,090
And then we have this loop success as a Boolean.

17
00:01:29,100 --> 00:01:37,190
So it is true when the video is being captured from the webcam, we detect the faces from the frame,

18
00:01:37,190 --> 00:01:38,210
the current frame.

19
00:01:38,930 --> 00:01:41,120
So the frame we got sets from here.

20
00:01:42,410 --> 00:01:49,400
Then we go through all the phases and we draw a rectangle around each phase.

21
00:01:50,150 --> 00:01:57,980
Now at this point here we want to on indent, so be outside the full loop.

22
00:01:58,580 --> 00:02:07,400
But inside the one loop and see see two dots I show I am stands for image show.

23
00:02:07,580 --> 00:02:10,680
So we want to show the frame, the image on the screen.

24
00:02:11,120 --> 00:02:13,220
We want to give a label to the window.

25
00:02:15,140 --> 00:02:16,430
Recording should define.

26
00:02:17,360 --> 00:02:21,920
And then the second argument should be the actual image object.

27
00:02:22,190 --> 00:02:26,540
So the frame object you want to display on that window.

28
00:02:28,450 --> 00:02:37,540
After that, you want to apply the CV to that weight key methods and give an argument of one.

29
00:02:38,170 --> 00:02:44,690
This is basically specifying how long will you wait to display the next video?

30
00:02:44,770 --> 00:02:50,020
So this is one milliseconds and that is a safe value so we can keep it one.

31
00:02:50,470 --> 00:02:51,040
And that's it.

32
00:02:51,110 --> 00:02:55,690
We can run this code now and see what's going on here.

33
00:02:56,380 --> 00:03:03,370
So once I run, it's among your programs, you should see this icon that is the program that has the

34
00:03:03,370 --> 00:03:03,970
video.

35
00:03:04,480 --> 00:03:05,920
So this is life.

36
00:03:05,920 --> 00:03:12,170
Now you see the rectangle around my face, even though this is a very bad lighting.

37
00:03:12,670 --> 00:03:14,770
It's still working well.

38
00:03:15,130 --> 00:03:19,120
You know, you can stop this using this button.

39
00:03:19,840 --> 00:03:28,030
The Stop button, although there is a better way to stop the video from playing, using a more user

40
00:03:28,030 --> 00:03:36,880
friendly technique that is by after the key you apply if key is equal to.

41
00:03:37,120 --> 00:03:47,050
So you see this double assignment operator AWD Q So if the user presses the Q button on their keyboard,

42
00:03:47,950 --> 00:03:49,540
then you want to break the loop.

43
00:03:50,980 --> 00:03:52,240
So let's try this again.

44
00:03:58,000 --> 00:03:59,530
So here is the window.

45
00:04:00,940 --> 00:04:01,780
I press Q.

46
00:04:03,530 --> 00:04:06,250
It took one or two seconds, but the video stopped.

47
00:04:07,080 --> 00:04:14,330
So you should also see now that we have the output, that's Avio File here in my folder, I can open

48
00:04:14,330 --> 00:04:17,060
it with V L C.

49
00:04:20,640 --> 00:04:31,470
And you can see that the video is playing very fast, and we can fix that by changing the frame per

50
00:04:31,470 --> 00:04:33,300
second rate over the video.

51
00:04:33,690 --> 00:04:42,230
So what's happening here is that my webcam records video in 15 frames per second, but the video right

52
00:04:42,360 --> 00:04:45,090
here is configured to write 30 frames per second.

53
00:04:45,930 --> 00:04:53,490
So there is a mismatch between the frames you should try to find on your computer how many frames your

54
00:04:53,490 --> 00:04:57,810
webcam captures and then puts here that number of frames.

55
00:04:57,810 --> 00:04:59,340
So 15, in my case.

56
00:04:59,790 --> 00:05:01,110
So let me run this again.

57
00:05:05,310 --> 00:05:06,660
Yeah, here is the video.

58
00:05:07,290 --> 00:05:08,170
One, two three.

59
00:05:08,190 --> 00:05:08,740
Let's stop.

60
00:05:09,210 --> 00:05:09,720
Cue.

61
00:05:10,740 --> 00:05:16,260
So when you press Q, you should have the focus on the video player for Q to work.

62
00:05:17,050 --> 00:05:19,710
Let me check the output again.

63
00:05:25,390 --> 00:05:27,670
Now, the speeds looks normal to me.

64
00:05:27,820 --> 00:05:28,060
Yeah.

65
00:05:29,520 --> 00:05:30,900
So it's working.

66
00:05:33,460 --> 00:05:37,900
We need to add two more lines here to make this more complete.

67
00:05:38,230 --> 00:05:40,570
And that is, you need to release the video.

68
00:05:41,440 --> 00:05:43,120
This is a good practice to do.

69
00:05:45,030 --> 00:05:55,560
And served to destroy all the windows, that is the methods, and let's try the program again to make

70
00:05:55,560 --> 00:05:57,450
sure everything is working smoothly.

71
00:05:58,260 --> 00:05:59,400
So here is the window.

72
00:05:59,400 --> 00:06:00,090
Hello again.

73
00:06:01,050 --> 00:06:04,200
Press cue to quit.

74
00:06:06,840 --> 00:06:07,650
And it's quite.

75
00:06:08,710 --> 00:06:11,240
There is a bit of delay in my computer, though.

76
00:06:12,040 --> 00:06:14,590
But anyway, if this is the final program.

77
00:06:15,780 --> 00:06:23,850
Capturing the video from webcam, detecting the faces in the video, showing the video on the screen

78
00:06:23,850 --> 00:06:33,030
and also writing the video file in a video a V file, so I hope it works for you and I'll talk to you

79
00:06:33,030 --> 00:06:33,870
in the next videos.

80
00:06:33,870 --> 00:06:34,140
So you.

