1
00:00:02,580 --> 00:00:05,670
But now we will see how we can integrate YOLO v9 with flask.

2
00:00:05,670 --> 00:00:14,610
So I will just go over here and create a new uh.py file by the name last app.py.

3
00:00:16,690 --> 00:00:21,070
Okay, so here I will just writing all my code to create a flask app.

4
00:00:22,090 --> 00:00:28,660
So first of all we will import all the the required libraries over here.

5
00:00:33,690 --> 00:00:37,560
So I am just importing all the required libraries.

6
00:00:40,320 --> 00:00:47,490
I would just like, uh, before this, we need to install the last package, so just install last.

7
00:00:47,940 --> 00:00:48,480
Okay.

8
00:00:51,540 --> 00:00:53,970
Here I will just write from flask import.

9
00:00:55,670 --> 00:00:59,000
Thus rendered template.

10
00:00:59,000 --> 00:01:00,770
We will be using this library later on.

11
00:01:03,110 --> 00:01:04,400
Response.

12
00:01:12,900 --> 00:01:15,900
There Sonify requests.

13
00:01:18,730 --> 00:01:20,170
Ah, we don't need to disturb.

14
00:01:20,470 --> 00:01:20,920
Okay.

15
00:01:22,960 --> 00:01:26,020
Then we can just import OS and.

16
00:01:27,200 --> 00:01:30,380
Import C window opens with Python package.

17
00:01:30,380 --> 00:01:34,340
So in the meanwhile our class library has been installed, so that's good.

18
00:01:36,770 --> 00:01:39,500
Last from this detection.py file.

19
00:01:39,500 --> 00:01:43,400
We will be importing this object detection function as well.

20
00:01:43,820 --> 00:01:52,460
So I will just write over here from detection import object detection okay so that's good.

21
00:01:53,900 --> 00:01:59,720
So in the step number one we need to initialize the class application.

22
00:02:01,250 --> 00:02:05,300
So to initialize the flask application I will just write over here.

23
00:02:06,470 --> 00:02:09,350
Now you can see that we have initialized the flask application.

24
00:02:10,220 --> 00:02:10,580
Okay.

25
00:02:10,580 --> 00:02:12,980
So now next we will configure.

26
00:02:14,510 --> 00:02:16,340
Biosecurity.

27
00:02:19,370 --> 00:02:22,100
Well, we'll just write one app dot config.

28
00:02:28,870 --> 00:02:29,230
Bigger.

29
00:02:29,500 --> 00:02:31,900
And you can write any key over here.

30
00:02:31,900 --> 00:02:33,310
That's not necessary.

31
00:02:34,390 --> 00:02:37,840
So I will just write my own name over here.

32
00:02:43,310 --> 00:02:46,430
So as you know that we are creating a web app using class.

33
00:02:46,430 --> 00:02:54,260
So we will create an upload folder, uh, where if the user uploads any input video image so that uh

34
00:02:54,260 --> 00:02:56,390
file will be saved into that folder.

35
00:02:59,250 --> 00:03:01,950
Boredstalker uploaded.

36
00:03:15,670 --> 00:03:18,460
So for this I will just write app dot one.

37
00:03:18,460 --> 00:03:18,970
Sick.

38
00:03:23,170 --> 00:03:24,520
Upload folder.

39
00:03:29,130 --> 00:03:29,670
That date.

40
00:03:31,960 --> 00:03:35,740
Well, but you can see that we have not created this folder anywhere over here.

41
00:03:35,740 --> 00:03:38,950
So I will just create a new directory that date.

42
00:03:40,090 --> 00:03:40,450
Okay.

43
00:03:40,450 --> 00:03:46,120
And over here I will just create another decade cycles okay.

44
00:03:46,120 --> 00:03:48,670
So now you can see that we have created the required directories.

45
00:03:52,990 --> 00:04:01,690
So now we will just create another function by the name generate frames, and the input to this function

46
00:04:01,690 --> 00:04:08,620
will be the input file path, whether it can be image image audio okay.

47
00:04:08,620 --> 00:04:09,130
So.

48
00:04:12,270 --> 00:04:14,430
Or it can be for live webcam feed.

49
00:04:14,430 --> 00:04:16,020
You can pass it over here.

