1
00:00:03,000 --> 00:00:08,000
In this video tutorial, we will look at Multi-object tracking with Ultralytics YOLO.

2
00:00:09,000 --> 00:00:16,000
In object tracking, we assign a unique ID to each of the detected object, and then we track that detected

3
00:00:16,000 --> 00:00:19,000
object throughout the entire video frames.

4
00:00:19,000 --> 00:00:26,000
We will also plot the movement of detected object across multiple video frames by drawing the trails,

5
00:00:26,000 --> 00:00:31,000
which through which we can see what pattern the object is following.

6
00:00:31,000 --> 00:00:38,000
The applications of object tracking are limitless, from security and surveillance to real time sports

7
00:00:38,000 --> 00:00:39,000
analysis.

8
00:00:40,000 --> 00:00:47,000
In this tutorial for Object tracking for object detection, I will be using Ultralytics YOLO 11 model

9
00:00:47,000 --> 00:00:52,000
and for object tracking I will also use the Ultralytics package.

10
00:00:52,000 --> 00:00:59,000
Ultralytics package currently supports a two object tracking algorithms, one is Boardshort and addressed

11
00:00:59,000 --> 00:01:00,000
by Greg.

12
00:01:00,000 --> 00:01:07,000
So currently, uh, the politics package sports two object tracking algorithm, although there are other

13
00:01:07,000 --> 00:01:13,000
object tracking algorithms available as well, like Deepsort, sword and others as well.

14
00:01:13,000 --> 00:01:18,000
But currently the Ultralytics package, uh, supports two object tracking algorithm, which I told you

15
00:01:18,000 --> 00:01:20,000
one is called sort and other is by drag.

16
00:01:20,000 --> 00:01:26,000
So we will be using, uh, Ultralytics package to integrate object tracking with our object detection,

17
00:01:26,000 --> 00:01:27,000
uh, model.

18
00:01:27,000 --> 00:01:29,000
So let's get started with this.

19
00:01:29,000 --> 00:01:33,000
Uh, here you can see the demo is being played on your screen as well.

20
00:01:33,000 --> 00:01:39,000
In this demo, you can see that, uh, for each of the detected object, we have assigned a unique ID

21
00:01:39,000 --> 00:01:41,000
like one, three, nine, ten.

22
00:01:41,000 --> 00:01:43,000
And you can see that we are.

23
00:01:43,000 --> 00:01:50,000
So we are also, uh, checking the movement of the detected object by drawing the trace, which is telling

24
00:01:50,000 --> 00:01:54,000
us what path the object is being, uh, following.

25
00:01:54,000 --> 00:01:54,000
Okay.

26
00:01:54,000 --> 00:01:59,000
So this is a quick demo, and let's get started with this over here.

27
00:01:59,000 --> 00:02:07,000
So first of all, I will, uh, start writing down the code from scratch, and then I will show you

28
00:02:07,000 --> 00:02:11,000
how you can integrate object tracking with your object detection algorithm.

29
00:02:11,000 --> 00:02:17,000
So but before I go ahead, you can check this documentation by alternatives like how you can perform

30
00:02:17,000 --> 00:02:19,000
multi object tracking with Ultralytics YOLO.

31
00:02:19,000 --> 00:02:24,000
So we will be following this documentation uh in this complete tutorial.

32
00:02:24,000 --> 00:02:26,000
So you can also check out this documentation.

33
00:02:26,000 --> 00:02:31,000
And or you just need to search on Google by Multi Object Tracking with Ultralytics yolo.

34
00:02:31,000 --> 00:02:33,000
And you will just find the first link.

35
00:02:33,000 --> 00:02:37,000
And you can just click that link and you will be able to open this documentation.

36
00:02:37,000 --> 00:02:39,000
So let's start writing down the code.

37
00:02:40,000 --> 00:02:45,000
So over here you can see I have just created a project in PyCharm over here.

38
00:02:45,000 --> 00:02:48,000
And you can see I have multiple video files over here.

39
00:02:48,000 --> 00:02:53,000
And first of all I will just create a requirements.txt file.

40
00:03:01,000 --> 00:03:06,000
He had acquired the Ultralytics badge along with Ultralytics.

41
00:03:06,000 --> 00:03:12,000
Many other packages get installed as well, like OpenCV, Python, matplotlib, NumPy, Seaborn.

42
00:03:12,000 --> 00:03:14,000
So we will install.

43
00:03:19,000 --> 00:03:23,000
It install python r requirements dot txt.

44
00:03:25,000 --> 00:03:31,000
So now I'm just installing the latest package because in my requirements.txt file I have only mentioned

45
00:03:31,000 --> 00:03:32,000
the ultralytics package.

46
00:03:33,000 --> 00:03:35,000
R spellings are all for the requirements.

47
00:03:35,000 --> 00:03:36,000
That means.

48
00:03:53,000 --> 00:03:54,000
Let's run this.

49
00:03:54,000 --> 00:04:00,000
So if you have mentioned any other package in this requirements.txt file, this will also be get downloaded

50
00:04:00,000 --> 00:04:04,000
with the ultralytics package as well.

51
00:04:04,000 --> 00:04:09,000
So currently we only require ultralytics package along with ultralytics package like SciPy, torch,

52
00:04:09,000 --> 00:04:13,000
OpenCV, Python, NumPy and many other packages get installed as well.

