1
00:00:02,000 --> 00:00:03,000
In the part one.

2
00:00:03,000 --> 00:00:05,000
We have implemented the vehicle counting.

3
00:00:05,000 --> 00:00:11,000
In the second part, I will add the speed estimation port in the that script as well.

4
00:00:11,000 --> 00:00:16,000
So first of all, we will write declare a variable speed line queue.

5
00:00:16,000 --> 00:00:23,000
So when we have the estimated speed, we will append the speed into this dictionary so that we can further

6
00:00:23,000 --> 00:00:24,000
estimate the speed of the vehicle.

7
00:00:24,000 --> 00:00:29,000
So now we need to create a function by the name estimate speed over here.

8
00:00:29,000 --> 00:00:31,000
Define estimate speed.

9
00:00:32,000 --> 00:00:33,000
And it.

10
00:00:35,000 --> 00:00:36,000
Report it will take.

11
00:00:38,000 --> 00:00:42,000
Reverse location one and location two.

12
00:00:42,000 --> 00:00:44,000
Okay, so what are these?

13
00:00:44,000 --> 00:00:45,000
Let me tell you.

14
00:00:46,000 --> 00:00:51,000
So the input it will take these two variables the the first and the second point of the trail.

15
00:00:51,000 --> 00:00:58,000
So what does it mean that it will take this first point of the trail and the second point of this trail?

16
00:00:58,000 --> 00:00:59,000
Okay.

17
00:00:59,000 --> 00:01:05,000
Basically, the trails are created when we basically you can say that when we append the center coordinates

18
00:01:05,000 --> 00:01:07,000
of the bounding box in each frame.

19
00:01:07,000 --> 00:01:09,000
So in this way, the trails are created.

20
00:01:09,000 --> 00:01:14,000
So we are taking the first coordinate and the second coordinate of this trails.

21
00:01:15,000 --> 00:01:19,000
Okay, so here we are in location one and location two and then click on Enter.

22
00:01:19,000 --> 00:01:23,000
So first we need to find the distance in pixels.

23
00:01:23,000 --> 00:01:27,000
So what is distance in pixels or how it is calculated?

24
00:01:27,000 --> 00:01:32,000
So to calculate the distance in pixels, we will use a klodian formula.

25
00:01:32,000 --> 00:01:35,000
So this write a distance formula.

26
00:01:35,000 --> 00:01:43,000
So when I go to the images over here, so this is the formula we have for Euclidean distance formula,

27
00:01:43,000 --> 00:01:49,000
which is x two minus x one over square plus y two minus y one over square.

28
00:01:49,000 --> 00:01:52,000
So I will just write this formula over here.

29
00:01:52,000 --> 00:01:56,000
So first we need to define the square root mat, dot, square root.

30
00:01:56,000 --> 00:01:59,000
Then we need to have the power.

31
00:01:59,000 --> 00:02:02,000
So to do this we will write mat.

32
00:02:05,000 --> 00:02:06,000
Okay.

33
00:02:06,000 --> 00:02:09,000
What I'm doing now Math Dot P.O.W..

34
00:02:09,000 --> 00:02:16,000
So now I will write allocation to basically it's x two minus x one.

35
00:02:16,000 --> 00:02:17,000
So it's zero.

36
00:02:18,000 --> 00:02:19,000
Then I will write.

37
00:02:21,000 --> 00:02:22,000
Just give me a minute to set this.

38
00:02:24,000 --> 00:02:26,000
Then in the next step, I will write.

39
00:02:28,000 --> 00:02:30,000
Minus location.

40
00:02:31,000 --> 00:02:33,000
One zero.

41
00:02:35,000 --> 00:02:35,000
Next.

42
00:02:35,000 --> 00:02:37,000
What I will do is.

43
00:02:38,000 --> 00:02:40,000
So here we need to define the power of two.

44
00:02:40,000 --> 00:02:42,000
So it means power.

45
00:02:42,000 --> 00:02:46,000
So as you can see that here we have the power of two.

46
00:02:46,000 --> 00:02:47,000
So here I have written two.

47
00:02:47,000 --> 00:02:51,000
So in that case, if there is power of 3 or 4, I will just write over here.

48
00:02:51,000 --> 00:02:53,000
So just come over here.

49
00:02:53,000 --> 00:02:54,000
Then I will write.

50
00:02:56,000 --> 00:02:58,000
Nice net dollar.

51
00:02:58,000 --> 00:03:02,000
IOW, then it is location.

52
00:03:03,000 --> 00:03:06,000
Rule one minus.

53
00:03:07,000 --> 00:03:08,000
Vacation.

54
00:03:09,000 --> 00:03:10,000
One.

55
00:03:10,000 --> 00:03:11,000
One.

56
00:03:13,000 --> 00:03:13,000
Two.

