1
00:00:02,000 --> 00:00:06,000
Now we will see how we can integrate Yolo V8 with flask.

2
00:00:06,000 --> 00:00:11,000
So this is all the code which I have already written and explained you previously.

3
00:00:11,000 --> 00:00:16,000
But one change, which one change which I have made is that I have just created a function video detection

4
00:00:16,000 --> 00:00:19,000
and added all this code inside this function.

5
00:00:19,000 --> 00:00:20,000
Video detection.

6
00:00:20,000 --> 00:00:21,000
Okay.

7
00:00:21,000 --> 00:00:29,000
And in the end of this function or the output of this function is the output image or the frame with

8
00:00:29,000 --> 00:00:33,000
the bounding boxes around the detected object with labels and the confidence score.

9
00:00:33,000 --> 00:00:40,000
So this is that you can see here in the end we have the image or the current frame with output bounding

10
00:00:40,000 --> 00:00:46,000
or with output bounding boxes around detected object with the labels and the confidence score.

11
00:00:47,000 --> 00:00:51,000
So now, plus I have just created a file by the name plus app.py file.

12
00:00:51,000 --> 00:00:54,000
So let's start from the start.

13
00:00:54,000 --> 00:01:00,000
So as we are integrating with flask, so in the first step you need to make sure that you have installed

14
00:01:00,000 --> 00:01:01,000
class on your system.

15
00:01:01,000 --> 00:01:07,000
So if you have not installed flask on your system, just install it by just writing PIP install.

16
00:01:09,000 --> 00:01:12,000
Okay, so this will install flaws on your system because.

17
00:01:14,000 --> 00:01:16,000
We are creating a web app using flask.

18
00:01:16,000 --> 00:01:16,000
Okay.

19
00:01:16,000 --> 00:01:20,000
And we are just integrating your V8 with class to create a web.

20
00:01:22,000 --> 00:01:24,000
So as I've already installed the flaps.

21
00:01:24,000 --> 00:01:26,000
So you can see over here the requirements already satisfied.

22
00:01:26,000 --> 00:01:31,000
But you have if you haven't installed flask already, it will take some time to install.

23
00:01:31,000 --> 00:01:32,000
Okay.

24
00:01:32,000 --> 00:01:36,000
And then we are just importing from flask import flask render template.

25
00:01:36,000 --> 00:01:44,000
So why we need to import render template is that we just we need a render template to render our HTML

26
00:01:44,000 --> 00:01:44,000
file.

27
00:01:44,000 --> 00:01:46,000
But we are not using this currently over here.

28
00:01:46,000 --> 00:01:49,000
So you can just remove this from here.

29
00:01:49,000 --> 00:01:53,000
Like this session request json require response.

30
00:01:53,000 --> 00:01:58,000
You can remove this render dash template currently because we are not using it.

31
00:01:58,000 --> 00:02:03,000
Plus you can also use this session because we are not saving the video file but the session storage.

32
00:02:03,000 --> 00:02:04,000
We will do this later on.

33
00:02:05,000 --> 00:02:08,000
Thus you can see simply remove just one you as well.

34
00:02:09,000 --> 00:02:16,000
We use JSON file when we want to convert our output like frame rate or total number of detections into

35
00:02:16,000 --> 00:02:19,000
JSON format to display on our HTML page.

36
00:02:22,000 --> 00:02:23,000
And if.

37
00:02:23,000 --> 00:02:23,000
Go ahead.

38
00:02:23,000 --> 00:02:25,000
I am just importing cv2.

39
00:02:25,000 --> 00:02:30,000
So Cv2 library is required if you want to run the YOLO V8 model.

40
00:02:30,000 --> 00:02:35,000
So then I am just from the yolo v dash v video.py file from this file.

41
00:02:35,000 --> 00:02:38,000
I'm just importing the video dash detection function.

42
00:02:38,000 --> 00:02:42,000
So now you can see here in this yolo-video.py file.

43
00:02:42,000 --> 00:02:48,000
I have this video dash detection function so I'm just importing this function and here I'm just initializing

44
00:02:48,000 --> 00:02:48,000
class.

45
00:02:48,000 --> 00:02:53,000
You can see here and here I'm just creating a secret key which I have written by name.

