yolov8 multiple vehicle counting | track & count multiple objects using yolov8 | computer vision

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hello friends and welcome to YouTube channel Freedom te and in this session what we are going to learn in this session we are going to use YOLO for object detection tracking and Counting we are going to detect multiple vehicle class also we are going to track multiple vehicle class also we are going to create a counter for multiple vehicle class so before we move to our practical friends if you learn something from our videos please consider to subscribe our Channel okay friends thank you so much and let's get started so friends as I mentioned today we are going to use yolow V8 pre-train object detection model for detecting a car class then we are going to detect a bus class also we are going to detect a truck class then we are going to use our tracker for tracking car bus and truck and then we are going to count the frequency for going upside also for going down downside for car class for bus class also for the truck class so for that this is Windows 11 machine of course you can use your Windows 10 machine also so let's just start with package installation simply open Tony python IDE then go to the tools manage packages and search for open CV hyen python open CV hyen python first package select it click on install button that's it it will install open CV hyen python then we need ultral litics so ultral litics just search for ultral litics hit enter first package select it click on install that's it it will install ultral ttic on our Windows 11 machine same steps for Windows 10 machine so CV Zone next package hit enter first package CV Zone click on install button that's it it will install CV Zone on our Windows 11 machine so this is how we need to install open CV Hy Python ultral litics and CV Zone package for this project done now simply for today's session I have create a new repository I will mention the link inside the description box you need to Simply copy paste the link inside the browser and the repository name is Yolo at multiple vehicle class simply go to the code and click on download zip and it will download our ZIP format repository simply open download folder this is what our repository right click when RAR and extract with the folder name go inside the folder again we have same folder name and then we have our files so first we need our video file so VI .txt text file open inside that we have our uh video link copy the link close the file and open browser and open new tab and control+ V it will paste our link and then just hit enter it will open Mega Cloud link where we have our video file so simply click on download so file I have already download so that's why it say just save so click on Save in your case it says download so just click on download button and download our video file done now simply move video file from downloads right click and cut and move the video file from downloads to our repository paste it done now simply let's just first watch our video file and as you can see there is a road there is a traffic also on the road so we have here car class as you can see there is a car class which basically going upside so this is what our upside traffic and then we have downside traffic as you can see there is a car which basically going downside upside traffic downside traffic so we have both side traffic we have both side car class as you can see there is a car going and coming both side there is a steel car car class and then as you can see there is a bus there is a bus on going downside so we are as I mentioned we are going to detect our car class also we are going to detect our bus class then we are going to track a car class for both side for going downside and for coming coming side upside so same for bus class we are going to detect bus class then we are going to track the bus class for both side and then in this video we have also truck so as you can see there is a truck simple so same way we are going to detect our truck we are going to track the truck also we are going to create a counter for truck bus and car class for both side for going downside and for coming upside so this is what our scenario our video file now let's just start our code so let me close the video file and I have mentioned the basic code because I have explained the basic code for YOLO V8 in several previous video so I have created a playlist simply watch the playlist then you will get the idea how to use YOLO V8 for object detection with the help of python and open CV simple so in main Ed dop I have mentioned the basic code where we have our uh single detection our single class detection single class object detection with the help of YOLO so this is what our basic code simple and then as you can see this is what our detection object detection so we have coordinates rectangle coordinates for drawing the rectangle when we detect our classes when we detect our vehicle classes so X1 y1 X2 and Y2 is there and then here it is as you can see I have mentioned the condition because we are not going to detect only single class which is car we are going to detect here multiple vehicle classes so we want to create a list for each class separately means suppose I want to detect a car so I want to create a car rectangle coordinates when we detect a car we want to create a separate list list for a rectangle coordinates so here it is as you can see I have mentioned here it is what our coordinates X1 y1 X2 Y2 with the help of our uh yolow at pre- Trend object detection model so then this is the c c is basically our class list so our class list is here as you can see this is what our class list variable which represent our coco. txt file a classes file simple so if if we detect a car if there is a car in C so C is basically our class list so if we detect a car in our video we are going to create a list which is list do append and inside that we are going to append our rectangle coordinates so now here it is as you can see I have mentioned the list so in this list we have only car rectangle coordinates means because we mention here a condition if the there is a car class only then we are going to append all the rectangle coordinates of the car class so if there is a curreny list do append and X1 y1 X2 and Y2 list so in this list we have only a car rectangle coordinates simple then Al if if we detect a bus from our video file if we detect a bus then again we are going to create list one new list list one. append and again simply we are going to append our all rectangle coordinates so in list one in list one we have bus rectangle coordinates the X1 y1 X2 and Y2 and then the last one our truck class so if we detect a truck again we are going to create a new list which is list two and inside that we are going to open X1 y1 X2 and Y2 and this coordinates we are going to save inside our list two so the list only for car class list one only for bus class and least two only for truck class that's it now simply this is our detection the object detection with the help of yate pre-trend model now we detect our object now we want to track our objects for that we have our tracker so if we want to use our tracker we want to send our detected object rectangle coordinates in our tracker for that simply as you can see bbox idx is just a variable bbox idx is equal to our tracker variable here it is as you can see our tracker variable this tracker variable represent our tracker class from our tracker file which I have mentioned inside our same repository as you can see tracker. Pi this is the file so from tracker this file we have our tracker class so here here tracker is just a variable which represent our tracker class as you can see T is capital so tracker that's it so now we have our tracker variable ready so we can simply call our tracker variable bbox idx is equal to tracker do update function from our tracker. PI file we have update function so bbox idx is equal to our tracker variable do update function and inside that if we want to track our car class simply we want to mention our list because the list as I explained already this list is dedicated for only car class so if you want to track a car class we want to send our car class rectangle coordinates inside our tracker for that Leist simply mention like this way tracker. update and pass the list now we successfully send our car class rectangle coordinates inside our tracker now tracker will again track that object and it will assign the unique ID for object means it will again create a new rectangle coordinates also it will add a unique ID for car class so for that simply we are going to use a for Loop for bbox is just a variable so for bbox in bbox ID X so for bbox in bbox ID X now as I mentioned now we will get new rectangle coordinates along with unique ID simple so X3 Y3 X4 and y4 new variables for rectangle coordinates X3 Y3 X4 y4 and then id1 is for the ID all this is our B box that's it now we need a center point for our car class because when we detect our object we have rectangle then we need a rectangle center point because we want to create our counter for that we want to mention a condition so for condition we need object center point so cx3 just a variable cx3 in X3 + X4 divided 2 this is how we will get our cx3 and then cy3 in Y3 + y4 /2 this is how we will get our cy3 so we have now our cx3 and C Y3 which is our Circle point so now with the help of this we can draw our Circle as you can see CV2 do Circle method and cx3 and cy3 then radius color and because we want to fill our Circle so mention minus one as simple as then we we have our rectangle coordinates so C2 do rectangle method X3 Y3 X4 and y4 then the color pink color and then the thickness of our rectangle which is two then we are going to put our car class ID means we have now ID for each car so we are going to put our ID on our car rectangle top left corner top left corner here it is as you can see the rectangle top left corner is basically X3 and Y3 that's it so now we have a car detection also we have car tracking so let's just start our code first now it will download our pre-ra object detection model then it will detect a car class also it will track a car also it will assign the unique ID for each car because we mention here because we mention here simple so now as you can see it's now downloading yellow at s. PT which is pre-train model so he successfully download and then as you can see there is a car uh coming upside here it is as you can see and we have a rectangle coordinates a center point which in uh which is basically in blue color and then on rectangle top left corner we have unique ID for this car we have three for this carve we have four there is a Center Point rectangle so here here it is for this side also for going Downs side also we have car there is a Center Point blue color Center Point and there is a unique ID which we assign with the help of our tracker for each car for both side for both side we are now detecting our object we are now tracking our object also there is a Center Point done so we are going to start a detection tracking both side using a single class simple so let's just start step by step so we detect our car class we track our car class now we want to create a counter for both side so let's just say I just want to First detect a car which basically go upside so I want to create a counter for going upside only for car class simple so we detect a car class we track our car class that's it now here it is as you can see I have mentioned here two line two line with the help of C2 do line function I have mentioned here two line so green color line as you can see the C2 do line green color line 0255 is our first line let's just say first line and red color line is basically our second line simple so let me uh freeze a our frame save the code run the code so we started our frame so with the help of our mouse event function as you can see I have mentioned here mouse event function in code here it is this is the mouse event function mouse event Mouse move function basically c. event Mouse move this is the function which when you move your mouse on your frame on the frame like this way I'm moving inside the shell as you can see inside shell we have X and Y coordinates of our mouse cursor for particular point so let's just say I want to draw a line so if I want to draw the line like this which I have already draw on the frame green color line so I need to Simply move my cursor over here here and then inside shell as you can see there is a coordinates which is 1 and 184 so one is basically our X and 184 is basically our Y coordinates so how do we draw our line simple for drawing our line we need start Point XY coordinates and we need end point XY coordinates so this is what my start Point XY coordinat which is 1 and 184 so I have mentioned like this way as you can see C2 Line 1 and cy1 so the cy1 is basically our coordinates our coordinates y coordinat so here it is as you can see C y1 is basically 184 so instead of mentioning the digit I have mentioned cy1 simple instead of mentioning the 184 number I have create a cy1 because we are going to use this cy1 for our condition for our if condition so simply mention our first line C2 do line y coordinate y coordinate like this way you have to mention y-coordinate over here create a new variable which is cy1 and mention the Y coordinates number which is the 184 in my case so 184 cy1 so instead of 184 we are going to mention here cy1 simple and then this is the end point of our line this one so if you move your mouse cursor over here you have 108 and 183 so 108 and instead of mentioning the Y coordinates simply mention C y1 because we want this both Y coordinates same so instead of mentioning the number simply mention number the Y coordinates number over here here it is 184 and mention the number as cy1 and then simply mention cy1 for both start point and end point the Y coordinates cy1 and cy1 same for the second line as you can see same for the second line you will get the coordinates XY coordinates for start point for end point XY coordinate so instead of mentioning the number for Y coordinates I have mentioned the Y coordinates same way 209 is basically y coordinate of our second line which is red color and I have mentioned C Y2 is basically our Y coordinates 209 and instead of Y coordinates I have mentioned cy2 for both side for start point and for end point simple I hope you all clear so this is how this is how I have draw here a line which we are going to use for creating a counter basically this is what my region of Interest area this two line is basically my region of Interest area means when we have Center Point as you can see if I skip the frame this is what my object and it has a rectangle also it has a center point also we assign the unique ID for our object which is car class so if the object rectangle Center Point when this Center Point touch my first area means first line which is in green color line if this Center Point touch a green line then only we are going to start our detection then only we are going to track our object object otherwise we are not going to detect our object for that we create our tool line because this is how we can say there is a detection there is a tracking and then it is really easy to create a counter for multiple vehicle classes simple so if the center point touch our green color line simple so if the center point touch our green color line in that that time simply we are going to save this car ID which is zero also this car center point of coordinates which is XY coordinates so when this car touch our green color line we are going to create a dictionary and inside that dictionary we are going to save their coordinates their current position their current position means CX 3 and cy3 is basically our Center Point uh this car center point so we are going to save their Center Point and their unique ID when this car rectangle Center Point touch our green color line so for that I have create here a dictionary for all classes I have already mentioned the dictionary for going upar class we have mentioned up car dictionary so for downside I have mentioned down car and the dictionary then for bus as you can see down bus dictionary then up bus there is dictionary and then we have truck also down down truck as you can see down truck the dictionary there is no truck is basically a coming upside so I have not mentioned here any up truck dictionary but suppose if you have different scenario and in your case there is a truck also coming upside you can same way mention the up truck dictionary and inside that dictionary as I explained inside that dictionary we are going to save when our object Center Point touch our first line in that time we are going to save their current position and their ID inside all these dictionary for each classes we need to mention separate dictionary for car class mention separate dictionary for bus class mention separate dictionary for truck class mention separate dictionary for both side for both side means for coming upside mention separate dictionary for going downside mention separate dictionary which I have already mentioned here in the code simple now I have explained all these things now we are going to start our practical so we have our center point so simply if the center point touch our green color line so here this is what our detection as you can see we are tracking our car class so now first condition if our car Center Point touch our green line so for green line we mention cy1 cy1 is for the green line so simply also we need here offset so I have already mentioned the offset value for8 that's it now let's just start our code so here if first we are going to create a counter for going upside only for car class only for car class going upside okay so if if cy1 cy1 is for green color line which is our first line so when car want to go upside first it will touch our green color line as you can see first it will touch our green color line then the same car will touch our red color line so if cy1 if it is less than our cy3 center point of our rectangle which is cy3 so mention cy3 cy3 plus offset which we already mentioned here uh here it is offset as you can see so offset and cy1 if it is greater than cy3 minus offset if cy1 less than cy3 which is our rectangle Center Point for car class plus offset and cy1 if it is greater than cy3 minus offset this is what our condition the condition the meaning of this condition when The Car Center Point touch our green line then only we are going to draw a center point then only we are going to draw a rectangle then only we are going to put our ID on our object rectangle top left corner now Simply Save the code and if I run the code so as you can see there is a car but there is a no detection there is a no tracking there is a no ID for this car because this car is not crossing our first line which is green color line when this car Center Point touch our green color line in that time only we have rectangle Center Point and ID so let's just keep the frame so I'm skipping frame and when this car Center Point as soon as it's touch the line then as you can see we have pink color rectangle we have blue color Center Point and we have unique ID for this car which is zero simple then again when the car cross our first line again there is no detection and nothing simple so as I explained previously this is what our first condition when Car Center Point touch the green color line which is the first line only that time we have detection and all other things so now the next next condition what is our next condition when car touch a green line which is the first line in that time we are going to save their ID and their current position in our dictionary which we create for going upside only for going upside not for downside simple so we create upside dictionary for car class is up car so inside the dictionary we are going to save their current position and their unique ID when car touch our green color line first line simple so let's just say here this is what our condition after that we want to save their ID and their current position so call the dictionary upar upar this is what our dictionary name cross check up car okay up car up car then what we are going to save we are going to save ID 1 id1 is for car class so upar id1 is equal to is equal to our Center Point our Center Point is basically the current position of our car car class when car touch our first line the current position is basically their center point so simply mention cx3 and cy3 done now if you go here and if you print our dictionary which is upar let just save the code and if you run the code so now there is nothing because the car center point is not crossing our first line and inside shell as you can see there is a empty dictionary there is a empty dictionary and when Car Center Point touch our line first line which is in green color in that time as you can see now inside dictionary we have zero ID for the car and their Center Point their current position when car touch our green color line that's it so we are successfully saving their ID and their current position inside our upcard dictionary that's it now what is our next condition same condition we are only going to now cross check that the same ID is touching our second line means we are saving our car position and there unique ID inside our upcar dictionary so from upar dictionary we are going to cross check that the same ID which already uh we save inside our dictionary if the same ID is crossing our second line or we can say second area which is in red color so for that from dictionary we are going to call our ID so here after that if the ID one if the ID one which we assign for car class if the ID one in our dictionary upar dictionary means we are going to cross check if the ID is available inside our dictionary only those ID we are going to cross check otherwise we are not going to cross check any other IDs simple so if ID one inside our upcard dictionary the same ID we are going to cross check when The Car Center Point touch our second line so for second line this is what our condition for Center Point touch the line so same condition only we are going to change here a line number so this time we are going to mention our second line because car is already touched our first line which is the green color line so C y1 is basically green color line and the cy2 is our red color line and then same cy3 cy3 the center point and then after then after we are going to draw all these things now what will happen when our car Touch first line which is green color line in that time we are going to save their unique ID and their current position and then the same car touch our second line after that we are going to or not after that basically in that time when car touch our second line in that time we are going to draw a circle we are going to draw basically Center Point and their rectangle and then we are going to put id1 on the car top left corner that's it so if I save the code and now let's just start our while loop save the code and if you run the code so now watch nothing is there when car touch our first line we are saving their ID and their current position also same car cross our second line in that time we have rectangle and all other things so watch and as you can see there is a pink color rectangle and blue color center point also we are saving their ID inside our dictionary here it is as you can see we are saving their ID and all other things so now now simply we create a condition now we can simply create our counter so for upside counter for car upside counter we create counter up and list and inside this list we are going to save the car ID because our car completed our both condition and then we we know that the same car is basically crossing our second line so we can simply say the car is basically going upside so here simply we can say we create here our list which I have already mentioned here as you can see uh counter car up so this is what our list so counter car up counter car up and what we are going to append inside this list we are going to append id1 for car class for going upside and then because there is some time for crossing our both area from green color line to red color line it will basically count a same IDE again and again so for that if counter car up if counter car up. count what we are counting we are coun in ID 1 is equal to is equal to Z means don't count same ID again and again that's it now if you go here and if you print here counter car up counter car up and let's just save the code and run the code now watch the list is right now empty but when we have first car it will save their ID as you can see for first car we have zero ID zero ID it's inside our list car counter up list then we have second car their ID three we have next car and their ID so this ID is in a list so if you mention the length of list is basically our counter length of list is basically our counter so mention the length counter car up run the code now inside shell we have count right now zero first car we count one car as you can see inside shell we count one car so now we are counting going upside car class so now simply let's just put our counter on the frame so copy the czone put text method and uh here mention the method and now our counter length counter car up we want to mention here a variable so let's just say C up car up is equal to length of counter car up so here we want to mention a variable let's just say up car up car and this then we want to mention inside this C cup C cup this is what our counter this is just a variable and then we want to mention a coordinates of the frame where we want to put our counter on the frame so let's just say 50 60 and two and two all is good save the code if I run the code and as you can see we put our counter car counter for going upside on our frame so we count one car which basically go upside one car now we have second car so we only count one car two and then three so we successfully create going upside counter now same way only we are going to reverse the condition means for going down side the car first will touch our red color line then the same car touch our green color line so let me explain here if I mention zero it will freeze our frame so for going upside the car will touch our green color line first then we are going to save their ID and their current position inside the dictionary and then we are going to call those ID for cross checking if the same ID touch our second line then we are going to create a counter same way for going downside only the if if the car want to go downside first car will be touch our red color line then we are going to save their ID inside the dictionary and then again we are going to call those ID for cross cheing if the same ID is touching my first line which is green color line and then we are going to create create a counter same way only first red color line saving the ID inside dictionary and then call those ID and then we we are going to cross check if the same ID is touching our green color line which is the first line same way so let's just mention here like this way we we have done with upside so car down car down now simply copy all the code from here from condition copy it check it is in line it start from here and then just press control+ V cross check if it is in line or not okay it's in line so as I mentioned this is for down side so for downside car first touch our second line so instead of cy1 we are going to first mention cy2 then the same Center Point same center point so there is no need to change the center point only change the line first it will touch our second line red color line so cy2 and all the things are same and here also cy2 and then of course for going downside we create a dictionary so for going downside the dictionary name is down car so mention the downar here down car down car and we are going to save ID one that's it id1 and their Center Point and then we are going to call those ID from our downar dictionary downard dictionary and then if now we are going to cross check if the same ID is touching our first line for going downside so instead of cy2 cy1 cy1 and then we are going to draw Circle and all other things only what we are going to do we for our knowing purpose we are going to change the color when the class when the vehicle class is basically going downside so car class we are going to change Circle Center Point in Pink So 255 0255 and then the rectangle color we are going to make a blue then it will easy to detect uh not detect basically it will easy to recognize that our code is perfectly working or not and then we are going to put our id1 on our rectangle top left corner X and Y3 and then we have our counter car down counter car down list here it is as you can see I have already mentioned counter counter car down list list and inside that list when our class when our car class completed our both condition for going downside we are going to save their ID inside our counter car down list same same way so counter car down count ID one and here also counter car down counter car down and the condition same way please don't count same ID again and again now uh same way here create a new variable C down car down and the length of our length of our counter car down our list where we are saving their ID so length of our counter car down we are going to put our counter car down on our frame so just copy paste czone method only we are going to change some variabl so upar we have we are going to mention down car and uh C cup we are going to mention C down and then we want to change the coordinates frame coordinates so 51 60 and the thickness and rectangle size are same so just save the code and just run while loop save the code and let me cross check which is all good okay it's all good let's just start our code now we have both side counter for car up car we count down car oh there is a type of mistake where is our down car down car down car down car is basically our dictionary save the code run the code so we have both side counter on our frame up car we count one down car there is no down car zero 2 three up car we count three car now down side 1 2 3 4 5 6 7 8 as you can see we are successfully counting both side cars friends we are successfully counting both side car for going downside also for coming upside so same way now only we are going to call our different different list for different different vehicle classes so same way so we have done with car class for for both side counter now let's just start for bus counter so let me create here like this way first uh let's just say upside bus up bus up bus and here now as I mentioned for bus we create list one so inside this list one we only have the bus rectangle coordinates so now for just we want to track our bus coordinates rectangle coordinates then we want to assign the unique ID for bus class so let's just say here because we mention same way for bus class again we want to create a new tracker so tracker one is for our bus class so tracker one and tracker and then here we are going to mention here bbox idx1 this is for our bus class variable bbox idx1 is equal to tracker one variable which we dedicated for our bus class update uh tracker 1. update update update so tracker 1. update and inside that we want to pass list one because we dedicated list one for bus class inside that list one we have rectangle coordinates when we detect the bus we have rectangle coordinates so list one now simply bbox one idx1 or you can simply mention here like this way instead of bbox idx1 we can simply say bbox one idx okay it's really good so now simply we are going to call our bbox one like this way using for Loop so here let's just cross check our Point starting point is here here for Loop so here simple so for again we already mention here B box B box for car so now we are going to increase the variable so for B box one for b class for bbx one in B box one idx bbox one idx this bbox one idx so for bbx one in bbx one idx for B box one in B box one idx let's just cross check if it is in line yes it is in line it's good and then we are going to Simply now as I explained previously now we will get new coordinates with the help of tracker also we will get the ID unique ID for bus class so again we mention here X3 Y3 X4 y4 and id1 so we want to increase the coordinates so let's just say X5 y5 X6 and Y6 and then id1 instead of id1 again we are going to increase the ID variable so id1 is which we already dedicated for car class so id2 for bus class as simple as friends say same condition only we want to change some variables increase some variables that's it and all these things is basically our bbox one B box one now simply we can draw our rectangle and we can we can simply create here A Center Point also so let's just first create a Center Point coordinates so we mention here cx3 and cy3 so this will be CX4 is equal to int X5 + X6 divided by 2 and cy4 is equal to int y5 + Y6 divided by 2 now we can simply draw a rectangle and all other things so just copy it from previous code copy it and just paste it and just change the variable aable so here let me make in line so C2 do Circle instead of cx3 we are going to mention now CX4 for bus cy4 and then X3 will become X5 Y3 will become y5 X4 X6 y4 Y6 and this id1 we are going to mention id2 X3 and Y3 will become X5 and Y 5 now it first it will detect our bus then we mention here a Tracker method now it will track our both side bus so if I save the code if I run the code so our frame is started we already done with our car class for both side now now let's just wait for bus class so friends as you can see there is a bus and there is a rectangle and there is a ID and there is a center point it means we are successfully detecting bus we are successfully tracking the bus there is a unique ID for both sides so now there is a bus only the going downside now the bus will basically come uh from uh upside also and bus is coming and it's detected there is a center point and there is a unique ID it means we successfully we are successfully detecting our second class we we detect our first class which is car class now we are detecting our second class which is bus class now same way first let's just count a bus side a bus class okay same way when the bus Center Point touch our first line we are going to save their unique ID and their current position inside our dictionary so for going upside we create a dictionary and the name of dictionary is basically up bus as you can see inside this up bus dictionary we are going to save the bus current position and their unique ID when the bus basically go upside simple so here up bus so we have Center Point here so let's just first create our condition when the bus Center Point touch our green color line same way if cy1 if cy1 if it is less than if C y1 if it is less than our cy4 our cy4 which is our bus Center Point cy4 plus offset and cy1 if it is greater than cy4 minus offset then we are going to save their ID and their current position inside a bus dictionary so here this is the condition whenever Bus Center Point touch over green color line which is first line after that up bus this is what our dictionary abas and then what we are going to save we are going to save their ID and their current position so their current position is basically CX 4 and cy4 simple now inside upb dictionary we are saving their ID and their current position so now simply we are going to call those ID here we want to mention id2 id2 for bus id2 we are saving id2 inside our up bus dictionary so now we are going to cross check if the same id2 which we assign for our bus same id2 is crossing our second line which is the red color line for going upside so for if id2 id2 in our up bus dictionary if id2 in our Abus dictionary only those ID will we are going to cross check for our second line so just copy the condition and only we are going to mention here our second line so our second line is basically cy2 cy2 and all other things are same and here also we want to mention cy2 after that we are going to draw a circle we are going to draw a rectangle we are going to put our text and here we want to mention our color so so for going upside uh for going upside we mention blue color for Center Point and the pink color for rectangle so same color for bus side also bus going upside so here the center point will become a blue so 255 0 and the rectangle will become Pink So 2555 255 and then now we know what what is basically happening here so we are going to Simply Save their ID inside our counter so for going upside we have we have a counter counter bus up as you can see I have mentioned counter bus up and the list so when our bus completed our both condition we are going to save their ID inside counter bus up counter simple list basically so here we match our all condition so counter counter bus up this is what our counter bus up. upen and what we are going to open we are going to open id2 and as I mentioned in previously it will count same ID again and again so for that create the condition if counter bus up if counter bus up what we are counting we are counting here ID so id2 for bus is equal to is equal to zero means don't count same ID again and again and then now simply here we are going to mention a variable with variable with a length of our counter bus up so C let's just say C what we are going to mention we can say here C Bus Let's just say C bus C bus up counter bus bus up so C bus up you can mention any variable so C bus up length of our counter bus up length of our counter bus up and then simply we are going to put our counter on the frame so here we mention 50 60 so what we are going to do first let's just comment our put text metal for counter let's just freeze our frame because we want to know here um if cy2 where is if cy2 I forgot to mention here like this way this is the if condition okay so save the code and run the code so we mention here up car and down car uh counter over here so let's just mention uh here for our bus counter let's just say over here so 79247 79247 this is the coordinates 7 792 and I forgot it what is the coord 7 here let's just say over here uh 794 and 43 let's just say 792 and 43 it's okay and then uh we are going to change the variable so now uh bus bus up let's just say bus up and then here we want to mention our counter variable so our counter variable is basically C bus up C bus up that's it so if I save the code if I run the code it's okay so we have now bus up counter so let's just start our while loop if there is error we are going to Simply cross check our code but now let's just start our while loop so we we already done with our car class so friends as you can see there is a bus which is basically going downside but it's not detected it's not because we create a counter for bus only for upside and this bus is basically going downside so it's not detected it's not count as you can see bus up zero because we create a counter only for going upside for bus class so there is no bus is basically coming upside right now so when there is a bus coming from upside Road from this road then only it will count bus up still there is a zero there is a zero as you can see so friends as you can see there is a bus on upside track of s road when it will cross over both condition is detected and we count bus up one it means we are successfully counting car class and bus class for going upside now same condition only we are going to reverse for going downside bus so let's just say over here down bus down bus and then only we are going to change our condition so let's just copy it from if cy1 to our uh where it is from here just copy it is copy as it is copy it and just check it is in line simple so we copy our code now only we are going to change our condition so for going downside Bus Center Point first touch our second line which is red color line so instead of if C y1 if cy1 mention if cy2 then all the things are same and here up bus we are going to change our dictionary which I have mentioned here down bus simple so down bus this variable you can change I have already mentioned all these dictionary and counter list inside the code you can change as per your requirement so down car where is the here at the end here it is up bus now down bus down bus and then id2 and all the things are same then if id2 and down bus then we are saving their ID for going downside we are saving bus ID inside our down bus dictionary then we are going to call those ID and we are going to cross check if the same ID is touching my first line which is the green color line for going downside the bus class so if IID to in down bus then our next condition so here we mention second line for going downside then the same bus ID will touch our first line so if cy1 and then we are going to draw a circle rectangle and we are going to change our Center Point for going downside with blue width pink and the rectangle we are going to make pink with blue and then uh all the things are same and counter bus down counter bus down and here also counter bus down counter bus down it's all good and then here we want to mention C bus down this is just a variable you can change the variable C bu down is equal to length of our length of our counter bus down counter bus down and then simply we are going to use our Sone put text method for putting our counter on the frame for bus downside so let's just cross check because we want to mention the frame coordinates so if I start the code and let's just say over here so 78673 7 so let's just say 792 we mentioned for bus up and this we can [Music] say 150 no 150 basically let's just cross check not 153 if I mention here 43 so let's just say 50 if I start the code not there if I go over here 96 okay let's just mention 100 okay now it's there the counter is there now simply we want to change our counter variable so this will become bus down bus down and then C bus up we are going to mention C bus down C bus down that's it now let's just start our while loop start the code so let's just watch we have done with car class for going upside for going downside we are done with bus class for going upside also for going downside so now let's just watch a counter we are counting a both side car you can cross check the counter we count up car five down car 12 there is no bus upside there is no bus downside 27 28 car already count for downside and now there is a bus going downside as you can see it's detected bus down one we count one bus for going downside and we already count bus up which is the one bus for this side so we successfully counting here a multiple vehicle class so same method for truck class class friends so I hope you you use the method and you will create a truck class for both side for both side same way same method and then you can create a truck class or you can simply detect the truck class also you can track the truck class also you can create a counter for truck class for going both side for upside and for downside so friends this is how we can use YOLO for multiple vehicle class detection tracking and Counting I hope you will learn something from this video we'll meet our next video till then thank you take care and bye-bye
Info
Channel: FREEDOM TECH
Views: 4,071
Rating: undefined out of 5
Keywords:
Id: G-FyFVwgDk8
Channel Id: undefined
Length: 67min 38sec (4058 seconds)
Published: Thu Dec 28 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.