In the part one.
We have implemented the vehicle counting.
In the second part, I will add the speed estimation port in the that script as well.
So first of all, we will write declare a variable speed line queue.
So when we have the estimated speed, we will append the speed into this dictionary so that we can further
estimate the speed of the vehicle.
So now we need to create a function by the name estimate speed over here.
Define estimate speed.
And it.
Report it will take.
Reverse location one and location two.
Okay, so what are these?
Let me tell you.
So the input it will take these two variables the the first and the second point of the trail.
So what does it mean that it will take this first point of the trail and the second point of this trail?
Okay.
Basically, the trails are created when we basically you can say that when we append the center coordinates
of the bounding box in each frame.
So in this way, the trails are created.
So we are taking the first coordinate and the second coordinate of this trails.
Okay, so here we are in location one and location two and then click on Enter.
So first we need to find the distance in pixels.
So what is distance in pixels or how it is calculated?
So to calculate the distance in pixels, we will use a klodian formula.
So this write a distance formula.
So when I go to the images over here, so this is the formula we have for Euclidean distance formula,
which is x two minus x one over square plus y two minus y one over square.
So I will just write this formula over here.
So first we need to define the square root mat, dot, square root.
Then we need to have the power.
So to do this we will write mat.
Okay.
What I'm doing now Math Dot P.O.W..
So now I will write allocation to basically it's x two minus x one.
So it's zero.
Then I will write.
Just give me a minute to set this.
Then in the next step, I will write.
Minus location.
One zero.
Next.
What I will do is.
So here we need to define the power of two.
So it means power.
So as you can see that here we have the power of two.
So here I have written two.
So in that case, if there is power of 3 or 4, I will just write over here.
So just come over here.
Then I will write.
Nice net dollar.
IOW, then it is location.
Rule one minus.
Vacation.
One.
Two.
So here I've.
Here I've written the distance in pixels in the form of occlusion distance formula.
So next we need to calculate the pixel parameters.
So here I will take the pixel about pixel fixed value of pixel per meter.
But if you want to get more adequate results or more better vision, you can make it dynamically.
Bowser.
Trembler
Westminster parameter.
But here the x value of pixel per as in here.
Then we will calculate the distance in meters, which will be.
Distance in pixels.
Multiply by sorry.
Distance in pixels divided by pixel.
Parameter.
Then I will declare a time constant.
So this is basically.
You see that basically fixed value which will contain 15 cross 3.6.
So we can.
The more elevated result you can get.
3.6 is also the constraint which we can adjust as one over.
So now we will calculate speed.
So let me share what is the formula speed eight point.
So speed is equal to distance over time.
Okay.
So what I will do over here is the distance in meters.
It's overtime.
But here what we're doing, we are getting time constraint.
So we have basically frequency in this case.
So.
Frequency is equal to one by T.
Okay.
So we will just multiply the under time constraint because time constraint in the form of fancy.
So we are just multiplying that time constraint with the distance.
Okay.
If we have a time then we should divide it so it will return here and speed.
Okay.
So we have created a function for the speed estimation.
The next thing we need to do is we need to add this call, this function where we need to call this
function.
Just checking it because I might forgot something.
Okay, so we now need to call this function over here.
I will write object speed is equal to estimate speed, which are the function which I have created.
Then I will pass that vehicle ID.
One then will pass the data.
ID zero as well.
Over here.
IDs zero.
And then I will press enter and bound my speed with the.
I will just append these values into this.
Object be okay?
So I have done this.
So here we are appending the object speed values into this dictionary so that we can get where the speed
of each of the detected object.
Okay, so I think that's enough.
Plus we need to make that change.
One thing over here because we need to display this right here.
I, if we get the speed in labor, is equal to labor.
Thus.
Thus we just had the space over here.
Basically, we are we are adding the speed value with the we can say that with the label.
So we are.
So basically, let me show you the speed value will appear with this label like here with this label
in the with this label over here.
So we are just defining this over here some.
Viewed by In-q.
ID or an ear.
Then what I will do is next.
Just divide this over here.
Divide by the length.
Then I will write.
Just speed.
Then Q over here.
Then I will write.
Well, here I have.
I think I'm just missing one bracket over here.
Let me see what I am missing.
Okay, then.
Space.
Okay.
I think that's fine.
I'm not missing anything just so I will write km over hours, so I think that's fine.
So in that case, if you don't have the speed, so then I will write the accept over here and we will
just pass.
Okay.
So I think I'll have written this and it will be working.
Should work.
Fine.
Just run the script now and see what results do we actually get.
So just running.
Now we have added the destination code as well, but let's see whether we are getting the speed or not.
It might take a few minutes to run.
So you may be seeing the output in the parallel as well.
Okay.
So on a toybox have passed.
We are not able to see the currently the speed.
But I think when this vehicle crosses this line, we will able to see the speed.
Let's see when this the train crosses this line because we have a higher return.
When the line intersects, then we will get better speed.
But if you want to get greater speed before the line intersection, just move this from here to above
this.
Okay?
So just checking.
Okay.
And.
So it is a bit slow.
And yes, it's going very slow.
So when let's see, when this intersects, doesn't get the speed or not.
So it might take a few seconds more.
Okay.
So.
It just crossing, So.
Let's see.
What results do we get?
It might take a few more seconds.
Then the previous one.
So let's see.
Okay, so we're just crossing the line over here.
And now it should when the trails intersect with this line, I think there we should have the count
and the speed estimation should be done and should be should.
Okay.
So not okay.
What does this happen?
Okay, so there is an error.
Let me see and fix this.
I have found out the mistake.
Basically, I have not initialized over here.
This line queue ID is equal to list over here.
So this was a mistake which I was making.
So let's rerun the script again.
Now reading the square.
And so let's see what results do we get?
Or if there is an error, we will definitely fix this.
So it might take some time to execute.
So please bear with me.
Okay.
So it might take some time.
So.
Or as this vehicle crosses this line, let's see what it does.
It goes.
Okay.
So you can see there.
Then this closes this line.
Okay.
So consider.
Being.
So when this vehicle crosses the line, we should have a speed of the vehicle over here with that truck
at label and.
Us, there should be the count as well.
I hope it will work by now.
We will not see the show like we see previously.
So let's sing.
It's around.
You can see that we get this crossing line, which is restricting now.
Okay.
So we have the vehicle count here as well.
You can see it.
Plus we have the speed of the vehicle as well.
That's cool.
So now let's see for the other vehicle.
The mistake was only that we have not initialized the list.
So that was the only the mistake which we were making.
So I have just added the list.
And now you can see that the results are very perfect.
So by just adding a list, you can see that.
Result are awesome.
So now let's see when this vehicle crosses this line.
And we can have should have a vehicle count here as well, and it should increment as well.
So now we can see that the vehicle is going to cross the line.
Okay.
So when you can see that we have a car one as well and we can see the speed as well.
So that's all from this tutorial.
See you all in the next tutorial.
Till then, bye bye.