53
00:04:13,000 --> 00:04:17,000
Like you can see matplotlib, OpenCV, Python over here.

54
00:04:17,000 --> 00:04:19,000
Okay so numpy.

55
00:04:20,000 --> 00:04:24,000
So you can see over here many other packages have been get installed pandas.

56
00:04:25,000 --> 00:04:30,000
So let's try to create a new.py file over here.

57
00:04:33,000 --> 00:04:35,000
So we'll write object.

58
00:04:38,000 --> 00:04:40,000
tracking.py.

59
00:04:44,000 --> 00:04:49,000
Or in the step number one we will import all the required.

60
00:04:51,000 --> 00:04:52,000
Libraries.

61
00:04:54,000 --> 00:04:56,000
So from Ultralytics.

62
00:04:58,000 --> 00:05:00,000
In port Yolo.

63
00:05:04,000 --> 00:05:08,000
We will load the YOLO in our model.

64
00:05:12,000 --> 00:05:18,000
So I will write model is equal to YOLO and we want the YOLO 11 nano model.

65
00:05:18,000 --> 00:05:20,000
Your 11 comes with five different models.

66
00:05:21,000 --> 00:05:27,000
YOLO 11 nano is the fastest, but it is the least accurate among other YOLO 11 models.

67
00:05:34,000 --> 00:05:37,000
The first one is tracking with it.

68
00:05:37,000 --> 00:05:39,000
All right.

69
00:05:40,000 --> 00:05:41,000
What sort?

70
00:05:43,000 --> 00:05:44,000
Of test.

71
00:05:44,000 --> 00:05:50,000
So if we just check out the documentation over here, uh, you will find that the default tracker is

72
00:05:50,000 --> 00:05:51,000
bot sort.

73
00:05:51,000 --> 00:05:51,000
Chart.

74
00:05:51,000 --> 00:05:55,000
Okay, so if you don't define that tracker over here like you right.

75
00:05:55,000 --> 00:06:00,000
Model or drag and don't define that tracker over here, let me just zoom in okay.

76
00:06:03,000 --> 00:06:03,000
Okay.

77
00:06:03,000 --> 00:06:09,000
And so if you right model or track but you don't define the tracker over here, it will use the default

78
00:06:09,000 --> 00:06:11,000
tracker which is what sort.

79
00:06:11,000 --> 00:06:16,000
So Ultralytics supports the following tracking algorithm about sort and by track.

80
00:06:16,000 --> 00:06:23,000
Uh so you can enable uh, any of these tracking algorithms like hidden sort or by track by, by passing

81
00:06:23,000 --> 00:06:27,000
the board sort dot yml file or by track dot yml file.

82
00:06:27,000 --> 00:06:33,000
So uh, by passing the arrangement yml configuration, you can activate any of the tracker.

83
00:06:33,000 --> 00:06:33,000
Okay.

84
00:06:35,000 --> 00:06:41,000
So if you want to check uh, the informations like uh, on the alternatives tracker base, like you

85
00:06:41,000 --> 00:06:44,000
can see it's post trackers, bot sort and by track.

86
00:06:44,000 --> 00:06:44,000
Okay.

87
00:06:46,000 --> 00:06:48,000
So let's move towards the code.

88
00:06:52,000 --> 00:06:54,000
Alright results model dot.

89
00:06:54,000 --> 00:06:58,000
So if I want to do object detection, I don't need to write anything.

90
00:06:58,000 --> 00:07:02,000
I just need to go over here and write the source in which I need to pass the video path.

91
00:07:02,000 --> 00:07:08,000
But if you want to add tracking, you just need to write track over here, and then you just need to

92
00:07:08,000 --> 00:07:13,000
define the source file like your input file over here.

93
00:07:16,000 --> 00:07:19,000
So I just need to go to the resources folder.

94
00:07:19,000 --> 00:07:21,000
Then I just need to go to the videos folder.

95
00:07:21,000 --> 00:07:27,000
And I can use video seven dot app.

96
00:07:31,000 --> 00:07:36,000
If I want to show this video I can write show is equal to true.

97
00:07:36,000 --> 00:07:41,000
And if you want to save the output video, uh, you can write save is equal to true.

98
00:07:41,000 --> 00:07:46,000
So shortly our packages will be get installed like it's doing indexing.

99
00:07:46,000 --> 00:07:48,000
So this will not take very much time.

100
00:07:48,000 --> 00:07:56,000
So let's wait for this to finish and then I will just write or implement this code.

101
00:07:56,000 --> 00:08:01,000
So now you can see currently we are using default tracker because I have not defined any tracker over

102
00:08:01,000 --> 00:08:02,000
here okay.

103
00:08:04,000 --> 00:08:07,000
So let's wait for the packages to finish.

104
00:08:12,000 --> 00:08:17,000
By now you can see that finally the packages package installation is being done.

105
00:08:17,000 --> 00:08:23,000
And now let's run this script over here okay, so the indexing is almost completed.

106
00:08:23,000 --> 00:08:25,000
Uh, let's wait for a few seconds.

107
00:08:26,000 --> 00:08:29,000
Uh, the indexing is being done, so this will not take very much time.

108
00:08:31,000 --> 00:08:33,000
Okay, let's run the object.