57
00:03:14,000 --> 00:03:15,000
So here I've.

58
00:03:16,000 --> 00:03:21,000
Here I've written the distance in pixels in the form of occlusion distance formula.

59
00:03:21,000 --> 00:03:24,000
So next we need to calculate the pixel parameters.

60
00:03:24,000 --> 00:03:30,000
So here I will take the pixel about pixel fixed value of pixel per meter.

61
00:03:30,000 --> 00:03:37,000
But if you want to get more adequate results or more better vision, you can make it dynamically.

62
00:03:37,000 --> 00:03:38,000
Bowser.

63
00:03:38,000 --> 00:03:38,000
Trembler

64
00:03:41,000 --> 00:03:43,000
Westminster parameter.

65
00:03:43,000 --> 00:03:46,000
But here the x value of pixel per as in here.

66
00:03:46,000 --> 00:03:50,000
Then we will calculate the distance in meters, which will be.

67
00:03:52,000 --> 00:03:54,000
Distance in pixels.

68
00:03:55,000 --> 00:03:56,000
Distance in pixels.

69
00:03:56,000 --> 00:03:59,000
Multiply by sorry.

70
00:03:59,000 --> 00:04:01,000
Distance in pixels divided by pixel.

71
00:04:01,000 --> 00:04:02,000
Parameter.

72
00:04:02,000 --> 00:04:05,000
Then I will declare a time constant.

73
00:04:05,000 --> 00:04:07,000
So this is basically.

74
00:04:08,000 --> 00:04:14,000
You see that basically fixed value which will contain 15 cross 3.6.

75
00:04:14,000 --> 00:04:15,000
So we can.

76
00:04:18,000 --> 00:04:22,000
The more elevated result you can get.

77
00:04:24,000 --> 00:04:28,000
3.6 is also the constraint which we can adjust as one over.

78
00:04:28,000 --> 00:04:30,000
So now we will calculate speed.

79
00:04:30,000 --> 00:04:37,000
So let me share what is the formula speed eight point.

80
00:04:40,000 --> 00:04:42,000
So speed is equal to distance over time.

81
00:04:43,000 --> 00:04:43,000
Okay.

82
00:04:43,000 --> 00:04:50,000
So what I will do over here is the distance in meters.

83
00:04:51,000 --> 00:04:52,000
It's overtime.

84
00:04:52,000 --> 00:04:56,000
But here what we're doing, we are getting time constraint.

85
00:04:58,000 --> 00:05:01,000
So we have basically frequency in this case.

86
00:05:01,000 --> 00:05:01,000
So.

87
00:05:02,000 --> 00:05:04,000
Frequency is equal to one by T.

88
00:05:05,000 --> 00:05:05,000
Okay.

89
00:05:05,000 --> 00:05:10,000
So we will just multiply the under time constraint because time constraint in the form of fancy.

90
00:05:10,000 --> 00:05:14,000
So we are just multiplying that time constraint with the distance.

91
00:05:14,000 --> 00:05:14,000
Okay.

92
00:05:14,000 --> 00:05:21,000
If we have a time then we should divide it so it will return here and speed.

93
00:05:21,000 --> 00:05:21,000
Okay.

94
00:05:22,000 --> 00:05:25,000
So we have created a function for the speed estimation.

95
00:05:25,000 --> 00:05:33,000
The next thing we need to do is we need to add this call, this function where we need to call this

96
00:05:33,000 --> 00:05:34,000
function.

97
00:05:34,000 --> 00:05:38,000
Just checking it because I might forgot something.

98
00:05:38,000 --> 00:05:41,000
Okay, so we now need to call this function over here.

99
00:05:41,000 --> 00:05:48,000
I will write object speed is equal to estimate speed, which are the function which I have created.

100
00:05:48,000 --> 00:05:51,000
Then I will pass that vehicle ID.

101
00:05:52,000 --> 00:05:54,000
One then will pass the data.

102
00:05:54,000 --> 00:05:56,000
ID zero as well.

103
00:05:56,000 --> 00:05:57,000
Over here.

104
00:05:57,000 --> 00:05:59,000
IDs zero.

105
00:05:59,000 --> 00:06:04,000
And then I will press enter and bound my speed with the.

106
00:06:04,000 --> 00:06:08,000
I will just append these values into this.

107
00:06:10,000 --> 00:06:13,000
Object be okay?

108
00:06:14,000 --> 00:06:16,000
So I have done this.

109
00:06:16,000 --> 00:06:22,000
So here we are appending the object speed values into this dictionary so that we can get where the speed

110
00:06:22,000 --> 00:06:24,000
of each of the detected object.

111
00:06:25,000 --> 00:06:27,000
Okay, so I think that's enough.

112
00:06:27,000 --> 00:06:29,000
Plus we need to make that change.