50
00:04:17,760 --> 00:04:18,390
So.

51
00:04:21,810 --> 00:04:23,910
But within this right, you'll win an output.

52
00:04:23,910 --> 00:04:27,810
And from this object detection function which we have imported.

53
00:04:27,810 --> 00:04:31,560
So let's write object detection action.

54
00:04:33,090 --> 00:04:35,490
So now you can see this object detection function.

55
00:04:35,490 --> 00:04:41,490
Take only the input file as an input whether it can be image video.

56
00:04:42,210 --> 00:04:47,460
So the input file path will be passed uh to this function as input okay.

57
00:04:47,460 --> 00:04:49,140
So input file path.

58
00:04:57,410 --> 00:05:06,500
So and this function of basically yields I to image uh or current frame or then the frame rate in which

59
00:05:06,500 --> 00:05:09,080
the shape of the current frame and total number of iterations.

60
00:05:09,080 --> 00:05:14,480
So these are the four outputs I am zero frame.

61
00:05:47,640 --> 00:05:51,510
So now you can see that we have the encoded image over here.

62
00:05:53,630 --> 00:05:55,700
Is not there should be in code.

63
00:05:55,730 --> 00:05:55,940
Okay.

64
00:05:55,940 --> 00:05:59,180
So now you can see that, uh, we have the encoded image over here.

65
00:05:59,180 --> 00:06:05,210
So any flask application basically requires the encoded image, uh, to be converted into bytes and

66
00:06:05,210 --> 00:06:07,070
rendered into the HTML.

67
00:06:07,070 --> 00:06:08,030
So.

68
00:06:09,620 --> 00:06:11,960
To convert this encoded image to into bytes.

69
00:06:11,960 --> 00:06:15,230
We'll be using dot two bytes uh function.

70
00:06:15,260 --> 00:06:21,950
So what I will do over here is I will write frame is equal to buffer dot two bytes.

71
00:06:23,770 --> 00:06:25,060
So two bytes.

72
00:06:25,090 --> 00:06:25,720
Dot two bytes.

73
00:06:25,720 --> 00:06:27,880
Convert the encoded image into bytes.

74
00:06:29,940 --> 00:06:30,390
That.

75
00:06:32,700 --> 00:06:38,610
And using dot gain keyword like you can see over here we will display the individual frames.

76
00:06:38,760 --> 00:06:39,420
Okay.

77
00:06:50,880 --> 00:06:58,530
And, uh, we will loop through all the individual frames and, uh, go through all the individual frames

78
00:06:58,740 --> 00:07:05,430
and to convert the individual frames are into subsequent frames will use the content type.

79
00:07:05,670 --> 00:07:10,050
So we need to convert all these individual frames into subsequent frames okay.

80
00:07:13,800 --> 00:07:14,580
It's all.

81
00:07:21,010 --> 00:07:26,560
Right content type so that I can convert the individual frames into subsequent frames.

82
00:07:57,170 --> 00:07:58,820
Okay, so that's good.

83
00:07:58,820 --> 00:07:59,930
We have done good enough.

84
00:07:59,930 --> 00:08:02,150
So we have created a generate frame function.

85
00:08:02,150 --> 00:08:07,100
I'm not currently calculating the frame rate frame shape because I don't require this yet.

86
00:08:11,590 --> 00:08:15,730
Then I will just write app dot route so that I can create a URL.

87
00:08:23,210 --> 00:08:24,440
That you can just.

88
00:08:27,290 --> 00:08:28,370
Let's try it out.

89
00:08:28,370 --> 00:08:29,390
This as well.

90
00:08:44,500 --> 00:08:45,160
That films.

91
00:08:45,160 --> 00:08:48,730
And here we will be calling the generate frame function, which are created above.

92
00:09:03,950 --> 00:09:06,530
So currently I will just pause the video part.

93
00:09:06,530 --> 00:09:09,380
So I will just running video two dot mp4.

94
00:09:42,510 --> 00:09:44,040
Okay, so that's all.

95
00:09:44,040 --> 00:09:45,840
I don't see any error yet.

96
00:09:45,840 --> 00:09:48,330
So just right over here.

97
00:09:59,930 --> 00:10:03,770
And out run so that we can make some changes in the runtime.