109
00:08:35,000 --> 00:08:40,000
So it takes around 5 to 6 minutes for the index package to get installed.

110
00:08:40,000 --> 00:08:44,000
Because the alternative is many other packages also get installed.

111
00:08:44,000 --> 00:08:46,000
So this takes some time okay.

112
00:08:46,000 --> 00:08:49,000
So But first of all, it will download the YOLO 11 nano model.

113
00:08:50,000 --> 00:08:51,000
It automatically downloads.

114
00:08:51,000 --> 00:08:58,000
You don't need to go to the GitHub repository and specifically download the YOLO 11 nano model.

115
00:08:58,000 --> 00:08:58,000
Okay?

116
00:09:15,000 --> 00:09:17,000
Okay, now you can see over here.

117
00:09:20,000 --> 00:09:24,000
Okay, so we are just getting issue no module named lab.

118
00:09:24,000 --> 00:09:24,000
Okay.

119
00:09:24,000 --> 00:09:26,000
So we can just write over here.

120
00:09:27,000 --> 00:09:30,000
Uh we also need to install the lab package as well.

121
00:09:30,000 --> 00:09:33,000
Um, actually it should include in their installation.

122
00:09:33,000 --> 00:09:36,000
Like you don't need to install it specifically.

123
00:09:40,000 --> 00:09:45,000
So now you can see I'm downloading installing the lab package over here.

124
00:09:45,000 --> 00:09:47,000
and you can see your 11 nano models being downloaded.

125
00:09:48,000 --> 00:09:49,000
So this.

126
00:09:49,000 --> 00:09:53,000
Installation will take two seconds more as well, so let's wait for it to get finished.

127
00:09:59,000 --> 00:10:01,000
Uh, we can ignore this.

128
00:10:01,000 --> 00:10:01,000
Uh.

129
00:10:06,000 --> 00:10:07,000
Uh, let me just check.

130
00:10:11,000 --> 00:10:13,000
Hopefully it should run now.

131
00:10:13,000 --> 00:10:15,000
And let's see how.

132
00:10:22,000 --> 00:10:24,000
It will perform an auto update over here.

133
00:10:34,000 --> 00:10:37,000
Okay, so here you can see we have the results.

134
00:10:37,000 --> 00:10:40,000
Now you can see that, uh, ID is equal to one.

135
00:10:40,000 --> 00:10:42,000
And here we are detecting the cars.

136
00:10:42,000 --> 00:10:43,000
So okay.

137
00:10:43,000 --> 00:10:49,000
but we are not able to assign the we are not able to do the reductions over here.

138
00:10:50,000 --> 00:10:51,000
Okay.

139
00:10:51,000 --> 00:10:55,000
So now you can see as the object comes here we are able to do the reductions.

140
00:10:55,000 --> 00:10:59,000
Now you can see that each of detected object is being assigned a unique ID.

141
00:10:59,000 --> 00:11:01,000
Now it looks pretty good.

142
00:11:01,000 --> 00:11:01,000
Yeah.

143
00:11:01,000 --> 00:11:06,000
So now you can see that each of the rejected object is being randomly assigned an ID.

144
00:11:06,000 --> 00:11:07,000
Okay.

145
00:11:07,000 --> 00:11:08,000
So if you use a.

146
00:11:08,000 --> 00:11:10,000
Currently I am using YOLO 11 nano model.

147
00:11:10,000 --> 00:11:17,000
But if you use uh, other models like YOLO 11 medium or your 11 x which have a high accuracy rate,

148
00:11:17,000 --> 00:11:19,000
so you will see that detection results will further improve.

149
00:11:19,000 --> 00:11:22,000
Currently I'm running it on my CPU machine.

150
00:11:22,000 --> 00:11:28,000
I don't have a GPU, so therefore I'm pressing YOLO 11 nano model because it is the fastest among YOLO

151
00:11:28,000 --> 00:11:30,000
11 model, but it is least accurate.

152
00:11:30,000 --> 00:11:37,000
Okay, so now you have over here you can see that we are able to detection and we are able to assign

153
00:11:37,000 --> 00:11:40,000
a unique ID to each of the detected object over here.

154
00:11:40,000 --> 00:11:41,000
Okay.

155
00:11:42,000 --> 00:11:49,000
So now you can see this is this object detection over here I am using 11 nano.

156
00:11:49,000 --> 00:11:52,000
So therefore there are some false positives over here as well.

157
00:11:52,000 --> 00:11:55,000
But this is what we do in object tracking.

158
00:11:55,000 --> 00:11:59,000
Like you can see we are assigning a unique ID to each of the detected object.

159
00:12:00,000 --> 00:12:00,000
Okay.

160
00:12:00,000 --> 00:12:07,000
And to stop this I will just click the pause button and it will stop okay.

161
00:12:07,000 --> 00:12:08,000
So.

162
00:12:11,000 --> 00:12:13,000
For next thing what we can do is.

163
00:12:15,000 --> 00:12:20,000
Now we will see how we can do tracking with by tracking okay.

164
00:12:26,000 --> 00:12:28,000
So we will just define.

165
00:12:30,000 --> 00:12:32,000
That is equal to model dot track.

166
00:12:32,000 --> 00:12:36,000
Over here force is equal to.

167
00:12:36,000 --> 00:12:38,000
Let's use some other video.

168
00:12:38,000 --> 00:12:41,000
I just need to go inside the resources folder.