113
00:06:29,000 --> 00:06:35,000
One thing over here because we need to display this right here.

114
00:06:37,000 --> 00:06:42,000
I, if we get the speed in labor, is equal to labor.

115
00:06:43,000 --> 00:06:43,000
Thus.

116
00:06:45,000 --> 00:06:48,000
Thus we just had the space over here.

117
00:06:50,000 --> 00:06:56,000
Basically, we are we are adding the speed value with the we can say that with the label.

118
00:06:56,000 --> 00:06:57,000
So we are.

119
00:06:57,000 --> 00:07:04,000
So basically, let me show you the speed value will appear with this label like here with this label

120
00:07:04,000 --> 00:07:06,000
in the with this label over here.

121
00:07:06,000 --> 00:07:09,000
So we are just defining this over here some.

122
00:07:11,000 --> 00:07:13,000
Viewed by In-q.

123
00:07:15,000 --> 00:07:16,000
ID or an ear.

124
00:07:16,000 --> 00:07:18,000
Then what I will do is next.

125
00:07:18,000 --> 00:07:21,000
Just divide this over here.

126
00:07:21,000 --> 00:07:22,000
Divide by the length.

127
00:07:23,000 --> 00:07:24,000
Then I will write.

128
00:07:25,000 --> 00:07:26,000
Just speed.

129
00:07:27,000 --> 00:07:29,000
Then Q over here.

130
00:07:29,000 --> 00:07:30,000
Then I will write.

131
00:07:32,000 --> 00:07:34,000
Well, here I have.

132
00:07:34,000 --> 00:07:38,000
I think I'm just missing one bracket over here.

133
00:07:38,000 --> 00:07:40,000
Let me see what I am missing.

134
00:07:40,000 --> 00:07:41,000
Okay, then.

135
00:07:41,000 --> 00:07:42,000
Space.

136
00:07:43,000 --> 00:07:43,000
Okay.

137
00:07:43,000 --> 00:07:44,000
I think that's fine.

138
00:07:44,000 --> 00:07:51,000
I'm not missing anything just so I will write km over hours, so I think that's fine.

139
00:07:51,000 --> 00:07:58,000
So in that case, if you don't have the speed, so then I will write the accept over here and we will

140
00:07:58,000 --> 00:07:59,000
just pass.

141
00:08:00,000 --> 00:08:00,000
Okay.

142
00:08:00,000 --> 00:08:04,000
So I think I'll have written this and it will be working.

143
00:08:04,000 --> 00:08:05,000
Should work.

144
00:08:05,000 --> 00:08:05,000
Fine.

145
00:08:05,000 --> 00:08:09,000
Just run the script now and see what results do we actually get.

146
00:08:09,000 --> 00:08:10,000
So just running.

147
00:08:11,000 --> 00:08:18,000
Now we have added the destination code as well, but let's see whether we are getting the speed or not.

148
00:08:19,000 --> 00:08:21,000
It might take a few minutes to run.

149
00:08:23,000 --> 00:08:27,000
So you may be seeing the output in the parallel as well.

150
00:08:28,000 --> 00:08:28,000
Okay.

151
00:08:32,000 --> 00:08:34,000
So on a toybox have passed.

152
00:08:36,000 --> 00:08:39,000
We are not able to see the currently the speed.

153
00:08:39,000 --> 00:08:43,000
But I think when this vehicle crosses this line, we will able to see the speed.

154
00:08:43,000 --> 00:08:49,000
Let's see when this the train crosses this line because we have a higher return.

155
00:08:49,000 --> 00:08:53,000
When the line intersects, then we will get better speed.

156
00:08:53,000 --> 00:08:59,000
But if you want to get greater speed before the line intersection, just move this from here to above

157
00:08:59,000 --> 00:08:59,000
this.

158
00:09:00,000 --> 00:09:00,000
Okay?

159
00:09:02,000 --> 00:09:04,000
So just checking.

160
00:09:04,000 --> 00:09:05,000
Okay.

161
00:09:07,000 --> 00:09:07,000
And.

162
00:09:11,000 --> 00:09:13,000
So it is a bit slow.

163
00:09:15,000 --> 00:09:17,000
And yes, it's going very slow.

164
00:09:18,000 --> 00:09:21,000
So when let's see, when this intersects, doesn't get the speed or not.

165
00:09:23,000 --> 00:09:25,000
So it might take a few seconds more.

166
00:09:30,000 --> 00:09:31,000
Okay.

167
00:09:32,000 --> 00:09:33,000
So.

168
00:09:34,000 --> 00:09:36,000
It just crossing, So.

169
00:09:37,000 --> 00:09:37,000
Let's see.

170
00:09:37,000 --> 00:09:38,000
What results do we get?

171
00:09:38,000 --> 00:09:40,000
It might take a few more seconds.

