In this tutorial, we will be creating an application where I will be counting the persons entering
and leaving from a specific area.
Plus, I will also show you how you can count the number of vehicles entering and leaving from a specific
area as well.
So in this tutorial we will be doing objects counting and an object will be counting the objects entering
and leaving from a specific area.
And we will be creating two different applications.
One is the upper one is the count of persons entering and leaving from a specific area, and the second
one is the count of vehicles which are entering and leaving from a specific area.
So let's get started with it.
So in this tutorial, uh, with these applications I will be using Yolov5 and Deepsort object tracking
algorithm.
So you will be in a state of the art object detection algorithm, while, uh, Deepsort is the state
of the art object tracking algorithm.
Okay.
So we will be integrating object detection and object tracking so that we can create a card counting
application or vehicle counting application.
Or you can say we will be, uh, counting the persons entering and leaving from a specific area.
So there will be two applications.
One is the persons entering and leaving, or the count of persons entering and leaving from a specific
area.
And the second one will be the count of vehicles entering and leaving from a specific area.
So first of all, before we go ahead, uh, we have lost.
So there are so.
So before, uh, let's get started with it.
So first of all, you can see over here I have the YOLO v nine repository or over here.
So I will just first clone this YOLO nine GitHub repo.
So I will just open the PyCharm from here.
So you can see here the PyCharm ID.
I've just created a new project by the name entering leaving counting your Deepsort recording.
So you I've just created this project in my F local directory.
Okay.
So let's get started with it.
So first of all, I just, uh, I will just note that you have the benign GitHub repository.
So I will just add the link over here and write git clone.
So now you can see that, uh, your login and GitHub repository has been cloned.
Okay.
So if I just refresh this over here.
It.
But it's not here.
Okay.
So you can see here we have the lone Euro v nine, uh, complete GitHub repository over here.
So you can see all the files that we have in the repository are being here.
So now I will just set this yolo v nine uh directory uh folder as my parent directory.
So to do this I will just write CD which stands for current directory.
And I will just set this folder as my current directory.
And now it's being set.
So before we go ahead let's create our virtual environment so you can create the virtual environment
if you don't want to disturb your uh packages.
So you will just write conda create minus n.
And here I will just write the name of my virtual environment as v nine.
Okay.
So I am just creating a virtual environment by the name your Logging line.
Okay, so.
So you can see that it says that already a virtual environment by the name YOLO v9.
So I've revoked that already created environment.
And now I'm just waiting a new environment.
So by the name of ignite and I will just write conda activate yolo v9.
So that's it.
So now I have just created a virtual world by the name yolo v9.
And now I will install all the packages that are mentioned in the requirements.txt file.
So over here you can see the requirements.txt file.
In the requirements.txt file you will find all the packages uh, that are required to run this uh to
run object detection object tracking scripts successfully.
So if I just write pip install minus r.
So this will install all the packages that are listed inside this requirements.txt file.
So if you install these packages one by one this will take quite some time.
So it's always a good practice to list all your packages in the requirements.txt file and books.
And by writing one command in the terminal pip install minus r requirements.txt.
So this install all the packages that are listed in the requirements dot txt file.
So the package installation will take around 3 to 4 minutes.
So let's get back as this packages gets drawn.
Now you can see that all the packages are being installed.
So the instructions are I've just created a notepad file by the name instruction.
Here I have listed all the steps that we will be following in this tutorial.
So now we have uploaded the nine GitHub repo.
We have created a virtual environment.
We have installed all the required packages.
So three things are done.
So now we will download the sample videos from the Google Drive link below.
So I have added some uh videos or to test uh when we try to.
So one is the person, uh, walking on a street and other are the vehicles on a highway lane so that
we can, uh, count the vehicles entering and leaving and count the persons entering and leaving the
specific area.
So I have placed those demo videos onto my Google Drive.
So I will directly download those demo videos from Google Drive into this PyCharm, uh, IDE.
So to download the demo videos from, uh, Google Drive and directly into the PyCharm IDE, we need
to install the pip install g down package.
So I will just write over here pip install a down.
And I will add this package in the uh requirements.txt file over here as well.
So.
Now you can see this package is installed.
So this package now allows us to download any demo videos or any files or any image file or any video
and image file or any, uh, other files, zip files from the Google Drive directly into our local IDE.
It can be Visual Studio Video, it can be PyCharm, or it can be Orange Studio or any other IDE.
Okay, so I've just added the write down and edit the link over here.
So now you can see that uh, just watch that mp4 uh is downloaded into our PyCharm IDE.
Or if I just refresh this up you can see the text box dot mp4 file over here.
And let me just open this up.
So now I will download the second demo video from the Google Drive.
Like look directly into this PyCharm ID.
So I will just add this link over here.
So now you can see the second demo video is being downloaded.
Uh, the name of this demo video is S3 dot mp4.
Okay, so we, I have downloaded two demo videos and that would be enough to test our scripts.
Okay so we have test for MP4 and testing.
Okay.
So here we have a test.
We know that.
So that's good enough.
So now if we just see over here uh, I have cloned a GitHub repo, created a virtual environment, installed
all the required packages, download the sample video.
So I've downloaded two sample videos from the Google Drive into my PyCharm IDE as well.
So now in next step, in the first step I will be doing object tracking using YOLO, v9 and Sword algorithm.
So let's get started with it.
Up here.
You can see I've just created a file by the name detect-dual-tracking.py.
Currently it only has the object detection board in the first step.
I will integrate a Deepsort object tracking with yolo v9 object detection board over here.
So currently this is all object detection code.
We will first integrate object tracking and then we will be counting the person or vehicles entering
and leaving in the next step.
So object tracking using YOLO v9 and the source.
So here right.
So we will be doing object tracking using yolo v9 and Deepsort algorithm.
So let me integrate object tracking board into this object detection board over here.
The midfielders open the stands over here.
So from the algorithm.
The algorithm gives us output in the form of bounding box coordinates x one and y one represents the
top, left corner and bounding box coordinates, and x two.
Y two represents the bottom right corner bounding box coordinates.
So this is the output uh, which we get from the algorithm.
Plus we also get the confidence score and the class name okay.
So but uh, we will be passing the output that we get from the algorithm as an input to the Deepsort
algorithm.
So the output that we get from the YOLO algorithm will be passed as an input to the Deepsort object
tracking algorithm.
So the Deepsort object tracking algorithm accepts uh, the input as height.
And so.
The Deepsort algorithm does not accept the bounding box coordinates like x one, y one or x two, y
two.
The Deepsort object tracking algorithm accepts input as the height and width of the bounding box.
Okay.
Last, the center point of the bounding box.
So this is what our Deepsort object tracking algorithm accept as input.
Along with this, accept a confidence score and class name.
So the confidence score and class name are same uh, for the algorithm.
But uh, the Yolo v nine algorithm gives us output in the form of bounding box coordinates.
So Deepsort algorithm will not accept the, uh, output input uh, in the form of bounding box coordinates.
So as we pass the yolo v nine output as an input to that Deepsort algorithm.
So we need to convert this, uh, bounding box coordinates x one, y one and X2Y2 into this form like
height and width of the bounding box and the center point of the bounding box.
So before it pass the YOLO v nine output as an input to the Deepsort algorithm, we need to transform
the Yolo nine output into the format that is required by the Deepsort algorithm, which is height and
width of the bounding box and center coordinates of the bounding box.
So let's do it.
So x.
So this is X1Y1 and X2Y2.
Okay.
So last we have the class names.
Okay.
But this is what we get from the revolving line output.
So the output is currently in the form of tensors.
We need to convert the output from tensors into integers.
The next, we will find the center coordinates for each of the bounding box.
So you can see over here we have find the center coordinates for each of the bounding box.
As I told you, uh, that Deepsort algorithm accepts input as a center coordinates of the bounding box
and height and width of the bounding box.
So next we need to find the height and width of the bounding box.
So I will just write.
The.
So here you can see that we have pointed out the width and the height of the bounding boxes.
So, uh, if you just see over here so you can see here, uh, this is the x one minus x two.
We do this, we get the width.
And if we do y one minus y two we get the height.
So I'm just following the same steps over here.
So now, uh, as in a single frame, there will be multiple different objects will be detected.
So now we will need to append this width and height and center coordinates of the bounding box for a
complete frame into our list.
So we will do this.
I would create three empty lists over here.
So this is what the bounding box coordinates.
This is for the confidence score.
This is for the class name and one we have for output as well.
The.
Got a Deepsort algorithm accept input as in the form of central coordinates Cxxvi bounding box coordinates.
Width and height.
Well, now I will just append these values to this list which we have created.
Now I will also find out the quantum score for this.
So I will just use for the math library so that I can convert the confidence score from tensors into
integer.
He.
And now I will also open the scoring to the list which I have created above.
And I'm just converting the class IDs into integers as well.
Because they are originally in the form of tensors, we need to convert them into integers.
And now I'm just spilling all the class ideas into the list as well.
But now I'm just converted.
Uh, so now I've just, uh, transformed my Yolo V8 output into the format that is required by the Deepsort
algorithm.
Like, you can see that I have the width and height and center coordinates of the bounding boxes.
I have the confidence score.
I have the class names as well.
So now we need to convert, uh, this output into tensors.
Uh, or this, uh, this, uh, output into dancers.
And then we'll pass in this as an input to the Deepsort algorithm.
Okay.
So we have converted the this as.
So we have going to just enter coordinates.
Uh bounding boxes width and height into tensors that are required.
We don't require to convert the class IDs into tensors currently.
So I will just write output is equal to okay.
So okay okay okay.
So now I have not initialized with over here.
So before we go ahead here.
Over here.
I've just created a file by the name object counter dot pi.
So here you can see that I have class object counter.
And over here I will explain this complete code which is over here.
So first we have this initialize Deepsort.
So first I will do what I will do here is okay.
So I will just write from check out the import.
So I will just import this class.
So all the functions that we are required are inside this class okay.
So I will just write object counter.
Now I will just need to the initialization over here.
Okay.
We are good to go.
Next I will write.
Each sword is equal to.
Object counter, and we will be using the initialized Deepsort function over here.
Okay.
So now what I will do is.
Oh, well, I will just go over here.
It's not.
So if I just show you.
Okay, so now I have don't have added the Deepsort files over here as well.
So let me add those Deepsort files.
And so I haven't added the link over here.
So.
Before we write the sixth and seventh step, we need to add.
We need to download.
That Deepsort files are.
Right.
It.
We can see here.
I did a Google Drive link.
I have pasted each zip file in this Google Drive link on this Google Drive link, so I will actually
download a zip file from this Google Drive link into my PyCharm ID, and then I will unzip this file.
Okay.
So I'm downloading this deepsort zip file from the Google Drive directly into this PyCharm IDE.
And uh, now you can see the file size is 43.1 MB.
And as I as it gets downloaded I will unzip this file.
Okay.
So now you can see the file is being downloaded.
Let me just unzip it.
So now unzip that file.
So let's go ahead and you can see I have this file over here.
So if I just open the deepsort uh.py code over here.
So now you can see here we have the class deepsort.
And here we have the initialize function over here.
And I will be using this Deepsort dot update function.
And here I am this update function.
Now you can see that we have the input in the form of bounding box coordinates and width.
And uh, we have the input in the form of width and the height of the bounding box and center coordinates
of the bounding boxes.
Plus we have the confidence score and the class name and the original frame as the input of this update
function.
So that's good.
So I will be using this Deepsort dot update function and in the import over here.
In the input over here.
I will be passing this center coordinates of the bounding box bounding box width and the bounding box
height.
And we have all this inside this.
Inside this because we have converted the this into tensors, and now we are passing this as an input
to the data sort update function.
Okay.
For the input ready sort algorithm.
Plus we will be passing the confidence port and the class IDs.
And we will be passing the grand frame which I have already shown.
Okay, so this will be the input to the deep sort algorithm, and we will be passing this to that update
function that I've already shown you.
So next what we'll do is we have the length of the outputs greater than zero.
Like if there are some objects, if any of the object is directly in the current frame, like 1 or 2,
then what we.
Right.
So I mean, so if you just print out the output from here.
Let me show you how our output looks like.
Thought we were just running this detect as dual tracking, not by script.
And that we just got this text box, not MP4 video, which we have downloaded already from the Google
Drive link.
So let me show you.
So if I just show you here.
From the Deepsort algorithm like we have passed it in the in as a center coordinates of the bounding
boxes and width and the height of the bounding boxes as an input to the dot algorithm and from the from
the output of the algorithm.
What we get is the bounding box coordinates.
So this is the output of the Deepsort algorithm.
We get the bounding box coordinates a unique ID.
Basically, in object tracking we assign a unique ID to each of the detected object.
So we get the unique ID for each of the detected object.
Plus we get the class name or class IDs.
For example, for the person class, the class ID is zero.
So the Deepsort algorithm returns us the bounding box coordinates like x one, y one, and x two, y
two that are the top left corner bounding box coordinate and bottom right corner bounding box coordinates.
Along with this Deepsort algorithm, output gives us signs.
In the Deepsort algorithm output, we get a unique ID for each of the detected object.
Basically, this is what object tracking do.
In object tracking, we assign a unique ID to each detected object.
Thus we get the class ID.
For example, for the person class, the class ID is zero.
So this is the output that we get from the Deepsort algorithm.
Love it.
So I have got the idea for this error because.
So we just layer this over here.
It.
The.
Okay, so now it's working.
Okay.
So now I think.
Yeah.
Hopefully it will work fine.
Let's see how it goes.
I think now the issue will be solved.
Okay, so.
Okay, so we also need to run the Deepsort algorithm step.
We need to have the easy dish package installed as well.
So I try to.
Then I can just, like, maybe start easy then.
Yeah.
So I run over here as well.
So if you just install all these packages.
Uh, if you run install the requirements.txt file, this package will also get installed along the way.
So let's run this up.
So this will take a few seconds because on my local system I don't have GPU, I have CPU, so I'm running
on CPU.
A.
Or last one will have the output being shown over here.
Okay.
So last data packet is shown.
Like let me just correct this up over here as well where I have num pi.
It's all we need to have.
NumPy.
Less than 1.24.
Else will give an error log.
Okay, so we will I will first uninstall numpy.
Because with the latest version of numpy we get error.
So we'll just downgrade the one version.
So.
Or you just install numpy with version less than.
1.2 score.
Okay, so I hope this will fix up the issue.
Currently there is no output was.
As we go out in the next frame we will be able to see the output.
I am not showing displaying the output currently.
Okay, so now you can see here.
Uh, so this is the output that we get from the uh sort algorithm like you can see over here.
So this is the output that we are getting from the Deepsort algorithm, so that these are the bounding
box coordinates.
Okay.
Here you can see this is a unique ID that is being assigned to each of the detected object.
And here we have the class IDs.
For example for the person class the class ID zero.
So these are the bounding box coordinates X1Y1X2Y2.
This is the unique ID like in object tracking we assign a unique ID to each of the detected object.
So the.
Here the unique id is one.
Here for the second object the unique id is two.
For the third object, unique id is four.
And this is the class ID for the person class.
The class ID is zero.
Okay.
So if I just show you over here.
So the Deepsort algorithm gives us the bounding box coordinates, a unique ID for each of the detected
object.
Plus we get the class IDs.
For example, for the person class the class id zero okay.
So this is for what we are getting for each of the frame.
Like the complete video is divided into 341 frames.
And we are doing detection on each of the frame one by one.
And we are getting the bounding box coordinates unique ID for each of the detected object.
Thus we are getting the class IDs as well.
Okay.
So.
If the length of the output is greater than zero.
The first four are presenting the bounding box coordinates.
Then the second last basically represents the unique ID that we assign to each of the detected object.
And the last one represents the object ID or the class ID.
Okay, so if I just go to the object counter.py file.
So over here you can see that I have created draw boxes function that will draw bounding box coordinates
around each of the detected object.
Plus will add the unique ID that is being assigned to each of the detected object.
Plus will also add the class names.
So I will just write draw dash boxes or I will just write.
So if I just go above over here so we have object counter.
I will assign draw dash boxes.
We have the front frame over here.
Lasts will pass down the warning box or nets.
It was the IDs.
You need guidance.
Plus will class the class ylist here.
Okay, so if I just go to the object counter.py file.
So let me explain you this complete code from the start very start.
So over here you can see that here we have created a function by the name.
Uh okay.
Let's start from the initialization step.
So here I am just creating a line by the name self dot line.
Okay.
So in this uh, dot nine or I am just passing the coordinates for the line.
So let me show you how does it works.
At this.
So for example, this is the video in which I will be doing vehicle scouting.
I will be counting the vehicles entering and leaving.
So I am just creating a line over here.
You can see that.
So when the vehicles passes by this line.
So I will say like this vehicle passes by this time I will say that this vehicle is.
So when this vehicle passes first line, I will say that this vehicle is leaving.
Okay.
And when the vehicle coming from here passes by this line, I will say that this vehicle is entering.
So the vehicle passes by.
I say that vehicle is leaving the lane.
And when the vehicle over here on this lane passes by this line, I will say that vehicle is entering
the lane.
Okay.
So we have this creating a line.
And here I have this.
If you just record this.
So if you just focus over here in that spot where my cursor is.
Okay.
At this point where my question is so you can see if I just go over here, this will be the one to explain
the the first endpoint coordinates of the line.
And so if I just go over here this gave me the second and third point coordinates for this line okay.
So these are the first endpoint coordinates.
And these are the second and third borders for this line.
And you can see those values over here okay.
So you can see that I have this pass on the first endpoint coordinates of the lines values over here.
And these represent the second endpoint coordinates of the line okay.
Plus we are just creating a dictionary over here uh, by the name entering and leaving.
And in the end conditioning dictionary.
We are storing the vehicles or the persons entering, uh, the lane over and thus leaving their dictionary.
We are this will restore the person or vehicles leaving the lane.
And I'm just creating another dictionary by the name Delta Dash DK.
Okay, so here I have just mentioned all the classes name that we have in the Coco data set.
So the Coco or YOLO model has been pre-trained trained on the Coco data set.
And Coco dataset consists of 80 different classes.
So uh, if we have the class id zero, this means it belongs to the person class.
If we have the class id one, it means that it belongs to the bicycle class.
If we have the class 82, it belongs to the car class.
And if we have the class ID four, uh, if we have the class ID three, it belongs to the motorbike
class.
Okay.
And if we have the class ID as 79, then it locks the toothbrush class.
So we start with zero and end at 79.
Okay.
So the class would class ID zero means that it belongs to the person class.
Class ID one means it blocks the bicycle.
Class 82 means blocks of the car class.
Then we have the complete color code labels function.
So if the class ID or label is zero, then it means it belongs to the person class and the bounding
box will have the green color.
If the class ID is two, then it means it belongs to the car class, and the bounding box will have
the following color.
If the class ID is three blocks, the motorbike class and the bounding box will have the the following
color.
If the class ID is five, then it belongs to the bus class and the bounding box will have the following
color.
And if, uh, the class ID doesn't belong to either of these classes, then we will assign that this
following color to the bounding boxes.
Okay, so here I have displayed the initialized Deepsort function where we are just initializing the
Deepsort tracker over here.
And here we have the speed at deepsort configuration of the object.
And we have, uh, where we have loaded all the settings from the Deepsort dot yml file over here.
Okay, so now, uh, what we will say over here is, um, so now here you can see we have the intersect
function.
Okay.
So what does this do?
Okay.
So we are just saying that over here, when the slide, you consider where the center point of the bounding
box, like you can see here, we have the center point of the bounding box and the center point of the
bounding box.
The exact with this line over here, then we will count or we will say that the, uh, volume vehicle
is leaving.
And when the center point of this car coming from here intersect with this line, then we will say the
car is entering the lid.
And when the center point of the.
If the vehicle coming over a car coming from this lane in this sect with this line so that center point
of the vehicle or the car intersect with this line, then we will say, uh, the vehicle is leaving.
Okay.
So when the center point of the vehicle intersect in this line, then you will say a vehicle is leaving.
So if I just open over here, so, like, okay, uh, I can check if two segments intersect.
So there is I found out the solution for the chord over here.
So basically we need to find out how the two lines intersect.
So here we have the intersect chord over here.
So if the two lines intersect so here we have the chord.
So I will be using this piece of code from here.
Okay, so now you can see that I've just added this code over here to find the intersection between
the center point of the vehicle and the line, which I have drawn.
If so.
I will be finding the intersection for the center point of the London line, which have brought it over
here.
So now I have just created a function by the name get prediction.
So uh, what I will say that, uh.
If I just open over here.
So if the vehicle is going into this direction, like this is a north direction.
Okay.
Or if let me just, uh.
So if the vehicle is going into this direction, this is a north direction.
Okay.
And so when the vehicle goes into the north direction, we will say the vehicles are entering.
And if the vehicle goes into this direction which is the south direction, then we will say the vehicles
are leaving the lane.
Okay.
So if the vehicles go into the north direction over here, then you'll say the vehicles are entering.
And if the vehicles go over here, then we will say south direction.
The vehicles are leaving.
And if the vehicles causing the north direction then we'll say the vehicles are entering.
Okay.
So we will find out the direction.
So how we can find out the direction okay.
So let me just tell you how we can find out that direction like in which direction the vehicles are
traveling.
If you go to the drop boxes function.
So over here you can see that we are.
So here you can see that we have created a dictionary by the name data Dash dk.
And uh here you can see that we are just defining it.
DK so DK is basically a list.
Or you can say DK is preferred over list in the cases where we need to quicker in or pop operations.
Okay.
So where we need a quicker in and pop operation where we prefer DK over list.
So DK is just a list and we are just defining the maximum length of this big list will be 64.
Okay.
Over here and in this data DK, we are just appending our center coordinates of the bounding boxes.
Okay.
And in the data DK we are just appending the center coordinates of the bounding boxes.
So let me just, uh, print this out to show you how we will find out the direction.
It.
Let me just run this from the.
It.
The.
So this will take a few seconds.
Um, let us wait for this.
The.
So.
It.
Okay, so I have the data enough.
So let me just show you how the zero.
Okay, so if I just open this up over here.
So now you can see if I just go about about.
So okay.
For here, you can see that, uh, this is basically the unique ID for each of the object which we have.
Okay.
And here we have the dequeue list which you can find over here okay.
And the maximum length of this list is 64 okay.
So now you can see that uh, here we have in the dequeue list, we have more than two different iterations
over here.
Like you can see that if the log here we have added a condition if the length or the data id.
So here you can see that for the ID one the length is equal to two.
Like we have two different iterations over here.
So now what how we can find out the direction okay.
So over here you can see that if the point one is greater than point two okay.
So if the first index of the point one is greater than the first index of the point two okay.
So like this is the first index of the point one.
And this is the first index of the point two.
So over here I'm just passing the data dequeue ID zero and ID one okay.
So this is the data dequeue ID zero.
And this is the data dequeue ID one okay.
So.
Over here.
And we are just finding using the first index which we have defined over here, like we are just considering
out the first index.
So the first index will be this one and this one okay.
So both of these.
So we are saying that if the like here the 783 is greater than 782.
So this means like here you can see that 783 is greater than 782.
So this means the our object or the vehicle or the person is traveling in the south direction.
So if I just show you so this means the vehicle or person is traveling in the south direction which
means the vehicle is leaving.
Okay.
If this, uh, point one is less than point two, like here, the country, the point one is greater
than point two.
So this is traveling the south south direction.
But, uh, let me consider another case where this is happening.
Okay.
Like here you can see that.
So 137 so here you can see that point one is less than point two.
So that you can say that vehicle or the person is traveling in the north direction okay.
So.
What if we say the vehicle over the person is traveling the north direction?
Then we are saying that the person is entering or the vehicle is entering.
When we say the person or the vehicle is traveling the south direction, we can we are saying that the
person or the vehicle is leaving.
Okay, so how we can find out.
Like you can see over here, 783 is greater than 782.
So we are just saying that it's traveling in the South direction because 783 represents the latest represent
the latest iteration.
And this is the previous side.
Like uh so here this is one represent the latest iteration.
Okay.
So if I just open this over here like you can see over here, this is the starting .00.
And at this extreme point we have the higher value.
So the maximum point of the width and the height is basically this point.
This end point okay.
So when we say that 783 is greater than 782 okay.
So.
Like you can see out here.
Uh, if I just see, say, over here, that's 783 is greater than 782.
So this basically means that we are traveling on the higher side over here.
Okay.
Because the previous was 783.
Uh, the previous was 782.
And now the latest was 783.
So we are traveling in the south direction.
Okay.
The higher side, because here we have the maximum weight and the height.
Okay.
And when I say that.
Now when I say that over here.
So like you can see over here, I can say over here where the previous point.
Oh, let me consider the case where we are traveling in the north direction.
Like me.
They are just so over here.
Like you can see that this is 137 and 136.
Okay.
So the latest iteration is 136 and the previous iteration was uh, 137.
Okay.
So when there is 136 uh, so we are uh, just moving towards the north direction because in the over
towards this, our height will be decreasing.
Okay.
So towards this our height will be decreasing in the north direction.
Our height will be decreasing okay.
And thus our direction, our height will be increasing like in the south direction.
We will be, uh, going towards our maximum height.
And in the north direction our height will be continuously decreasing.
Okay.
So like you can see over here, we have 137 and 136 for the latest iteration is 136.
It means that we are going in the north direction and our height is constantly continuously decreasing.
So here the vehicles are entering.
So I have just added the same word over here.
Is the south in direction.
So the vehicles are leaving or the person is leaving.
And if the north is direction then the person is entering over.
The vehicles are entering.
So the same code is being added.
And here we are just finding the intersection.
So when we say that uh.
The center point of this car and this, like, intersect.
Okay.
So then we will just get better direction.
In which direction the car or the vehicle is being, uh, the car, vehicle or person is being traveling.
Okay.
And here I've just displayed the count of above like the leaving count or entering count over here.
So let me just run this complete script file and show you what output are we getting from here?
Oh, let me just.
It.
So now we will be running on the.
Okay.
And I will just write you that image so that I can show you the output as well.
And here we will be using a text box.
For now we will be using S3 dot mp4.
So.
So now you can see that currently we don't like you can see the line drawn over here.
And this is the wrong detection.
Okay.
So now you can see that here we have the center point of this car.
You can see this green line.
Okay.
And here you can see the center point of this car as well.
It.
So let's go ahead.
When the center point intersect with this line, then we will say the vehicle is entering.
And when this center point intersect with this line, then we can say that the car is leaving.
Okay.
So let me just show you how this works.
Okay so I'm using CPU so you can see the processing or the frame rate is very low.
But when the center point intersects with this line, then we will see.
So now you can see the center point as the center point intersect with this line.
Okay.
So the color of the line drawn wide.
And you can see that we have the entering count of the car as one.
Okay.
And when this center point intersect with this line then we will have the leaving count of the car as
one.
And you can say that using a we are doing integrating object detection with object tracking and using
Deepsort algorithm.
Like you can see that we have assigned a unique ID seven to this object to this car, we have assigned
a unique ID two to this car.
We have assigned a unique ID 15 to this car.
We have assigned a unique ID 16 to this car.
We have assigned a unique ID to this type card.
So this is what we do in object tracking.
Now the object tracking we assign a unique value to each of the detected object.
And then we track that object throughout the entire frame okay.
Oh, I'm just waiting for this car to intersect with this line so that I can show you the living count
over here as well.
Now you can see that as the center point intersect with this line.
Then we will see uneven count displayed over here as well.
Okay, so now you can see the living count of card.
So in this way you can count the vehicles entering and leaving our lane as well.
So I will just test on other video as well.
So before testing on other video like for the person counting, uh, let me just make one change the.
So I'm just so here that different coordinates with persuading the video frame.
Okay.
So plus over here the line coordinates will also change or the dimensions of the line will also change.
These are the starting point and this is the ending point of the line if.
And now I will just writing test walk.
Okay.
And this is what the person.
And so let's run this and let's see if you are able to do person counting and entering or leaving lane
or not.
If.
Oh, yeah.
You can see we have the video over here.
Yet.
Rod.
You can see here we have the lane, the green lane.
So when this person intersect with this line we will see a leaving cone displayed over here.
So let's see.
Order.
So as this person intersect with this line and we'll see a living cone.
And when this person intersect with this line we will see entering.
So this person is traveling in the north direction.
And this person is traveling a south direction.
So in the south direction we'll have the living cow.
And in the north direction we will have the entering cow.
A.
And you can see using object tracking, we have assigned a unique ID 517, 21 2519 1013 eight to each
person.
So let's see.
Okay.
Okay, so now you can see we have the entering out over here.
And as this person intersect with this line we will have the leaving out should be over here.
So now you can see the center point intersect with this line.
Now you can see that we have the leaving count because this person have also crossed this line.
So two person simultaneously crossed.
We have the leaving count of person two and the entering count of the person as one.
So now you can see over here we are able to complete the application where we are doing persons counting,
entering and leaving a lane over the vehicles, counting and finger leaving a lane.
So that's all from this tutorial.
Thank you for watching.