169
00:12:41,000 --> 00:12:47,000
Then videos lets you create your eight dot board.

170
00:12:49,000 --> 00:12:56,000
I want to see the output and you can see over here, uh, our output is being saved over here for the

171
00:12:56,000 --> 00:12:58,000
previous, uh, run.

172
00:12:58,000 --> 00:12:59,000
Okay.

173
00:13:00,000 --> 00:13:04,000
So I want to save is equal to true.

174
00:13:08,000 --> 00:13:09,000
And we want to use.

175
00:13:12,000 --> 00:13:13,000
Byte pair dot.

176
00:13:13,000 --> 00:13:14,000
YML.

177
00:13:16,000 --> 00:13:22,000
And you like for the prediction in Yolo V8 model we have our different arguments.

178
00:13:22,000 --> 00:13:25,000
Similarly we have arguments for the tracking as well.

179
00:13:25,000 --> 00:13:29,000
Like we can set the constant ratio to 0.20.

180
00:13:29,000 --> 00:13:38,000
We can set the non-expression IOU to 0.5 so you can adjust these parameters.

181
00:13:39,000 --> 00:13:40,000
but we can make them too.

182
00:13:43,000 --> 00:13:45,000
So let's run this now.

183
00:13:46,000 --> 00:13:48,000
Okay, I made a mistake.

184
00:13:49,000 --> 00:13:51,000
I just need to comment this out.

185
00:14:08,000 --> 00:14:08,000
Over here.

186
00:14:08,000 --> 00:14:09,000
We have the output.

187
00:14:09,000 --> 00:14:14,000
Now, you can see over here, uh, we are able to detect the person over here in this video.

188
00:14:14,000 --> 00:14:22,000
And you can see that, uh, with each person, we have assigned a unique ID like seven, 6321.

189
00:14:22,000 --> 00:14:27,000
Like you can see, we are not able to detect these persons, but if you use, uh, other YOLO 11 models,

190
00:14:27,000 --> 00:14:29,000
currently I'm using 11 nano model.

191
00:14:29,000 --> 00:14:35,000
But if you use models, other YOLO 11 models which have a high accuracy rate, um, then it will be

192
00:14:35,000 --> 00:14:38,000
able to detect these persons over here as well.

193
00:14:38,000 --> 00:14:38,000
Okay.

194
00:14:38,000 --> 00:14:42,000
And but in this tutorial we are focusing on object tracking.

195
00:14:42,000 --> 00:14:43,000
Basically object tracking.

196
00:14:43,000 --> 00:14:46,000
We assign a unique ID to each of the detected object.

197
00:14:46,000 --> 00:14:47,000
Like you can see over here.

198
00:14:47,000 --> 00:14:50,000
We have assigned a unique ID and to each detected object.

199
00:14:50,000 --> 00:14:56,000
And then we can track that detected object throughout the entire video frames.

200
00:14:56,000 --> 00:14:57,000
Okay.

201
00:14:57,000 --> 00:14:59,000
So we are done with this.

202
00:15:00,000 --> 00:15:02,000
And that was pretty fine.

203
00:15:06,000 --> 00:15:06,000
Okay.

204
00:15:09,000 --> 00:15:13,000
So now first of all I will just comment all this out okay.

205
00:15:16,000 --> 00:15:19,000
So you can uncomment this and run this okay.

206
00:15:21,000 --> 00:15:30,000
So now I will just write a Python script using OpenCV, Python and YOLO 11 to run object tracking on

207
00:15:30,000 --> 00:15:31,000
video frames.

208
00:15:31,000 --> 00:15:35,000
Or you can also run on the live webcam feed as well.

209
00:15:35,000 --> 00:15:35,000
Okay.

210
00:15:38,000 --> 00:15:41,000
So let's add a separator.

211
00:15:43,000 --> 00:15:46,000
So we will write a Python script.

212
00:15:49,000 --> 00:15:53,000
Using OpenCV Python and.

213
00:15:59,000 --> 00:16:00,000
YOLO 11.

214
00:16:01,000 --> 00:16:10,000
Run object tracking on video frames.

215
00:16:10,000 --> 00:16:10,000
And.

216
00:16:15,000 --> 00:16:19,000
Okay so let's get started with this as well.

217
00:16:24,000 --> 00:16:29,000
So first of all will import all the required libraries.

218
00:16:31,000 --> 00:16:37,000
Import cv2 from I draw Netflix and thought YOLO.

219
00:16:40,000 --> 00:16:45,000
Then lower the YOLO 11 order right.

220
00:16:45,000 --> 00:16:52,000
Model Yolo Yolo 11 nano dot RT.

221
00:16:54,000 --> 00:17:04,000
Next we will create a video capture object like cv2 dot videocapture.

222
00:17:06,000 --> 00:17:10,000
We just need to go into the resources folder.

223
00:17:10,000 --> 00:17:16,000
Then we just need to go to the videos and we can use video seven.

224
00:17:16,000 --> 00:17:19,000
Or we can just use video five.

225
00:17:19,000 --> 00:17:21,000
Let's use some other video.

226
00:17:25,000 --> 00:17:36,000
Then we will go through very famous pipeline while True red form of frame cap dot read.

227
00:17:37,000 --> 00:17:44,000
So if we have able to read the video because that returns a boolean true, so it returns a that returns