98
00:10:03,770 --> 00:10:08,690
So I've just set debug is equal to true so that we can make changes in the runtime.

99
00:10:09,500 --> 00:10:13,790
So let's get started with this.

100
00:10:17,550 --> 00:10:21,120
So I will just open the terminal now and I will just write over here.

101
00:10:21,120 --> 00:10:21,900
Python.

102
00:10:22,800 --> 00:10:27,450
Ask app dot Pi, and let's see if there is an error so that we can fix this up.

103
00:10:38,750 --> 00:10:43,760
You can similarly pass an input image path over here or zero for the live webcam feed.

104
00:10:43,880 --> 00:10:45,080
Let's open this URL.

105
00:10:55,770 --> 00:11:00,240
But this will take some time before we have the results over here.

106
00:11:06,040 --> 00:11:09,220
The legislature bought seconds.

107
00:11:09,220 --> 00:11:14,410
I'm not going to pause the video so we can see how many time lag we get.

108
00:11:37,280 --> 00:11:39,710
So this will take a few more seconds.

109
00:11:39,710 --> 00:11:40,190
Get.

110
00:11:59,400 --> 00:12:07,320
Okay, so the processing on the frames have started, but why not just appearing over here?

111
00:12:19,910 --> 00:12:22,730
I can see over here the perception.

112
00:12:26,870 --> 00:12:28,520
I will be starting this.

113
00:12:42,090 --> 00:12:42,540
Oh, yeah.

114
00:12:42,540 --> 00:12:43,410
It's working now.

115
00:12:43,410 --> 00:12:43,800
Yeah.

116
00:12:44,310 --> 00:12:45,030
So that's great.

117
00:12:45,030 --> 00:12:49,260
So now you can see over here, uh, we have the URL over here.

118
00:12:49,260 --> 00:12:52,890
I've just passed this URL and this is the frame size which we are getting.

119
00:12:53,100 --> 00:13:00,150
Um, the width of this frame is 12, uh, 80 and the height is uh, 720, which you can find over here.

120
00:13:00,150 --> 00:13:03,720
And you can see that we are able to track different cars over here.

121
00:13:03,870 --> 00:13:07,860
Uh, I'm testing on CPU, so the processing is very, very slow.

122
00:13:07,860 --> 00:13:13,620
But, uh, if you have a good GPU and a processing will be very fast, like, you can see the car is

123
00:13:13,620 --> 00:13:18,990
moving, but the as the processing or frame rate is very low over here.

124
00:13:18,990 --> 00:13:22,980
So now you can see that we are able to to churn on this video.

125
00:13:22,980 --> 00:13:24,990
We have written different cars over here.

126
00:13:24,990 --> 00:13:25,890
This is a wrong detection.

127
00:13:25,890 --> 00:13:26,670
This is not a truck.

128
00:13:26,670 --> 00:13:28,950
And these are also false positive.

129
00:13:28,950 --> 00:13:31,350
Like these are the wrong detections okay.

130
00:13:31,350 --> 00:13:39,150
So in the same way uh you can pass uh like you don't need to close up this program simply, uh, we

131
00:13:39,150 --> 00:13:43,230
can also do object detection over an image like click or.

132
00:13:43,230 --> 00:13:43,440
Okay.

133
00:13:43,440 --> 00:13:44,400
So let's see.

134
00:13:47,130 --> 00:13:54,180
You just need to refresh this up and let's see if we are able to detect different objects in this image

135
00:13:54,180 --> 00:13:54,900
or not.

136
00:14:02,680 --> 00:14:07,360
It is, though, it's worth a few more seconds.

137
00:14:08,200 --> 00:14:11,110
Okay, so now here you can see we have our output image.

138
00:14:11,110 --> 00:14:14,230
We are able to detect this talk person this handbag.

139
00:14:14,440 --> 00:14:15,070
Okay.

140
00:14:15,070 --> 00:14:18,130
And let's test out on other image.

141
00:14:20,620 --> 00:14:21,370
Image.

142
00:14:22,420 --> 00:14:25,210
So let's try this out.

143
00:14:25,990 --> 00:14:26,140
Okay.

144
00:14:26,140 --> 00:14:28,270
So I will just click on refresh from here.

145
00:14:28,750 --> 00:14:32,770
And let's see if we are able to detect different objects in this image or not.