46
00:02:53,000 --> 00:02:55,000
You can just change it as well.

47
00:02:55,000 --> 00:02:57,000
So now here we have the generate frames function.

48
00:02:57,000 --> 00:03:03,000
So generate frame function, take part of input video file and gives the output with bounding boxes

49
00:03:03,000 --> 00:03:04,000
around detected objects.

50
00:03:04,000 --> 00:03:08,000
So here we are just creating a function by the name generate frame.

51
00:03:08,000 --> 00:03:15,000
So this in the part dash x, we will just pass the input video file path and it will give us the output

52
00:03:15,000 --> 00:03:20,000
with bounding boxes, labels and the confidence score around each of the detected objects.

53
00:03:20,000 --> 00:03:21,000
Okay.

54
00:03:23,000 --> 00:03:26,000
So now here I'm just calling the video detection function.

55
00:03:26,000 --> 00:03:29,000
And so now you can see here, here we have the video detection function.

56
00:03:29,000 --> 00:03:35,000
And in the video detection path function, we just pass the path of the input video file.

57
00:03:35,000 --> 00:03:35,000
Okay.

58
00:03:35,000 --> 00:03:38,000
So here I'm just calling the video detection function.

59
00:03:38,000 --> 00:03:42,000
So the video detection function will give us the in the output.

60
00:03:42,000 --> 00:03:47,000
The detection function will give us the bounding boxes around the detected object with labels and the

61
00:03:47,000 --> 00:03:48,000
confidence bar.

62
00:03:48,000 --> 00:03:49,000
Okay.

63
00:03:49,000 --> 00:03:51,000
So as we are doing detection frame by frame.

64
00:03:51,000 --> 00:03:52,000
Okay.

65
00:03:52,000 --> 00:03:57,000
So now you can see here we are just encoding the detection.

66
00:03:57,000 --> 00:04:02,000
So basically any in-class application requires the encoded image to be converted into bytes.

67
00:04:02,000 --> 00:04:05,000
So we are just encoding the current frame of the video.

68
00:04:05,000 --> 00:04:10,000
So basically any flask application required the encoded image to be converted into bytes.

69
00:04:10,000 --> 00:04:11,000
So.

70
00:04:12,000 --> 00:04:18,000
So here you can see over here we are just converting the encoded image like we can see here or the encoded

71
00:04:18,000 --> 00:04:19,000
frame into bytes.

72
00:04:19,000 --> 00:04:21,000
You can see over here using dot two bytes.

73
00:04:21,000 --> 00:04:25,000
I'm just converting the encoded image or the frame into bytes.

74
00:04:25,000 --> 00:04:26,000
Okay.

75
00:04:26,000 --> 00:04:32,000
So now we will look over all the individual frames and display them as video.

76
00:04:32,000 --> 00:04:34,000
So now we will look each.

77
00:04:34,000 --> 00:04:37,000
So basically our video is divided into multiple frames.

78
00:04:37,000 --> 00:04:42,000
When we run object detection on a video, the complete video is divided into multiple frames and we

79
00:04:42,000 --> 00:04:45,000
do the detection on each of the frame one by one.

80
00:04:45,000 --> 00:04:45,000
Okay.

81
00:04:45,000 --> 00:04:51,000
So after doing detections on each of the frame, so you can see here, we will look over all in visual

82
00:04:51,000 --> 00:04:53,000
frame and display them in this video.

83
00:04:53,000 --> 00:04:58,000
So after doing detection on each of the frame one by one, now basically we want to display our output

84
00:04:58,000 --> 00:04:59,000
as a video.

85
00:04:59,000 --> 00:05:04,000
So when we want the individual frames to be replaced by subsequent frames, like in the form of video,

86
00:05:04,000 --> 00:05:07,000
the content type or mini type will be used.

87
00:05:07,000 --> 00:05:09,000
So now you can see here we are just using the content type.

88
00:05:09,000 --> 00:05:14,000
Plus we just want to replace the individual frames detection by the subsequent frames.

89
00:05:14,000 --> 00:05:15,000
Okay.

90
00:05:16,000 --> 00:05:17,000
And.

91
00:05:19,000 --> 00:05:24,000
So you can see over here, here we are just using the yield keyword, which you can see over here.

