1
00:00:02,000 --> 00:00:06,000
Well, guys, till now we have done the vehicles counting, entering and leaving.

2
00:00:06,000 --> 00:00:09,000
Plus we have also seen object tracking as well.

3
00:00:09,000 --> 00:00:15,000
So now I will only add the speed estimation code in the previous script, which we have implemented,

4
00:00:15,000 --> 00:00:19,000
in which we implemented our vehicles, counting, entering and leaving.

5
00:00:19,000 --> 00:00:23,000
So I will just add the speed estimation code in the in the previous script.

6
00:00:23,000 --> 00:00:29,000
So I have already explained you the speed estimation when I explained the vehicles counting the previous

7
00:00:29,000 --> 00:00:29,000
lectures.

8
00:00:29,000 --> 00:00:35,000
So if you haven't watched that lecture, do watch that lecture because in this lecture I will just add

9
00:00:35,000 --> 00:00:37,000
the speed estimation function over here.

10
00:00:37,000 --> 00:00:42,000
I will not go into very much detail, but if you want to go into the details of the speed estimation,

11
00:00:42,000 --> 00:00:47,000
you must watch the previous lecture of in which I explained the speed estimation code.

12
00:00:47,000 --> 00:00:50,000
The lecture name will be weakened counting and the speed estimation.

13
00:00:50,000 --> 00:00:54,000
So here in this script, in the vehicles counting, entering and leaving, I will just add the speed

14
00:00:54,000 --> 00:00:58,000
estimation code and give you a quick overview over here.

15
00:00:58,000 --> 00:01:01,000
So here I've added a speed estimation code.

16
00:01:01,000 --> 00:01:05,000
So I've created a function by the name estimate speed over here.

17
00:01:05,000 --> 00:01:10,000
So in this function you can see over here I am using, I'm first calculating the distance in pixels.

18
00:01:10,000 --> 00:01:16,000
So here to calculate the distance in pixels, I'm using a gradient distance formula which is square

19
00:01:16,000 --> 00:01:21,000
root x two minus x one square plus x two minus y one squared.

20
00:01:21,000 --> 00:01:24,000
So I'm just using the collodion distance for now over here.

21
00:01:24,000 --> 00:01:30,000
I've just let me write it down in this tense formula over here.

22
00:01:30,000 --> 00:01:33,000
So I'm just using a gradient distance formula over here.

23
00:01:33,000 --> 00:01:38,000
Calculate the distance in pixels, and here I've defined the pixel per meter as constant, which is

24
00:01:38,000 --> 00:01:38,000
eight.

25
00:01:38,000 --> 00:01:42,000
We can make it dynamic, like away from camera one and close to camera.

26
00:01:42,000 --> 00:01:48,000
The value of pixel per meter is 20, and to calculate the distance in meters, I need to divide divide

27
00:01:48,000 --> 00:01:52,000
the distance in pixel over pixels per meter.

28
00:01:52,000 --> 00:01:54,000
And here I'm calculating a time constraint.

29
00:01:54,000 --> 00:01:55,000
It's just a constant.

30
00:01:55,000 --> 00:01:57,000
You can make it dynamic as well.

31
00:01:57,000 --> 00:01:59,000
And here I'm calculating the speed I know.

32
00:01:59,000 --> 00:02:03,000
And you also know speed is equal to distance divided by time.

33
00:02:03,000 --> 00:02:06,000
But here the time constant is basically frequency.

34
00:02:06,000 --> 00:02:10,000
This is basically frequency, and time is equal to one over frequency.

35
00:02:10,000 --> 00:02:14,000
So it becomes speed is equal to distance in meters multiplied by frequency.

36
00:02:14,000 --> 00:02:17,000
So this time constant is equal to basically frequency.

37
00:02:17,000 --> 00:02:18,000
Okay.

38
00:02:18,000 --> 00:02:20,000
So we are just multiplying speed in these equations.

39
00:02:21,000 --> 00:02:26,000
So we are calculating speed is distance in meters multiplied by frequency, and in return we get the

40
00:02:26,000 --> 00:02:26,000
speed.

41
00:02:26,000 --> 00:02:31,000
Now I will call this estimate speed function in draw dash boxes function over here.

42
00:02:33,000 --> 00:02:38,000
Okay, so in this draw boxes function, I will calculate this call the estimate speed function over

43
00:02:38,000 --> 00:02:39,000
here.

44
00:02:39,000 --> 00:02:39,000
Okay.

45
00:02:39,000 --> 00:02:42,000
So you can see that here.

46
00:02:42,000 --> 00:02:43,000
I'm just calling.

47
00:02:43,000 --> 00:02:45,000
Let me show you where I'm just calling.

48
00:02:45,000 --> 00:02:50,000
So here I'm just calling the estimate speed function over here and I'm just passing, passing the.

49
00:02:50,000 --> 00:02:55,000
You can say that the center coordinates of the bottom of the bounding box over here to calculate the

50
00:02:55,000 --> 00:02:56,000
estimate speed.

51
00:02:56,000 --> 00:03:02,000
And just after calculating the object speed in the current frame, I'm just appending the speed values

52
00:03:02,000 --> 00:03:08,000
into the list by the name speed line queue, which can of object speed of with respect to each ID and

53
00:03:08,000 --> 00:03:11,000
the object id like each detected object has its own ID.

54
00:03:12,000 --> 00:03:16,000
And in the label section, I'm just displaying the speed over here.

55
00:03:16,000 --> 00:03:22,000
After object ID and the detected object name, for example, is car or truck.

56
00:03:22,000 --> 00:03:24,000
And after this the speed will appear.

57
00:03:24,000 --> 00:03:29,000
So I'm just adding the speed as well and I'm just presenting the speed in the form of kilometer per

58
00:03:29,000 --> 00:03:29,000
hour.

59
00:03:29,000 --> 00:03:34,000
So let me show you the result as I'm using C running this script on CPU.

60
00:03:34,000 --> 00:03:42,000
So I've just run the script before this video tutorial because CPU takes quite some time while in GPU

61
00:03:42,000 --> 00:03:43,000
it runs faster.

62
00:03:43,000 --> 00:03:45,000
So here are the results.

63
00:03:45,000 --> 00:03:47,000
Let me just open the results over here.

64
00:03:48,000 --> 00:03:49,000
So you can see that.

65
00:03:49,000 --> 00:03:53,000
Now, let's see, when this trail crosses this line, we get the speed.

66
00:03:53,000 --> 00:03:54,000
Okay?

67
00:03:54,000 --> 00:04:00,000
And now when this trail crosses the line, like you can see over here, this brown will intersect this

68
00:04:00,000 --> 00:04:00,000
green line.

69
00:04:00,000 --> 00:04:01,000
We get the speed.

70
00:04:01,000 --> 00:04:02,000
Okay.

71
00:04:02,000 --> 00:04:07,000
So when now when this truck will cross this line, when we get the speed.

72
00:04:07,000 --> 00:04:10,000
So this is the speed estimation, code explanation.

73
00:04:10,000 --> 00:04:16,000
So if this is all from this video tutorial, I hope you have learned a lot from this video tutorial

74
00:04:16,000 --> 00:04:17,000
series.

75
00:04:17,000 --> 00:04:19,000
See you all in the next video tutorial.

76
00:04:19,000 --> 00:04:21,000
Till then, bye bye.