228
00:17:44,000 --> 00:17:47,000
a boolean true that is able to read a video.

229
00:17:47,000 --> 00:17:48,000
Then.

230
00:17:52,000 --> 00:17:53,000
We will run.

231
00:17:56,000 --> 00:18:00,000
Event tracking on the video frames.

232
00:18:02,000 --> 00:18:03,000
We will write.

233
00:18:07,000 --> 00:18:11,000
Results is equal to model dot track.

234
00:18:14,000 --> 00:18:19,000
We have the input frame and we will set our argument assistant is equal to true.

235
00:18:23,000 --> 00:18:33,000
So this argument tells the tracker that it should expect a track from the previous frame or image in

236
00:18:33,000 --> 00:18:35,000
the current frame, so persistent is equal to true.

237
00:18:35,000 --> 00:18:40,000
Tells the tracker that it should expect tracks from the previous frame into the current frame.

238
00:18:40,000 --> 00:18:41,000
Okay.

239
00:18:46,000 --> 00:18:50,000
Well, next we will visualize the results on the frame.

240
00:18:55,000 --> 00:19:03,000
We have an updated frame is equal to results 0:00.

241
00:19:07,000 --> 00:19:10,000
Next we will display the annotated frame.

242
00:19:21,000 --> 00:19:24,000
We can write the name of the window as YOLO 11 tracking.

243
00:19:26,000 --> 00:19:32,000
So now in this window we will show short object tracking integrated with our object detection.

244
00:19:36,000 --> 00:19:37,000
All right.

245
00:19:37,000 --> 00:19:38,000
If it will not work.

246
00:19:38,000 --> 00:19:42,000
So we will add one millisecond delay between the consecutive frames.

247
00:19:43,000 --> 00:19:49,000
And if the users pass key, then the loop will break.

248
00:19:54,000 --> 00:19:56,000
We can add the command break the loop.

249
00:19:59,000 --> 00:20:02,000
If q key is pressed.

250
00:20:03,000 --> 00:20:04,000
Simple.

251
00:20:04,000 --> 00:20:10,000
And if it's unable to read the video frame, then it will break as well.

252
00:20:10,000 --> 00:20:16,000
And then it will release all the frames and we will destroy all the windows as well.

253
00:20:20,000 --> 00:20:23,000
So let's run this up now.

254
00:20:45,000 --> 00:20:49,000
So now over here, you can see that we are able to integrate object tracking.

255
00:20:49,000 --> 00:20:55,000
Like you can see that for each of the detected object, we are able to assign a unique ID like one with

256
00:20:55,000 --> 00:21:00,000
this person, six with this bicycle and eight with this bicycle.

257
00:21:00,000 --> 00:21:02,000
And the results look quite good.

258
00:21:02,000 --> 00:21:04,000
Like you can see with traffic lights.

259
00:21:04,000 --> 00:21:07,000
We are also able to assign a unique ID over here.

260
00:21:09,000 --> 00:21:12,000
Okay, so the results look quite promising to me.

261
00:21:13,000 --> 00:21:14,000
Okay.

262
00:21:16,000 --> 00:21:18,000
Yeah, the results look quite good.

263
00:21:18,000 --> 00:21:27,000
Like, we are able to assign a unique ID with each of the detected object, like 1715 Three 114.

264
00:21:27,000 --> 00:21:33,000
Okay, so if I press up, that loop will break that.

265
00:21:35,000 --> 00:21:44,000
So the next thing we can do is, um, now we'll see what, uh, path the object is following.

266
00:21:44,000 --> 00:21:48,000
So we'll draw the trail, or we can write another Python script over here.

267
00:21:54,000 --> 00:21:56,000
Object tracking trails.

268
00:22:03,000 --> 00:22:07,000
Obviously, plotting tracks over time.

269
00:22:12,000 --> 00:22:17,000
Or we will plot the movement of an object across multiple video frames.

270
00:22:21,000 --> 00:22:25,000
First of all, I will import all the required.

271
00:22:35,000 --> 00:22:36,000
Libraries.

272
00:22:53,000 --> 00:22:54,000
Are full.

273
00:22:54,000 --> 00:23:02,000
We will be saving the center point of each of the bounding box into our dictionary.

274
00:23:02,000 --> 00:23:06,000
And then using that center point, we will be drawing lines.

275
00:23:06,000 --> 00:23:06,000
Okay.

276
00:23:13,000 --> 00:23:19,000
So we will be saving the center point of the bounding box in each of the frame in our dictionary.

277
00:23:19,000 --> 00:23:21,000
And using that center point.

278
00:23:21,000 --> 00:23:22,000
Then we will draw the lines.

279
00:23:39,000 --> 00:23:41,000
So now we load the YOLO 11 model.

280
00:23:41,000 --> 00:23:45,000
Then we will create the video capture check.

281
00:23:53,000 --> 00:23:55,000
We just need to go inside the resources.

282
00:23:55,000 --> 00:23:57,000
Then we just need to go to the videos.

283
00:23:57,000 --> 00:24:00,000
And then we can use video five dot mp4.

284
00:24:02,000 --> 00:24:07,000
So we will store that track history into a dictionary.

285
00:24:24,000 --> 00:24:28,000
Then we will go through the video frames.

286
00:24:33,000 --> 00:24:34,000
Okay.