92
00:05:24,000 --> 00:05:32,000
So using get keyword, we will uh, uh, uh, after using keyword in the video detection function output,

93
00:05:32,000 --> 00:05:37,000
we will get the individual frames with bounding boxes around the detected object along with the label

94
00:05:37,000 --> 00:05:38,000
and the confidence score.

95
00:05:39,000 --> 00:05:45,000
Okay, so this is all so again, explaining the generating function in the generate frame function,

96
00:05:45,000 --> 00:05:48,000
we just pass the input path of our input video file.

97
00:05:49,000 --> 00:05:49,000
Okay.

98
00:05:49,000 --> 00:05:51,000
And here I'm just calling the video detection function.

99
00:05:51,000 --> 00:05:56,000
So video detection function will give us the output with bounding boxes around detected object.

100
00:05:56,000 --> 00:05:59,000
And here we are just encoding our frame.

101
00:05:59,000 --> 00:06:05,000
And so basically in uh, any classification required, the encoded in English to be converted into bytes.

102
00:06:05,000 --> 00:06:11,000
So now we can see over here we are just converting the encoded image into bytes using dot two bytes.

103
00:06:12,000 --> 00:06:17,000
And basically we will loop over all the individual frames and do the detection on each of the frames

104
00:06:17,000 --> 00:06:23,000
as one by one, and then we'll replace the individual frame by the subsequent frames using content type

105
00:06:23,000 --> 00:06:24,000
or mini type.

106
00:06:24,000 --> 00:06:29,000
Okay, so this is all and then I'm just calling this using apt route method.

107
00:06:29,000 --> 00:06:31,000
I'm just creating a dash video.

108
00:06:31,000 --> 00:06:35,000
So using apt route method, I'm just creating a dash video.

109
00:06:35,000 --> 00:06:41,000
So in the dash video I'm just creating, passing, generate frames calling this generate frame function

110
00:06:41,000 --> 00:06:42,000
in the.

111
00:06:45,000 --> 00:06:45,000
Response.

112
00:06:45,000 --> 00:06:48,000
I am just recalling the dash video URL.

113
00:06:48,000 --> 00:06:54,000
I've just calling the generate frame function and in the dash x I will just pass the path of my input

114
00:06:54,000 --> 00:06:55,000
video file.

115
00:06:55,000 --> 00:07:01,000
So just remove this and you can see over here, you can see that here I've just passed the path of my

116
00:07:01,000 --> 00:07:03,000
input video file.

117
00:07:03,000 --> 00:07:06,000
So currently I'm just in this folder of last tutorial.

118
00:07:07,000 --> 00:07:09,000
So I've just written dot dot.

119
00:07:09,000 --> 00:07:14,000
So just go out of this folder, get out of this folder and just go to the videos folder.

120
00:07:14,000 --> 00:07:19,000
And in the videos folder I have the bikes dot mp4, so I'm just going to the videos folder and here

121
00:07:19,000 --> 00:07:21,000
I have the bikes dot mp4.

122
00:07:21,000 --> 00:07:28,000
So as I already told you to, uh, when you want to the individual frames to be replaced by subsequent

123
00:07:28,000 --> 00:07:30,000
frames, we either use many type or content type.

124
00:07:30,000 --> 00:07:37,000
Okay, so here I'm just using mine type multipart to replace the individual frames by the subsequent

125
00:07:37,000 --> 00:07:37,000
frames.

126
00:07:37,000 --> 00:07:44,000
And here I've just passed the path of my input video file and just now run this flask app.py file and

127
00:07:44,000 --> 00:07:50,000
see if we are able to integrate flask with yolo V8 and how our results look like when we just call the

128
00:07:50,000 --> 00:07:51,000
url dash video.

129
00:07:52,000 --> 00:07:53,000
So just.

130
00:07:54,000 --> 00:07:55,000
Just need to go to the terminal.

131
00:07:56,000 --> 00:08:04,000
And if you just click over here and just click on Copy path and just write CD like want to set this

132
00:08:04,000 --> 00:08:05,000
path as our current directory.

133
00:08:06,000 --> 00:08:06,000
Okay.

134
00:08:06,000 --> 00:08:11,000
And just over here, copy path and just copy this absolute path.

