People Counting System (Shopping Mall) | yolov8 object detection & tracking & object counting

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hello friends and welcome to YouTube channel freedomtech and in this session what we are going to learn in this session we are going to create a people counter for shopping mall 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 we are going to create a people counter for shopping mall with the help of yellow V8 for that first you need to install Tony python ID then opencv and you allow V8 on Windows machine this is what Windows 11 of course you can use your Windows 10 machine also so I have already created a video how to install opencv how to install YOLO V8 how to install Tony python ID on Windows machine I will mention video link watch video and just install all these basic models then we are going to use here our tracker so I already get the video how we can use yellow V8 uh with opencv and python for object detection also how to track the object with the help of tracker okay so I will mention videos link watch video then you will get the basic idea so as I mentioned for today's session I have created the basic code where we have object detection with the help of yellow we had pretend model also we have tracker okay so for today's session I have created a repository and the repository name is Shopping Mall exit and enter counting okay so I will mention the link you need to Simply copy and paste the link inside the browser then go to the code click on download zip and it will download zip format repository then go to the show in folder this is what our repository just right click when there are extract to folder name and this is what our folder again same folder so first we need our video file so just open download.txt copy the link open the browser and new tab and press Ctrl plus we just hit enter it will open the cloud link where we have zip format folder and inside that folder we have our video file so let's just click on a download so friends we have successfully download our folder so just go here click on show in folder then right click and first we need to Simply move our folder inside our main repository folder so let's just cut and paste then right click and WinRAR extract here so this is what our video file so let's just play our video file then we will get the idea so friends as you can see this is what a shopping mall and this is the entrance automatic sliding door ah from this door people will basically ah go inside the mall also exit from the mall simple so this is whatever ah region of Interest area where we want to count the people frequency means we are going to create the counter for exit and enter simple so let's just play the video file so when the person in front of the Dover the door will automatic open because this automatic sliding door as you can see this person is in front of the door and door is automatic open and the person is basically exit from the mall okay so our goal is what we want to detect the object with the help of yellow weight we want to track the object also we want to create the counter for exit and enter basis okay so watch for this person this person is basically entering the mall okay he's front of the door then door will automatically open now he's entering inside the mall so this is Whatever video file ah so as I mentioned I have already created the basic code where we have detection with the help of yellowware also we have our tracker it means we have uh ID for each person each person we have unique ID so we can simply ah track the person OK so let's just start our basic code so main dot Pi here it is I have mentioned tracker dot Pi which is of which this the file which we are going to use as a Tracker and we have our coco.txt file which is the class file so let's just open main dot pi as I mentioned I already explained all these things in previous videos so I am not going to again explain how to use tracker and how to use the object detection with the help of opencv and python okay simple so here it is as you can see this is what our rectangle object rectangle then we only want to detect here a person so simply we can create the condition if there is person in C so C is basically our coco.txt file ah here it is as you can see we have here coco.txt file read function as you can see so this is how we can simply read the coco.txt file and of course if there is a person we we want to use our tracker we want to call our tracker so simply for tracker we need ah the rectangle coordinates so rectangle coordinates is basically each object coordinate so we are going to send our x one y One X two y two our tracker file so for that we need to create the list so list dot append and insert that will to pass x 1 y 1 x 2 and Y two as you can see I have passed then we are going to use our tracker so with the help of tracker ah inside tracker we have update function I already explained all these things in previous videos so of course we are going to update the list then again with the help of tracker we will get again the rectangle coordinates and the new coordinate is basically the ID it will assign the ID for each person simple so x three y three x four y four is the new coordinates with the help of our tracker and we have ID all this is basically our big box now simply we can draw the rectangle ah of course we need here ah rectangle bottom right corner and then we have switch Zone dot put text method which basically put the idea as a text on rectangle uh top left corner ok so this is the basic code and we have then region of Interest area but first we only ah run the object detection and tracker so that's why I have ah comment the C2 dot pole lines function which basically we are going to use for ah mentioning our region of Interest area so let's just start our code first it will be it will basically download our a pre-trained model which is yellow V8 s dot PT then of course we have our object detection and as we mentioned our tracker so of course we have ID for each person also we assign the also we also we show idea as a put text method with the help of CV Zone on rectangle top left corner okay so our frame is started now when the person is basically out from the shopping mall we have rectangle and we have ID and as you can see friends as I mentioned we have rectangle and zero is the ID for this person 0 is the ID for this person it means our object detection and our tracker is perfectly work so let's just watch a next person which basically ah want to enter the mall so here it is as you can see this person is also detected as object with the help of yellowware also we have tracker means we assign the ID with the help of our tracker so now we have as you can see the eight is the ID ok so we successfully assign the ID we have detection and all things we have done simple now let me freeze the frame so we have basically first frame so this is what our first frame so let just give some frame so friends as you can see now door is open person is detected we have ID so this person we have zero and as I mentioned uh we want to count uh we basically want to create the counter for exit and enter simple so for that what we want to do we want to create here our region of Interest area and in that region of Interest area if the person rectangle bottom right corner so as you can see I have highlighted the bottom right corner with the help of blue color circle here it is as you can see we have blue color circle so we can simply create the condition if the object rectangle bottom right corner if it is inside our area then only we want to detect the object otherwise don't detect the objects because we only want to detect the object in this area this is whatever region of Interest area for that for that I have create a C2 dot polylines function ok so if I start the code if I run the code so friends as you can see uh the red color polyline is basically our first area and the green color polyline is basically our second area so how to draw the polyline simple we have inside this code we have Mouse function okay as you can see this is what our Mouse function so with the help of mouse function when we move our Mouse on our frame inside shell we have X and Y coordinates as you can see inside cell we have x and y coordinate so if I want to draw the poly lines I need four points X Y X Y okay so if I want to start from this so simply move the cursor over here and inside shell you will get the coordinates ok so right now we have seven one one and two three nine so simply you need to mention this point like this way I have mentioned it here it is as you can see area One X and Y coordinates for first point for this point x Y coordinates we have here I have mentioned then second point then third point and then four point so this is how you need to mention the point for drawing polyline with the help of our Mouse function okay so same for next area you need to Simply move the cursor on the frame where you want to start the polyline point and simply mention the points like this way ok so this is how I have mentioned Area 1 and area two then simple with the help of C2 dot polylines we can simply draw the poly lines like this way NP dot array area one NP dot n32 through the color red and the thickness same for area 2. that's it now we have our area ready now as I mentioned we only want to detect the person if the person ah rectangle bottom right corner if it is inside our first area for that we have C two dot Point polygon test method I have explain all these things in previous videos ok so if you watch the old videos then you definitely get the idea so simply we are going to use here our Point polygon test method so where we have x three and Y three simply create the condition uh not condition basically first we want to create our method so results is just a variable results is equal to our method which is C2 dot Point polygon test CO2 dot point P Capital polygon T Capital CO2 dot Point polygon test and what we want to mention here we mention our area first we want to mention our area so our area is what our area is this method NP dot array so just copy it just copy it and just paste one more thing friends there is no need comma here I mistakly mentioned the comma so just remove it OK there is no need to comma here so just copy this method NP dot array to NP dot in 32 to bracket okay just copy as it is as you can see I have copy it and then after that in area which coordinate we want means which uh point we are going to mention we mentioned we are we are going to mention a rectangle bottom right point so rectangle bottom right point is basically our X4 and Y four that's why I have mentioned CO2 dot Circle method X4 and Y four point and I have highlight with blue color as you can see I have mentioned two five five zero zero this is the blue color so simply we need to mention here after that we need to mention our X4 and Y four in Tuple format X4 and y4 and then we are going to mention false now the result is like minus 1 or 1. when the person is not inside area we have minus 1 when the person inside our area we have one because I have already explained in several videos this concept ok so simply you know what basically inside our result we have minus one or one so let's just create our condition if results if result is greater than if results is greater than or is equal to 0 greater than or is equal to 0 then only we want to draw the rectangle then only we want to draw the circle then only we are going to use here Sim is on put text method okay now simply we are going to start our while loop now what will happen there is no detection in other area there is detection only in our selected area we select area one we only want object detection also tracking in this particular area the region of Interest area area one which is in red color watch door open there is nothing but as you can see when the person bottom right Corner if it is inside our area then only we have detection then only we have pink color rectangle then only we have highlighted Circle point and also then we have a ID ok so next person is basically coming which want to enter the mall so watch for this person right now there is nothing No Object detection no ID no blue color circle nothing when the person in our area as you can see there is detection and other things are done simple so this is what our first condition this is for basically ah first we are going to create exit counter then we are going to create enter counter so let just create the exit counter first so person who want to exit from the mall first he will be part of our area one of course which is red color and then he will part of our area two which is in green color so simply what we are going to do here first we mention our area one okay so when the person is enter in our area one what we are going to do we are going to save their ID also we are going to sell their current position in dictionary so for that I have create here a dictionary I already mentioned all the variables here it is as you can see people exit as I mentioned first we are going to create the exit counter so people exit and the dictionary so we are going to Simply call this dictionary after our condition completed and then inside the dictionary we are going to save each person ID because if you want to detect or not detect basically if you want to track the person so basically we are going to track their ID because ID is identification for each person because we are going to assign the ID for each person simple so we are going to save their ID and their current position so I have mentioned the dictionary variable people exit so we need to Simply call our variable where we match our condition means when the person in our area 1 then we are going to save their ID and then we are going to save their condition simple so here we can say people exit people exit this is whatever dictionary and we are going to save their ID in list format so people exit an ID is equal to their current position so their current position is basically X4 and Y four rectangle bottom right corner simple so if we print here if we print our dictionary which is people exit people people exit okay now simply we are going to mention here one because we want to start our while loop so now when the person is inside our area their ID and their current position will be saved inside our dictionary so right now as you can see there is a empty dictionary nothing inside there is a empty dictionary so when the person will come inside our area one there will be their ID so ID is basically zero and their current position as you can see we successfully say uh for this person we successfully save their ID and their current position when the person is inside our area one so first we are going to create the exit counter ok so we successfully save the person ID and their current position now the next Cooper condition so next condition is what now we have the person ID and their current position now simply we can say only only count those person which already part of our area one because we are saving their ID and their current position inside our dictionary so now we have the person who already cross over area one now of course he will be part of our area too he will be part of our area too so we can simply say only count those person who already part of Area 1 otherwise don't count it this is how we will create the counter OK simple so simply we can create here our new condition which is let me check it is in line here from here we can simply create our new condition so we want to say like this we have our dictionary inside the dictionary we have ID so we can simply say if ID if ID if ID means if the person because we saving the person as a ID inside our dictionary so we can simply say if ID inside our dictionary which is people people exit if ID in people exit so simply same condition just copy and paste and here now simply we can mention area two Result One and area 2 because the person is already Area 1 we say here if the idle inside people exit then only detect that person inside our area too so for that we need to create our area 2 condition Result One and after that simply we can draw our rectangle circles you to put text method so just cut and paste yes cut and paste and then make it in line okay so now we completed our condition now simply we can create our counter so after that I have mentioned here as you can see I mentioned here counter two for exit so counter two counter counter 2 dot append because we want to save their ID after we match our two condition we want to save their ID in list format so pass the ID also I'll explain in previous video when the person is basically Crossing Area 1 to Crossing area 2 there is some time it will take some time so meanwhile it will ah it will basically count same idea again and again so for that we create the condition if if counter 2 dot count and the ID if please don't count same ID again and again that's it this is what our condition and then now we know what we have inside our people exit so simply we can print uh counter 2 and the counter 2 is basically the list so simply length of counter 2 is our exit counter frequency simple so if I save the code if I run the code now it will count the person who want to exit ok so right now there is zero as you can see there is zero because no one is basically exit from the mall so when this person is basically exit from the mall our counter number will increase it will become one there is something error counter two dot append ID okay here I need to mention like this way counter dot obtain an ID now it will perfect work okay now it will work and friends as you can see our code is perfectly working we count one person as exit now same way same way only we want to reverse our condition and we can create the counter for entering the person so let's just copy our code just terminate copy it from here we are only going to reverse our condition also we are going to change some variables so start from here first let me check it is in line so results will come here okay so this is for person who want to enter the mall so simply we can say here enter Mall counter okay that's it and then a result we mentioned already result one so here we can say result two only we want to change the variable also we want to reverse the area person who want to enter the mall first he will be part of our area two green color area then he will be part of our area one red color area so here we want to mention area two then this will become result 2 then of course I have created here people enter dictionary ah people enter dictionary as you can see so simply we can mention here people enter people enter Then the method will be same we are going to save their ID and their current position which is X4 and Y four then again this will become pain people enter people enter the result we have result two there so result three and this one we can say area one then this one we can say a result three because this is whatever result three and after that we can simply draw the rectangle on all other things and for entering I have create the counter one here it is as you can see counter one as a list so simply we can mention counter one dot count and all other are same things simple so and now just change counter two with counter one and let's just watch then we are going to use series on put text method and we are going to put the counter on our frame ok so now it will show the counter for the person who's who want to enter the mall because I already show you the person who want to exit from the mall okay so right now zero because this counter is for person who want to enter the mall not for exit formald not exiting the mall let's just wait so this is a whatever person who want to enter the mall so first we will part of our area two which is green then you will part of Area 1 and we have counter one it means we successfully create our code that's it friends we have done now simply what we can do here we can simply create a variable so this is for enter so e is equal to counter one and exit let us say e r enter ER and exit e t is equal to length of our counter counter two that's it now simply we are going to use here our CV Zone method series one method paste and again next counter which is exit that's it so let us say here I want to mention ER for enter and 84 exit and then we need to mention the coordinates so let's say ah 50 50 50 50 and here I can mention 50 60 okay 50 60 let's just start our code then we will get the idea how it's look like if you want to change the coordinates we can simply change the coordinates okay so we want to change the coordinates so what we can do here let's say this 150 50 and 90. 50 90 now it's good we have two counter let's say here we can create the variable here this one is basically our enter so enter the mall [Music] entering for the mall and this one we can say exit okay so if I say record if fire in the code and as you can see or just a minute what we can do here can make like this way and we are going to make a rectangle size 2 now let's just watch now it's good but we want some ah some space ok so here I can mention 100 now it's good now it's good we have counter for enter 0 for exit 0. so when the person enter the mall counter will be increase the person exit from the mall counter will be increase ok so now this person is basically want to exit from the mall and we counted one as you can see we can't tell one person who basically exit from the mall so enter we have still zero so what for this person and this person is inside our area and then our counter is basically increase it means friends our counter is perfectly work our code is perfectly working so I hope you will learn something from this video we will meet our next video till then thank you take care and bye
Info
Channel: FREEDOM TECH
Views: 4,171
Rating: undefined out of 5
Keywords: People counting with YOLO, YOLO object detection for crowd analysis, Real-time people counting using YOLO, YOLO-based pedestrian counting, Crowd density estimation with YOLO, People tracking and counting using computer vision, YOLOv3 for people counting, YOLOv4 pedestrian detection and counting, Video-based people counting using YOLO, YOLO people counting accuracy, People density measurement with object detection, YOLO crowd analysis tutorial
Id: JCkvJNaO7vQ
Channel Id: undefined
Length: 29min 35sec (1775 seconds)
Published: Thu May 11 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.