287
00:24:34,000 --> 00:24:35,000
App dot frame.

288
00:24:35,000 --> 00:24:38,000
So if we are able to read the video then.

289
00:24:47,000 --> 00:24:49,000
We'll run your 11.

290
00:24:53,000 --> 00:24:55,000
Tracking frame.

291
00:25:00,000 --> 00:25:02,000
Like model dot track.

292
00:25:03,000 --> 00:25:05,000
Here we have the source.

293
00:25:08,000 --> 00:25:09,000
Which is frame.

294
00:25:22,000 --> 00:25:29,000
Now we need to get the bounding box coordinates and the track IDs.

295
00:25:34,000 --> 00:25:35,000
Blind box.

296
00:25:35,000 --> 00:25:43,000
This is equal to because this will contain the bounding box coordinates for all objects in the frame.

297
00:25:43,000 --> 00:25:45,000
And then we'll loop through this so we can write.

298
00:25:46,000 --> 00:25:47,000
Result zero.

299
00:25:55,000 --> 00:25:56,000
New requirements.

300
00:25:56,000 --> 00:25:57,000
S center coordinate.

301
00:26:04,000 --> 00:26:06,000
Then we will also require the track ID.

302
00:26:06,000 --> 00:26:09,000
So we'll get the track IDs for all the objects in the frame.

303
00:26:33,000 --> 00:26:41,000
So similarly, in the previous.py file, we'll write the results on the frame as well.

304
00:26:44,000 --> 00:26:46,000
And I annotate the frame.

305
00:26:59,000 --> 00:27:03,000
So I can display the annotated frame as well.

306
00:27:19,000 --> 00:27:22,000
So then we can write if cv2 dot wait.

307
00:27:22,000 --> 00:27:23,000
Key one.

308
00:27:23,000 --> 00:27:32,000
There is a one millisecond delay between the consecutive frames and if the user press the W key.

309
00:27:39,000 --> 00:27:41,000
I missed one thing over here.

310
00:27:45,000 --> 00:27:47,000
Then the loop will break.

311
00:27:53,000 --> 00:27:59,000
So now I will release on the frame and destroy all the windows as well.

312
00:27:59,000 --> 00:28:02,000
So let me just run this.

313
00:28:18,000 --> 00:28:23,000
Now, currently you can see that we are able to implement object tracking, but we are not able to draw

314
00:28:23,000 --> 00:28:24,000
the tracks.

315
00:28:24,000 --> 00:28:26,000
We show the path the object is following.

316
00:28:27,000 --> 00:28:29,000
So I just press the W key.

317
00:28:29,000 --> 00:28:30,000
It will close.

318
00:28:30,000 --> 00:28:33,000
So we need to plot the tracks.

319
00:28:34,000 --> 00:28:37,000
For this I will write the code over here.

320
00:28:39,000 --> 00:28:42,000
So now I will loop through the center coordinates and the track IDs.

321
00:28:42,000 --> 00:28:52,000
So I will just write box format track ID and say here we have the boxes.

322
00:28:52,000 --> 00:28:53,000
So I drag.

323
00:28:55,000 --> 00:28:55,000
ID.

324
00:29:08,000 --> 00:29:12,000
Over here we have created a default dictionary but in the variable track history.

325
00:29:12,000 --> 00:29:14,000
Now it's time to use this.

326
00:29:20,000 --> 00:29:26,000
And this track ID, we have the object IDs for all the objects in the frame.

327
00:29:32,000 --> 00:29:38,000
I submit that each track ID will save the center point of the bounding box, and we will then connect

328
00:29:38,000 --> 00:29:41,000
the center point of the bounding box for all the frames.

329
00:29:41,000 --> 00:29:46,000
And then we will draw the lines which tell us the path the object is following.

330
00:30:17,000 --> 00:30:23,000
So we need to obtain that points or center points for the 30 frames.

331
00:30:23,000 --> 00:30:23,000
Okay.

332
00:30:24,000 --> 00:30:26,000
So we write the ten track.

333
00:30:29,000 --> 00:30:29,000
30.

334
00:30:30,000 --> 00:30:34,000
So we will retain the center points for the 30 frames.

335
00:30:34,000 --> 00:30:41,000
So if you increase this value to 60 or 90 uh the the tracking trail line will increase.

336
00:30:41,000 --> 00:30:41,000
Okay.

337
00:30:41,000 --> 00:30:43,000
I will just show you as well.

338
00:30:52,000 --> 00:30:54,000
Now don't draw that tracking lines.

339
00:31:18,000 --> 00:31:23,000
Or using Siri to dot polling lines will draw the trails or the lines.

340
00:31:30,000 --> 00:31:32,000
Here we have the information or the center points.

341
00:31:43,000 --> 00:31:46,000
And the thickness will be ten.

342
00:31:46,000 --> 00:31:50,000
Okay, so that works pretty fine.

343
00:31:50,000 --> 00:31:51,000
Let's run this up.

344
00:31:51,000 --> 00:31:55,000
Now, uh, we can just use video.

345
00:31:56,000 --> 00:31:59,000
Uh, okay.

346
00:32:02,000 --> 00:32:06,000
So let's see how does it works.

347
00:32:09,000 --> 00:32:14,000
The color of these lines will be a white because we have just set the color to white.