146
00:14:32,770 --> 00:14:40,540
Like you can see over here we are able to score a person dog and bag.

147
00:14:40,630 --> 00:14:40,900
So.

148
00:14:43,850 --> 00:14:50,150
The results are very good overall, but let's see if it works on this other image or not.

149
00:14:51,440 --> 00:14:55,370
So as I'm trying it on, CPU processing is very low.

150
00:14:55,370 --> 00:14:57,290
But you can see here we have the results.

151
00:14:57,290 --> 00:15:04,280
We are able to detect this bus, traffic lights, person bag, bag, bicycle, hand bag, all this stuff

152
00:15:04,280 --> 00:15:07,340
are being detected and you can see this person are very far away.

153
00:15:07,340 --> 00:15:08,150
Plus they are blurred.

154
00:15:08,150 --> 00:15:10,670
But we are also able to track these persons as well.

155
00:15:10,670 --> 00:15:12,890
And we have both the traffic lights as well.

156
00:15:13,190 --> 00:15:16,580
So you can try it out on some other video as well.

157
00:15:16,670 --> 00:15:21,560
Like uh video tool dot uh mp4.

158
00:15:22,160 --> 00:15:23,090
Let's try it out.

159
00:15:23,090 --> 00:15:23,420
This.

160
00:15:28,100 --> 00:15:31,100
Similarly, you can also test it on the live webcam feed as well.

161
00:15:31,130 --> 00:15:32,750
I'll show you as well.

162
00:15:34,790 --> 00:15:37,580
Are you going to try it out on the live webcam feed?

163
00:15:44,600 --> 00:15:50,600
So it's Wednesday full time and you can see here we have the frame size for this video.

164
00:15:50,630 --> 00:15:51,170
Okay.

165
00:15:52,310 --> 00:15:55,490
So let's see what is it.

166
00:15:55,550 --> 00:15:59,750
So now you can see that we are able to detect different persons in this video.

167
00:16:00,140 --> 00:16:00,650
Okay.

168
00:16:00,650 --> 00:16:03,170
Like you can see in the processing is very slow.

169
00:16:03,200 --> 00:16:06,380
I'm using CPU else everything is okay.

170
00:16:06,410 --> 00:16:10,100
So in this way you can see that we are doing object detection on the video.

171
00:16:10,100 --> 00:16:14,030
And if you want to do it on the live webcam feed, just change it to zero.

172
00:16:17,360 --> 00:16:18,980
And let's run this up now.

173
00:16:31,380 --> 00:16:33,060
So this will take some time.

174
00:16:44,230 --> 00:16:44,530
Okay.

175
00:16:45,580 --> 00:16:46,660
Okay.

176
00:16:46,960 --> 00:16:47,920
Let's see.

177
00:16:47,920 --> 00:16:49,030
How does it goes?

178
00:16:57,490 --> 00:17:01,270
Uh, this will take a few more seconds, uh, before we have the results.

179
00:17:14,280 --> 00:17:18,870
Okay, so now you can see our fear of the live webcam feed is on.

180
00:17:19,590 --> 00:17:20,160
Okay.

181
00:17:20,160 --> 00:17:22,830
And you can find me young.

182
00:17:25,440 --> 00:17:31,110
But okay, so now you can see over here, uh, we are able to track the person as well.

183
00:17:31,140 --> 00:17:31,830
Over here.

184
00:17:31,830 --> 00:17:33,210
This is a false positive.

185
00:17:33,210 --> 00:17:35,160
Like you can see this is not the chair.

186
00:17:35,250 --> 00:17:40,860
So in this way you can do object detection with the, like webcam feed over here as well.

187
00:17:42,050 --> 00:17:42,470
Okay.

188
00:17:42,470 --> 00:17:43,070
So.

189
00:17:46,710 --> 00:17:48,630
So this is how it goes.

190
00:17:48,960 --> 00:17:55,230
Okay, so in this tutorial we have seen that how we can integrate YOLO v9 with flask and how we can

191
00:17:55,230 --> 00:18:00,930
do object detection on image video and on the live webcam feed.

192
00:18:00,930 --> 00:18:02,910
And that's all for this tutorial.

193
00:18:02,910 --> 00:18:03,870
Thank you for watching.