135
00:08:11,000 --> 00:08:12,000
Okay?

136
00:08:12,000 --> 00:08:15,000
And just write CD and just add this path.

137
00:08:15,000 --> 00:08:19,000
Now just write Python and just run this flask app dot.

138
00:08:19,000 --> 00:08:22,000
Flask app.py.

139
00:08:22,000 --> 00:08:23,000
Just click on enter now.

140
00:08:26,000 --> 00:08:26,000
Okay.

141
00:08:26,000 --> 00:08:27,000
So.

142
00:08:29,000 --> 00:08:36,000
Now, basically we are integrating it with Flask and currently I'm just running on a video basically.

143
00:08:36,000 --> 00:08:38,000
So just click, click on this URL.

144
00:08:40,000 --> 00:08:42,000
So basically, this is not our URL.

145
00:08:42,000 --> 00:08:44,000
Basically, we have created a URL dash video.

146
00:08:44,000 --> 00:08:45,000
Okay.

147
00:08:45,000 --> 00:08:47,000
So we have not created a root page yet.

148
00:08:47,000 --> 00:08:49,000
We have just created a golden dash video.

149
00:08:49,000 --> 00:08:53,000
So just click over here, dash video and just click on Enter.

150
00:08:55,000 --> 00:09:00,000
So now you can see over here we are just doing the reductions on our input video which have passed.

151
00:09:01,000 --> 00:09:01,000
Okay.

152
00:09:01,000 --> 00:09:06,000
So now you can see that we have the bounding boxes around the detected object, like around the person.

153
00:09:06,000 --> 00:09:11,000
We have the bounding box and we have the label person and the confidence score around the bicycle.

154
00:09:11,000 --> 00:09:16,000
We have the bounding box and we have the label bicycle and the confidence score over here as well.

155
00:09:16,000 --> 00:09:21,000
And on the traffic light, we have the bounding box around the traffic light, we have the label and

156
00:09:21,000 --> 00:09:25,000
we have also have the confidence score over here as well.

157
00:09:25,000 --> 00:09:27,000
So the results look impressive.

158
00:09:27,000 --> 00:09:31,000
So now you can see over here we have integrated YOLO V8 with class.

159
00:09:31,000 --> 00:09:38,000
And now when we call, call this video, it do the detections on the input video which have passed over

160
00:09:38,000 --> 00:09:38,000
here.

161
00:09:38,000 --> 00:09:41,000
So this is the input video which have passed.

162
00:09:41,000 --> 00:09:43,000
And let me just show you this video.

163
00:09:43,000 --> 00:09:45,000
So if I just go to.

164
00:09:47,000 --> 00:09:48,000
My folder.

165
00:09:48,000 --> 00:09:50,000
YOLO V8 Crash course.

166
00:09:50,000 --> 00:09:53,000
Okay, so if I just go to video.

167
00:09:53,000 --> 00:09:57,000
So I'm just passing this video as my input.

168
00:09:57,000 --> 00:09:58,000
So.

169
00:09:58,000 --> 00:10:02,000
And here the detection is done on frame by frame.

170
00:10:02,000 --> 00:10:07,000
So now you can see that I'm just using this video, uh, to do the detections.

171
00:10:07,000 --> 00:10:08,000
Okay.

172
00:10:08,000 --> 00:10:14,000
And you can see over here, uh, I've just passed this video as my input video file in the flask app.py

173
00:10:14,000 --> 00:10:20,000
file, and we can see that we are able to detections uh, of bicycle person and in traffic light.

174
00:10:20,000 --> 00:10:21,000
So.

175
00:10:22,000 --> 00:10:28,000
You can pass any part of what you want over here and you can do the reductions on it as well.

176
00:10:28,000 --> 00:10:32,000
So now we have done reductions on a video.

177
00:10:32,000 --> 00:10:37,000
Now in the next video tutorial or in the next part, we will see how we can do reductions on a live

178
00:10:37,000 --> 00:10:38,000
webcam feed.

179
00:10:38,000 --> 00:10:45,000
So how we can create a live class so that we can do reductions on the live webcam feed.

180
00:10:45,000 --> 00:10:48,000
So let's discuss in the next part.