172
00:09:43,000 --> 00:09:44,000
Then the previous one.

173
00:09:44,000 --> 00:09:46,000
So let's see.

174
00:09:47,000 --> 00:09:50,000
Okay, so we're just crossing the line over here.

175
00:09:50,000 --> 00:09:56,000
And now it should when the trails intersect with this line, I think there we should have the count

176
00:09:56,000 --> 00:10:00,000
and the speed estimation should be done and should be should.

177
00:10:01,000 --> 00:10:01,000
Okay.

178
00:10:01,000 --> 00:10:02,000
So not okay.

179
00:10:02,000 --> 00:10:03,000
What does this happen?

180
00:10:04,000 --> 00:10:06,000
Okay, so there is an error.

181
00:10:06,000 --> 00:10:08,000
Let me see and fix this.

182
00:10:10,000 --> 00:10:11,000
I have found out the mistake.

183
00:10:11,000 --> 00:10:14,000
Basically, I have not initialized over here.

184
00:10:14,000 --> 00:10:19,000
This line queue ID is equal to list over here.

185
00:10:19,000 --> 00:10:21,000
So this was a mistake which I was making.

186
00:10:21,000 --> 00:10:24,000
So let's rerun the script again.

187
00:10:26,000 --> 00:10:27,000
Now reading the square.

188
00:10:28,000 --> 00:10:31,000
And so let's see what results do we get?

189
00:10:31,000 --> 00:10:34,000
Or if there is an error, we will definitely fix this.

190
00:10:36,000 --> 00:10:39,000
So it might take some time to execute.

191
00:10:39,000 --> 00:10:41,000
So please bear with me.

192
00:10:49,000 --> 00:10:49,000
Okay.

193
00:10:53,000 --> 00:10:55,000
So it might take some time.

194
00:10:55,000 --> 00:10:55,000
So.

195
00:10:58,000 --> 00:11:02,000
Or as this vehicle crosses this line, let's see what it does.

196
00:11:02,000 --> 00:11:03,000
It goes.

197
00:11:15,000 --> 00:11:15,000
Okay.

198
00:11:15,000 --> 00:11:16,000
So you can see there.

199
00:11:18,000 --> 00:11:21,000
Then this closes this line.

200
00:11:29,000 --> 00:11:29,000
Okay.

201
00:11:29,000 --> 00:11:31,000
So consider.

202
00:11:35,000 --> 00:11:35,000
Being.

203
00:11:35,000 --> 00:11:42,000
So when this vehicle crosses the line, we should have a speed of the vehicle over here with that truck

204
00:11:42,000 --> 00:11:43,000
at label and.

205
00:11:44,000 --> 00:11:46,000
Us, there should be the count as well.

206
00:11:47,000 --> 00:11:49,000
I hope it will work by now.

207
00:11:49,000 --> 00:11:51,000
We will not see the show like we see previously.

208
00:11:52,000 --> 00:11:53,000
So let's sing.

209
00:11:57,000 --> 00:11:59,000
It's around.

210
00:12:02,000 --> 00:12:05,000
You can see that we get this crossing line, which is restricting now.

211
00:12:06,000 --> 00:12:06,000
Okay.

212
00:12:06,000 --> 00:12:09,000
So we have the vehicle count here as well.

213
00:12:09,000 --> 00:12:10,000
You can see it.

214
00:12:11,000 --> 00:12:13,000
Plus we have the speed of the vehicle as well.

215
00:12:13,000 --> 00:12:14,000
That's cool.

216
00:12:14,000 --> 00:12:16,000
So now let's see for the other vehicle.

217
00:12:16,000 --> 00:12:19,000
The mistake was only that we have not initialized the list.

218
00:12:19,000 --> 00:12:23,000
So that was the only the mistake which we were making.

219
00:12:23,000 --> 00:12:24,000
So I have just added the list.

220
00:12:24,000 --> 00:12:27,000
And now you can see that the results are very perfect.

221
00:12:29,000 --> 00:12:32,000
So by just adding a list, you can see that.

222
00:12:34,000 --> 00:12:35,000
Result are awesome.

223
00:12:35,000 --> 00:12:40,000
So now let's see when this vehicle crosses this line.

224
00:12:41,000 --> 00:12:46,000
And we can have should have a vehicle count here as well, and it should increment as well.

225
00:12:51,000 --> 00:12:55,000
So now we can see that the vehicle is going to cross the line.

226
00:12:55,000 --> 00:12:55,000
Okay.

227
00:12:55,000 --> 00:13:01,000
So when you can see that we have a car one as well and we can see the speed as well.

228
00:13:01,000 --> 00:13:03,000
So that's all from this tutorial.

229
00:13:03,000 --> 00:13:05,000
See you all in the next tutorial.

230
00:13:05,000 --> 00:13:06,000
Till then, bye bye.