348
00:32:14,000 --> 00:32:17,000
You can just change the color to any other color as well.

349
00:32:18,000 --> 00:32:23,000
Okay, so now you can see in the white we have the trails over here.

350
00:32:23,000 --> 00:32:26,000
So we chose the path the object is following.

351
00:32:26,000 --> 00:32:27,000
Okay.

352
00:32:28,000 --> 00:32:32,000
So now you can see over here we have the trails over here.

353
00:32:33,000 --> 00:32:38,000
Uh so let me just show you with other video.

354
00:32:39,000 --> 00:32:39,000
Video.

355
00:32:39,000 --> 00:32:45,000
So and we can just change the color to yellow.

356
00:32:49,000 --> 00:32:50,000
Let's run this now.

357
00:33:05,000 --> 00:33:06,000
Okay.

358
00:33:06,000 --> 00:33:08,000
So here we got the error call.

359
00:33:09,000 --> 00:33:09,000
Yeah.

360
00:33:16,000 --> 00:33:18,000
So how we can deal with this?

361
00:33:20,000 --> 00:33:21,000
We can write.

362
00:33:24,000 --> 00:33:26,000
XYZ0.

363
00:33:28,000 --> 00:33:30,000
But not id.

364
00:33:34,000 --> 00:33:38,000
Is not null.

365
00:33:51,000 --> 00:33:52,000
Okay.

366
00:33:53,000 --> 00:33:56,000
So now hopefully this will work out.

367
00:34:02,000 --> 00:34:03,000
So let's see.

368
00:34:12,000 --> 00:34:17,000
Now over here you can see that we are drawing the trails with a blue color over here.

369
00:34:17,000 --> 00:34:20,000
Okay, okay.

370
00:34:28,000 --> 00:34:34,000
Okay, so now you can see that these trails are telling us the pattern the object is following.

371
00:34:39,000 --> 00:34:39,000
Okay.

372
00:34:39,000 --> 00:34:45,000
So now you can see over here we are drawing the trails over here as well.

373
00:34:52,000 --> 00:34:54,000
So if I just press the W key this will close.

374
00:34:54,000 --> 00:34:59,000
And if I just write 90 over here let me show you what that does.

375
00:34:59,000 --> 00:34:59,000
It makes.

376
00:35:19,000 --> 00:35:24,000
So if I just write 90 over here, the length of these trails when further increase.

377
00:35:25,000 --> 00:35:25,000
Okay.

378
00:35:25,000 --> 00:35:32,000
So now you can see that like basically this is telling the path uh, the object is being following.

379
00:35:32,000 --> 00:35:38,000
Now you can see that the length has how much increased okay.

380
00:35:41,000 --> 00:35:43,000
So this is uh, quite makes impact.

381
00:35:44,000 --> 00:35:46,000
But 30 is the ideal value.

382
00:35:46,000 --> 00:35:46,000
Okay.

383
00:35:46,000 --> 00:35:52,000
So now we have seen that how we can plot the movement of object, how we can integrate object tracking.

384
00:35:52,000 --> 00:35:54,000
Now we will implement multi threading.

385
00:35:54,000 --> 00:35:56,000
Multi threaded tracking.

386
00:35:56,000 --> 00:36:02,000
So multi threaded tracking provides us the capability to run object tracking on multiple video streams

387
00:36:02,000 --> 00:36:06,000
or multiple live cam webcam feeds as well.

388
00:36:06,000 --> 00:36:09,000
Okay, so we can create another.py file.

389
00:36:23,000 --> 00:36:26,000
For multi threaded.

390
00:36:29,000 --> 00:36:31,000
Tracking provides.

391
00:36:34,000 --> 00:36:34,000
The.

392
00:36:37,000 --> 00:36:47,000
Capability to run check tracking on multiple video frames.

393
00:36:47,000 --> 00:36:56,000
Okay so first we will import all the required libraries.

394
00:37:03,000 --> 00:37:04,000
Import trading.

395
00:37:06,000 --> 00:37:11,000
Import cv2 from Ultra LaTeX.

396
00:37:12,000 --> 00:37:13,000
Import your.

397
00:37:16,000 --> 00:37:23,000
So next we need to define model names like what different models we use need to use in the multiple

398
00:37:23,000 --> 00:37:29,000
video streams and video sources.

399
00:37:29,000 --> 00:37:32,000
You can also define the webcam sources as well.

400
00:37:39,000 --> 00:37:48,000
We had windows in M1 nano model, and we will also use your 11 nano segmentation model as well.

401
00:37:53,000 --> 00:38:02,000
So we have sources equal to just need to go inside the resources, then there will need to go to the

402
00:38:02,000 --> 00:38:06,000
videos and first we'll run video seven dot mp4.

403
00:38:06,000 --> 00:38:09,000
Then we have sources.

404
00:38:12,000 --> 00:38:18,000
Videos video eight dot mp4 okay.

405
00:38:23,000 --> 00:38:27,000
So now we will run YOLO 11 tracker in its own track for concurrent processing.

406
00:38:27,000 --> 00:38:29,000
So we'll create a function.

407
00:38:32,000 --> 00:38:32,000
Okay.

408
00:38:34,000 --> 00:38:43,000
Run tracker that we just need to pass the model name and the file name in the input.

409
00:38:47,000 --> 00:38:49,000
So we'll run YOLO 11 tracker in its.

