Well, guys, till now we have done the vehicles counting, entering and leaving.
Plus we have also seen object tracking as well.
So now I will only add the speed estimation code in the previous script, which we have implemented,
in which we implemented our vehicles, counting, entering and leaving.
So I will just add the speed estimation code in the in the previous script.
So I have already explained you the speed estimation when I explained the vehicles counting the previous
lectures.
So if you haven't watched that lecture, do watch that lecture because in this lecture I will just add
the speed estimation function over here.
I will not go into very much detail, but if you want to go into the details of the speed estimation,
you must watch the previous lecture of in which I explained the speed estimation code.
The lecture name will be weakened counting and the speed estimation.
So here in this script, in the vehicles counting, entering and leaving, I will just add the speed
estimation code and give you a quick overview over here.
So here I've added a speed estimation code.
So I've created a function by the name estimate speed over here.
So in this function you can see over here I am using, I'm first calculating the distance in pixels.
So here to calculate the distance in pixels, I'm using a gradient distance formula which is square
root x two minus x one square plus x two minus y one squared.
So I'm just using the collodion distance for now over here.
I've just let me write it down in this tense formula over here.
So I'm just using a gradient distance formula over here.
Calculate the distance in pixels, and here I've defined the pixel per meter as constant, which is
eight.
We can make it dynamic, like away from camera one and close to camera.
The value of pixel per meter is 20, and to calculate the distance in meters, I need to divide divide
the distance in pixel over pixels per meter.
And here I'm calculating a time constraint.
It's just a constant.
You can make it dynamic as well.
And here I'm calculating the speed I know.
And you also know speed is equal to distance divided by time.
But here the time constant is basically frequency.
This is basically frequency, and time is equal to one over frequency.
So it becomes speed is equal to distance in meters multiplied by frequency.
So this time constant is equal to basically frequency.
Okay.
So we are just multiplying speed in these equations.
So we are calculating speed is distance in meters multiplied by frequency, and in return we get the
speed.
Now I will call this estimate speed function in draw dash boxes function over here.
Okay, so in this draw boxes function, I will calculate this call the estimate speed function over
here.
Okay.
So you can see that here.
I'm just calling.
Let me show you where I'm just calling.
So here I'm just calling the estimate speed function over here and I'm just passing, passing the.
You can say that the center coordinates of the bottom of the bounding box over here to calculate the
estimate speed.
And just after calculating the object speed in the current frame, I'm just appending the speed values
into the list by the name speed line queue, which can of object speed of with respect to each ID and
the object id like each detected object has its own ID.
And in the label section, I'm just displaying the speed over here.
After object ID and the detected object name, for example, is car or truck.
And after this the speed will appear.
So I'm just adding the speed as well and I'm just presenting the speed in the form of kilometer per
hour.
So let me show you the result as I'm using C running this script on CPU.
So I've just run the script before this video tutorial because CPU takes quite some time while in GPU
it runs faster.
So here are the results.
Let me just open the results over here.
So you can see that.
Now, let's see, when this trail crosses this line, we get the speed.
Okay?
And now when this trail crosses the line, like you can see over here, this brown will intersect this
green line.
We get the speed.
Okay.
So when now when this truck will cross this line, when we get the speed.
So this is the speed estimation, code explanation.
So if this is all from this video tutorial, I hope you have learned a lot from this video tutorial
series.
See you all in the next video tutorial.
Till then, bye bye.