410
00:38:52,000 --> 00:38:53,000
Own thread.

411
00:38:55,000 --> 00:38:57,000
For concurrent processing.

412
00:39:10,000 --> 00:39:12,000
So we'll pass the model name to the.

413
00:39:12,000 --> 00:39:13,000
Over here.

414
00:39:15,000 --> 00:39:21,000
Then we'll write results model dot back because we need to implement bracket.

415
00:39:22,000 --> 00:39:25,000
Then in the source over here we have the file name.

416
00:39:30,000 --> 00:39:32,000
We need to save the output video.

417
00:39:36,000 --> 00:39:40,000
Then we need in the documentation they have set stream is equal to true.

418
00:39:40,000 --> 00:39:43,000
But this doesn't show the output video.

419
00:39:43,000 --> 00:39:44,000
So we just need to write.

420
00:39:44,000 --> 00:39:46,000
Show is equal to true.

421
00:39:48,000 --> 00:39:50,000
Then we will loop through the results.

422
00:39:57,000 --> 00:40:01,000
Now create and start tracker thread.

423
00:40:07,000 --> 00:40:11,000
I will now create and start tracker threads using a for loop.

424
00:40:35,000 --> 00:40:38,000
For now I will loop through the video files and the model names.

425
00:40:58,000 --> 00:41:00,000
So the arguments will be.

426
00:41:04,000 --> 00:41:06,000
Modern name and the video file.

427
00:41:27,000 --> 00:41:32,000
So now we will run YOLO tracker in its own thread for concurrent processing.

428
00:41:32,000 --> 00:41:34,000
I will show you in the output how this works.

429
00:41:39,000 --> 00:41:41,000
Let's start this up now.

430
00:41:45,000 --> 00:41:52,000
Now before it completes for example, if any video completes, it will wait for all the tracker threads

431
00:41:52,000 --> 00:41:53,000
to finish.

432
00:42:15,000 --> 00:42:19,000
I will clean up and close all video files.

433
00:42:22,000 --> 00:42:24,000
So now it's clean up and close all windows.

434
00:42:24,000 --> 00:42:27,000
So we write cv2 dot destroy all windows.

435
00:42:27,000 --> 00:42:29,000
So this is how it works.

436
00:42:30,000 --> 00:42:32,000
And let's run this and see if it works.

437
00:42:44,000 --> 00:42:47,000
So we have 11 nano model but we don't have the segmentation model.

438
00:42:47,000 --> 00:42:48,000
So it's downloading.

439
00:42:49,000 --> 00:42:50,000
And let's.

440
00:42:52,000 --> 00:43:00,000
So this is our first video and here is our second video.

441
00:43:00,000 --> 00:43:00,000
Okay.

442
00:43:02,000 --> 00:43:09,000
So you can see over here we are able to implement multithreading.

443
00:43:11,000 --> 00:43:16,000
So using multithreading it provides us the capability to run object tracking on multiple video streams

444
00:43:16,000 --> 00:43:18,000
like you can see over here.

445
00:43:18,000 --> 00:43:22,000
On one side I am implementing object tracking with the segmentation model.

446
00:43:22,000 --> 00:43:29,000
And on the other side on the left hand side I am implementing object tracking with the object detection

447
00:43:29,000 --> 00:43:30,000
model.

448
00:43:30,000 --> 00:43:30,000
Okay.

449
00:43:30,000 --> 00:43:33,000
So now you can see that the results look pretty good.

450
00:43:33,000 --> 00:43:36,000
Like you can clearly see over here.

451
00:43:36,000 --> 00:43:40,000
Uh, the results look quite promising to me as well.

452
00:43:40,000 --> 00:43:41,000
Okay.

453
00:43:41,000 --> 00:43:47,000
So now uh, using a multithreading we are able to implement object tracking.

454
00:43:48,000 --> 00:43:51,000
So that is results look quite promising.

455
00:43:51,000 --> 00:43:56,000
So now we are able to implement object tracking on multiple video streams as well.

456
00:44:03,000 --> 00:44:09,000
So multi threaded tracking provides us the capability to run object tracking on multiple video streams

457
00:44:09,000 --> 00:44:11,000
which you can clearly see over here.

458
00:44:11,000 --> 00:44:14,000
And over here you can see that we are doing concurrent processing.

459
00:44:14,000 --> 00:44:20,000
We are running video seven and video eight are in parallel over here.

460
00:44:20,000 --> 00:44:25,000
You can also run on live webcam feeds like if you have multiple feeds coming, you can run it on multiple

461
00:44:25,000 --> 00:44:26,000
feeds as well.

462
00:44:26,000 --> 00:44:29,000
And you can see this is what we call concurrent processing.

463
00:44:29,000 --> 00:44:35,000
Like we are running video seven and video eight concurrently at the same time.

464
00:44:35,000 --> 00:44:38,000
Okay, okay.

465
00:44:38,000 --> 00:44:39,000
So this is how it works.

466
00:44:39,000 --> 00:44:42,000
And using multiple threading tracking.

467
00:44:43,000 --> 00:44:46,000
Uh, we have run object tracking on multiple video streams.

468
00:44:46,000 --> 00:44:47,000
That's all from this tutorial.

469
00:44:47,000 --> 00:44:49,000
Thank you for watching.

