yolov8 passenger counter | yolov8 custom object detection tracking & counting | computer vision

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hello friends and welcome to YouTube channel Freedom Tech and in this session what we are going to learn in this session we are going to create a bu passenger counter with the help of YOLO V8 but 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 create a bur passenger counter with the help of YOLO V8 we are going to create our own custom model which detect passenger head or we can say which detect passenger face so let's get started so this is Windows 11 machine of course you can use your Windows 10 machine also so first we are going to install our packages so just open Tony python IDE then go to the tools manage packages and search for open CV Hy python open CV hyen python this is what what our first package open CV hyphen python just select it click on install and then it will install open CV on our Windows machine then we need ultral litic package ultral litic package for YOLO vate click on search on piie then just select the package click on install done it will install Ultra litics on our Windows machine then we need a CV Zone package so just search for CV Zone select first package CV Zone click on install and then it will install CV Zone on our Windows machine so we have done with package installation we install open CV hyphen python we install tics we install CV Zone on our machine done so for today's session I have create a new repository I will mention the link you need to Simply copy paste the link inside the browser then the repository name is Yolo V8 object detection for public transport monitoring code click on the code then go to the download zip and it will download our ZIP format repository as you can see it's now downloading so friends as you can see we successfully download our repository so just open download folder this is what our repository as you can see right click vrar extract with the folder name and then it will extract our repository again same folder and let's just first watch our video file so FD door.in a v i means the front door of the bus so if I open the video file and as you can see this is the bus and we have inside bus view with the help of CCTV camera and bus is now sto at the station bus stop and this is the automatic front door and door is open and now passenger or we can say the person is basically entering inside the bus using this automatic door door so our goal is to detect the passenger head or we can say their face then we are going to mention here region of Interest area because we don't want to detect passenger all in bus we only want to detect the passenger when the passenger is basically entering inside the bus through this door through this front door so our goal is to detect passenger on only in this area this is what our area as you can see this is what our area so our goal is to detect a passenger head or face only this area because passenger is basically entering from here and then he will go inside the bus here it is as you can see the ticket machine so this is what my region of Interest area so here we are going to mention region of Interest area and then as I mentioned we are going to create our own custom model which detect person head and then we are going to draw of course we are going to draw the rectangle with the help of our model and then we can say if that rectangle Center Point if it is inside our area which we are going to mention as a poly line so if the person rectangle head if it is inside our area then we can simply say we this is basically passenger and we are going to track the passenger also with the help of tracker we are going to assign the unique ID for each passenger so it is really easy to create a counter so this is the whole concept which we are going to use for this project so first let's just create our own custom object detection model which detect person head for yate so this is what video files so first we need images so this is what our video file let me start again as you can see bus is stopped door is open and the person or we can say the passengers is basically entering inside the bus this is what ticket machine as you can see ticket machine done and then they just completely enter inside the bus so first as I mentioned let's just capture images with the help of our IMG dopy code and this IMG dopy code uh will capture images with the help of our video file itself as you can see the video file name which I have mentioned already inside the code then the maximum frames we need for this project I have mentioned 200 you can simply increase as per your requirement the number so for this I have mentioned 200 images is more than enough then here CV2 imite CV2 do imite is basically capture image and save inside the folder so here we need to mention our folder path so first let's just create our folder new folder inside our repository so we are now inside our repository so right click new folder and simply mention images the folder name images done then right click to the folder copy as a path and just open our IM dop and from images as you can see from images just remove all the things remove it like this way and then just press contrl + V because we copy our folder path so it will paste that folder path in our code and then as you can see the line which we paste is look like this way it's look like this way see users username downloads folder folder then our repository repository name and again inside that we have same folder same repository name and then we have images folder so now here we need to Simply remove this double coat as you can see images after that we have double cat so just remove it and then here at the start point we have two double Cod so we need we need only one so just remove one then you will see now the line is perfect now the line is perfect that's it now here after images you can see the person so this is basically image name it can change as per your requirement this is basically our class name or we can say this is basically our image name not basically class name I have mentioned here image name same as our object which we want to detect so I have mentioned person you can mention person head or you can only mention the head simple so I have mentioned person here and then this is what our extension do jpg simple so it will capture 200 images because we mention 200 maximum frames and then it will save inside our repository and inside that we create a new folder which is images and name of our all images basically person. jpg simple so let's just start our codes just save it and let's just run the code now it started our video file it's capturing images and then when it complete 200 images it will automatic turn off our video file so now if I open our images folder which we just create inside our repository and inside that as you can see we have uh 190 199 images as you can see this is the last one person 19 19 99. jpg so we capture 199 images with the help of our video file simple so we have done with images now we are going to Simply use these images for labeling purpose so for labeling purpose we need label IMG software so label IMG is basically work with python 3.8 version so we need python 3.8 so how to install python 3.8 simple just open Microsoft moft store as you can see Microsoft Store just open it and here we are going to search for python so it will basically it will basically show all the python version which available so as you can see I have mentioned just Python and we have all the versions python 3.11 3.10 3.9 3.7 and 3.8 so for label mg we need python 3.8 so just click on the the python 3.8 version and then you will see the install button just click on install button that's it done it will install python 3.8 as you can see if I click here I have already installed python 3.8 on my Windows machine so it is really easy just open Microsoft Store search for Python and then python 3.8 click on install it will install python 3.8 now we have done with python 3.8 installation so now we need to change the version for our Tony python IDE so just go to the Run configure interpreter and then here as you can see here just click on and then it will pop up the window like this way so we need to select here our version which we just installed the python 3.8 so as you can see the line is look like this way this is the path of the folder python 3.8 8 exe users fre app data local Microsoft Windows app and python 3.8 just select it click on okay and inside shell as you can see the version is now changed now we are working on python 3.8 version done so now simply we need to install label IMG so it is really easy just go to the tools manage packages and search for label IMG label IMG then just hit enter it will search label IMG package first package click on install done it will install label IMG that's it we have done with label mg now simply go to the tools again open system shell and here we need to run our label IMG command so just run label IMG as you can see this is what our Command label IMG done now just hit enter it will open our label IMG software like this way now simply we need to select our di so we need to select open DI as our images folder so go to the downloads our repository where we create our images folder just select the folder and then as you can see we have our all images then change save Dr again same folder repository again same folder and images folder just click on select folder done so this is how you need to install label IMG also you need to select open diir and change save di folder simple now friends as I mentioned what is our goal our goal is to detect passenger head or we can say passenger face but in this first image as you can see there is no passenger is basically entering inside the bus because the door is the front door is still closed it's not open so for that we are going to Simply skip all those images where our object is not there means in this scenario our object is person head or we can say the passenger head so in this image there is no passenger means there is no passenger head so we are going to Simply skip those images where our object is not there so just click on next image next image next image next next next next next just just go next next because still there is no passenger go next next next next next next now door is open but we cannot see the passenger head or face just go next next next next just go for next image next next next next and then now now as you can see we can see their face as I mentioned in 49 image we can simply see the passenger face so now just create create rectangle box and draw a rectangle box and mention our class name which is person person click on Okay click on Save now this is how you need to draw rectangle on each passenger face simple so now just go for next create rectangle click on okay save it just go for next image draw rectangle box click on okay save it go for next image create rectangle box draw the rectangle box click on okay save it now let me draw a rectangle box on each passenger face after that I will start video again so friends I have done with drawing rectangle with the help of label IMG on their head on the passenger head or face as you can see this is the last image actually we mention 200 images but as I mentioned we skip some images because in some images there is no object means there is no person and in some images our passenger is cross our region of Interest area so now there is no need to draw a rectangle box on their face or head if the person is basically cross our region of Interest area so 132 image number as you can see 132 image number here this is what the Last Passenger and he is completely enter inside at the bus and he's as I mentioned this is what my region of Interest area all this is so this person is also already cross the region of Interest area so now now after these images let me save first and after these images as you can see the person is completely enter inside the bus so now there is no need to draw a rectangle box on their face or the head because person is completely enter inside the bus so we are going to create our model which only detect a person head or face when the person is entering inside the bus entering inside the bus not when he is completely enter inside the bus simple for that we are going to skip all those images where the person is basically completely inside the bu simple so now because we skip some images here so we need to delete those images so I have done with label IMG I have explained the full code also when we Implement our model then you will get a better idea how our model will work simple so let's just close our label mg because we have done with label mg now close the system shell and then now simply we need to again change our version so just go to the Run configure interpreter and select the default version the first version python click on okay and now python 3.10.1 now as I mentioned I have created a code which basically delete images so go to the open downloads our repository and IMG delete y.p this is the code as I mentioned this is the code which basically a check image and their text file image and their text file if you open our repository and where we create our images folder inside that as you can see we have txt file txt file and we have images so it means label IMG is basically create image and their text file image and their text file so inside that text file we have rectangle coordinates so now simply our IMG uh Delete just a minute okay now it's good so our IMG delete yellow. py code will search if the image is there and if the text file is there if it is not there text file it will delete all those images simple so let's just because I have mentioned here images folder image directory here you need to mention the folder where you have all our images and their text file so I have mentioned images folder because we create our images folder inside our same repository so images folder now simply run the code and as you can see it's printed the number images deleted person 47.jpg because person 47. txt does not exit it's it basically print all the images number and because person 5. txt does not exit person 6.jpg deleted because person 6. uh txt does not exit so this is how it basically delete all those images which don't have txt file simple so now we have done with our labeling process now simply just minimize Sony python ID again go to the repository same folder and now we have our images now here we are going to create a new folder and the name of folder is basically Freedom Tech so right click and new folder images and oh sorry not images uh the folder name is freedom Tech Freedom Tech is the folder name done now just go inside the freedom Tech folder and here again we are going to create two new folder images and labels so right click new images and labels images and labels we are are now inside Freedom Tech folder and inside Freedom Tech folder we create again two new folder which is images and labels now just select one of the folder so let's just select images folder and go inside images folder and here now we are going to create again two new folder first one is training and next one is validation so training training and validation training and validation now same way inside labels training and validation new folder training and new folder validation that's it so this is how we create FM Tech folder then we create images and labels folder now just go inside images folder create validation and trading folder and same way go inside labels folder create training and validation folder now simply go back and from images where we have all our data just press control+ a select all the data then copy it and then go back go to the freedom Tech images training just paste it then go back then validation just paste it then go back back then go labels validation just paste it then go back just training and paste it so we copy paste our all data from images folder to Freedom Tech images training and validation as you can see then go back and then Freedom Tech labels training and validation folder copy paste all the data from our images folder so done now simply we are going to create our freedom Tech folder as a zip file so right click wiar at archive. zip click on okay it will create Freedom tech. zip file as you can see now simply we are going to upload our file on our Google Drive so I have open my Google Drive right click file upload and then go to the downloads our repository and then Freedom take. zip select it click on open now it will upload our file meanwhile simply we are going to upload our collab file so upload click on browse downloads our repository name and this is what our Google collab file which I have mentioned inside our repository so now it's uploading our collab file on our Google collab so friends as you can see we have successfully upload our collab file now we simply go to the runtime change runtime type select Python 3 then select T4 GPU click on Save done now simply click on connect it will connect so friends as you can see we successfully connected now simply we are going to run our cell one by one so let's just start with first cell then second cell it will install ultral litics so friends we have done with installing ultral litics now simply we are going to call our ultral litics as you can see from ultral litics import yellow also from IPython display import display and image then we are going to cross check if our ultral discs is perfectly installed so we are going to Simply use image from roof flow.com and the image name is dog. jpeg it will detect our objects from the images and it will save the result inside runs detect and predict so if there is error of course it will not detect any object so if uh if the result is there it will save the result and and is detected the object and as you can see there is a person there is a there is one person there is a one car and there is one Doc in particular doc. jpg image and the result is basically save inside runs detect predict it means our ultral XS we successfully install on our collab machine now simply we are going to mount our Google drive because we we upload our freedom te. zip on our Google Drive and one upload completed so we successfully upload our freedom tech. zip now simply we need to mount our Google Drive so just run this one code from google. collap import Drive connect to Google Drive select it the Gmail ID click on continue scroll down click on allow now it will Mount our Google Drive done as you can see we have our freedom tech. zip now simply click on the next cell it will create a data set directory and inside that it will mention or it will just copy Freedom tech. zip and then it will unzip all Freedom tech. zip file so as you can see inside that we have person and their text file and their images as simple as now just click on this folder icon then go to the data set folder as you can see we create here a data set folder so just click on here on the data set and inside that we have freedom Tech folder so now select this three do dos select these three dots and then create a new file and mention the new file name data do yl data. yl simple and then just hit enter it will create data. yl file then double click to the data. yml file it will open data. yaml file right now it's completely empty there is nothing so we need to copy our code inside data. yl so code which I have mentioned inside our repository data.txt file data. text file so just open with text editor this is just a normal text file so copy the code copy it close the file and just paste inside data. yl file right click and paste it done now here number of classes is basically one because right now we are going to only train one class which is person and the names only mention your class name so in this case we have person simple then press control+ s it will save our data. yl file we have done now we are ready and then run last cell it will start 100 apox and it will create our own model and friends as you can see it started our APO process one and out of 100 so it will take some time meanwhile I will pause video so friends as you can see our process is completed and we have successfully create our model and our model is basically save inside runs detect and train folder so this one is runs folder selected then inside that we have detch folder selected and inside that we have train folder as you can see train train select it and then inside train folder we have weights folder and inside WS we have best. PT our own model so just select it click on download and it will download our best. PT model so friends as you can see we successfully download our model so minimize all these things open download folder and inside that we have our best. PT so right click cut and move our model inside our rep repository where we have our all files so now simply here we need to create a Coco 1.txt our own class file so just right click coco. txt so text document Coco 1.txt open it and mention the class name person simple and just save it now just open test. and inside that I have mentioned a full code so let's just delete all our other python code file and then edit and clear shell now friends if you don't know how to use YOLO with python open CV and our tracker so I have already create a playlist watch the playlist and then you will get the idea how to use ovate and tracker object detection and all other things so I already mentioned the code for this project so we are going to Simply overview what basically inside our code so this is what our modules CV2 pandas as PD ultral litics and CV Zone nay NP tracker import tracker and then we have our model best. PT is our model name then this is what our mouse event function which we are going to use for selecting our region of Interest area then tracker is equal to tracker this is how we call our tracker file so tracker file is basically inside our repository and then video file then Coco one.txt file our class name file which we just create and then we have our detection and then we have our rectangle class name and then we are going to append the list because if we want to use our tracker we need to send our rectangle coordinates the object rectangle coordinates to our uh tracker and then create a new rectangle coordinate so we need to use all the rectangle coordinates along with their ID so for bbox in bbox idx bbox idx tracker. update list as I mentioned I have explained how to use tracker in Deep Way in my previous video so you need to First Watch my playlist then you will get the idea so here we send the list as you can see we send the list here we create a list and inside that we mention our X1 y1 X2 Y2 object rectangle coordinates and then we mention a list and then we call a list inside our tracker. update and then now tracker will get the coordinates and again it will create a new coordinates so X3 Y3 X4 y4 and the id4 each object then CX and Cy because we need a center point so CX and Cy is basically int X3 + X4 ided 2 Y3 + y4 ided 2 that's it now let's just first draw a rectangle with the help of our tracker coordinates so here it is I have mentioned X3 X3 Y3 X4 and y4 and then because we have ID so we are going to Simply use here CV on putut text method and we are going to put our ID as a text on X3 and Y3 means the rectangle top left corner and then here let's just freeze our frame if I save the code if I run the code and as you can see we started our video file because we freeze our frame so we need to skip our video file one by one so let's just press a space button from keyboard now we are skipping a frame by frame so now door is open as I mentioned we create our model which only detect when the passenger is basically entering from the door right now there is no passenger is basically entering from the door so there is no detection there is no object detection so when we see the passenger face and as you can see now there is a rectangle now there is a rectangle on passenger face because we create a model which we want to work like this way when there is a passenger then only we need to detect their face or we can say their head so now as you can see this passenger is basically entering inside our bus and we can clearly see their face in that time there is a rectangle on their face means our uh model is perfectly working is detecting our object as you can see done so this passenger is basically already cross over area so ID is still there one so watch for second passenger ID is still there too and this passenger is also cross our area now watch for this passenger is coming inside our bus done as you can see he cross over area then there is no detection because we train our images like this way with the help of label IMG as I mentioned when we create our model then you will get the idea so this as I mentioned this is what my region of Interest area only in this area we need to detect the person head or we can say their face so we create our model like this way which only detect the person head in this particular area in this particular area as simple as now let's just what we are going to do let's just start start while loop again and now let's just watch the door is open there is no detection there is no object detection but when we see a passenger face there is detection one two two ID for this person this passengers the second passenger then three ID for this passenger and then 4 ID for this passenger so we can simply detect the passenger when the passenger is basically entering inside our bus okay so now what we are going to do here I have already mentioned the region of Interest area I already mentioned the region of Interest area now simply if I start the code again let me make here zero what we are going to do we are going to Simply change our area coordinates simple so we are going to change our area coordinates let's just say let me skip here some more frames because still there is no per passenger and as you can see now we can see the passenger face so here we are going to draw a circle and let me mention here instead of drawing full rectangle instead of drawing full rectangle on their face we are going to use here cvz Zone CV zone. Corner rect method CV zone. Corner W method I have mentioned the method already inside the code so this CV zone. Corner Rec method would basically create pink color rectangle and their corner is highlighted with uh green color so for that we need X3 and Y3 so we have X3 and Y3 and then we need width and height so w and H is basically X4 - X3 X4 - X3 and y4 - Y3 then we will get the width and height and then we can simply use this method as you can see C Zone Corner r capital re frame we are going to draw a rectangle on our frame X3 and Y3 and WS W and H this coordinate and the 10 and the five this is the size so now if I save the code and if I run the code now we will see pink color rectangle also the corner is highlighted with green color so let me skip here frame and as you can see as I mentioned there is a pink color rectangle and the corner is basically highlighted with green color simple so now we are ready and as I mentioned we need to mention our region of Interest area so for that again let's just draw a Center Point so we mention our CX and Cy so now it will draw a center point so we have started our frame there is no passenger so as you can see now there is a center point there is a center point and here let's just say here we need to draw our poly line so if I go here if I go here and inside shell because we mention our mouse event function as I already explained here uh let me mention here as you can see this is what our mouse event function so which when we move our mouse cursor on our frame inside Shield we have coordinates so we are going to Simply use those coordinates so let's just go over here and if I move my mouse cursor over here so for this we have 716 272 716 272 716 27 just a minute 716 [Music] 27 here 715 273 715 273 273 715 273 that's it now so we mention here our first point so if I go here and inside shell we have 688 272 688 272 688 688 272 688 272 is basically here then if we go here 712 487 712 487 712 487 712 48 8 7 and the last Point Let's just say over here 783 484 783 484 783 484 done so this is what our area 1 coordinates I have changed the coordinates so now simply if we run our C2 poly lines coordinate frame np. array and area one this is what a new coordinates which we just mentioned this is what our new coordinates which we just mentioned with the help of mouse event function now it will draw a poly lines using our area 1 coordinates on the frame and as you can see as you can see so this is our coordinate so let's just make like this way here 73 4 486 73 4 486 734 486 let me cross check because we need to make it perfect so it will come here this is the point 737 487 737 487 this one 737 487 you can simply change the coordinates first let's just draw a poly lines with the coordinates then you can change the coordinates uh for looking perfect for looking perfect the polyline area so now it's look perfect as you can see it's perfect now if I skip here a frame one by one and now as you can see the person Center Point is inside our area and for this the second passenger also as you can see it's inside our area the center point and then for this passenger let's just assume that okay now the center point is basically inside our area and then for for this passenger let's just check yes it's inside our area and still inside our area so we successfully mention our area now second area what we are going to do simply we are going to use this poly line and inside that again we are going to use a second poly line so let's just say I need to only mention here let's just take this coordinate this one so what we are going to do we start from here so this is what uh this is the second poly line so for second line Second poly line my starting point is this let's just say this one so 71272 701 272 701 272 7 01 272 simple 71272 so we mention here 71272 and then this is what our next point so this next point is basically we are going to use from our polyline one area so this is what my polyline one area first point this is what my poly line area second point so the second polyline second poly line which we want to draw right now so we are going to use a same coordinates for drawing second poly line area are second Point our first poly line Second point is same point for drawing second poly line Second point so the area 2 point the second point is basically 688 and 272 688 and 272 because we are going to use a same poly line so this is what for poly line 2 this is what my first point and the second point of poly line 2 mean means the area two is same as our area one same as our area one so we need to mention our second Point done here now we done with second point now this is what our third point which is also same as our area 1 third Point area 1/3 point so let's just mention here same point 7 737 487 737 487 and the last point which we are going to use here the middle uh 75 8486 75 8486 758 486 so if I save the code if I run the code oh we forgot to mention our polyline method so this is what my area 2 for area 2 we need to again mention our polyline method and here I have mentioned area two save the code run the code if there is something issue we can simply change but there is no issue as you can see there is no issue we mention both area so this is what my first area we can say and this is what my second area this is what my first area area one and this is what my second area so we have done with both area we draw a polyline with the help of our area coordinates now simply we can mention our condition so let's just again skip our frame one by one the door will open and then passenger will enter inside the bus so right now there is no passenger so there is no detection nothing is there when we can see their face there is a rectangle there is a center point there is a ID for each passenger and the first passenger is Center Point is now enter inside our first area then enter inside our second area so we we successfully mention our area now we are ready and we are going to use our C2 Point polygon test method so here CV2 do Point CV2 do Point P Capital polygon T Capital test CV2 Point polygon test D capital and then we need to mention our both areas so let's just start with our first area copy it and then mention as it is this is what our area method so just copy it and mention as it is inside s2. Point polygon test method and then we need to mention their Center Point coordinate so Center Point coordinate is basically CX and Cy so mention in tle format and then after that mention false and then the result of this method result of this method is basically 1 or minus one so if result if it is greater than or is equal to zero then only we are going to draw a rectangle then only we are going to draw a circle then only we are going to put our text save the code run the code we start our frame and then we are going to skip our frame because we want to check our result frame by frame that's why uh we have mention a zero we freeze our frame and we are we are skipping a frame step by step for our knowing purpose so now as you can see the person is basically enter inside uh the bus but there is no detection because we mentioned if the person Center Point if the person rectangle Center Point if it is inside our area one then only draw a rectangle then only put the ID so right now the person rectangle Center Point is not inside our area when the person as you can see the there is a center point it's inside our area and then we can see there is a rectangle and then as you can see it's inside our second area but there is nothing simple so now for our doing purpose we can simply cross check for our second area also so let's just copy the code as it is and mention over here and just paste it and here let's just check if it is in line otherwise it will create a error so it's in line and then here we are going to mention this as a result one here also we are going to mention result one and then we are going to mention this as a area two and because our knowing purpose when the center point inside our area two we are going to change the rectangle color so rectangle or let's just change because we use a corner rectangle method so we are going to change their Center Point color so here I have mention blue so let's just mention pink if the center point if it is inside second area it will become pink if it is inside Area one it will become blue here it is as you can see save the code run the code so skip the frame and then there's a person and when the person enter inside our area one the color is blue Center Point and then when same Center Point inside Area 2 as you can see the center point color is changed now it's become a pink it's become a pink let's just watch for second passenger it's blue then it's pink watch for third passenger it's blue then it's pink done so now what we are going to do we can simply create our condition if the person if it is inside our area one the person Center Point means the rectangle Center Point if it is inside our area one we are going to save their ID and their current position inside the dictionary and the dictionary name is pin pin means the person in simple so let's just mention this is what our first condition if result if it is greater than or is equal to zero means the person is basically entering inside Area one then we are going to mention pin is our dictionary which we mention over here here it is pin is our dictionary and then pin and then we are going to save their current ID and is equal to their current position so their current position is basically their center point so CX and Cy that's it done now if you print over here if you print let just say here if you print here pin which is our dictionary inside that dictionary we are going to save their ID and their current position when the person Center Point if it is inside our area one so frame is started and I'm skipping frame one by one and as you can see right now the dictionary is empty there is nothing but when the person Center Point inside our area one as I mentioned we are saving their ID and their current position so now inside dictionary as you can see their ID one and their Center Point 739 356 so this is for first person now then the second person area one it is inside our area one and inside dictionary as you can see their ID two and their current position simple so this is is how our method will work now simply we can say now we know that our person is basically crossing our area one because we are saving their ID and their current position so we have now their unique ID so we can simply say the same person because we have their unique ID for each person so we can simply say same ID is now crossing our area to because we know that this ID is already cross my area one now the same ID is cross my area to because we are saving their ID and their current position inside pin dictionary so so we are going to call our ID from that dictionary and we can simply mention now only detect those ID which already part of my first area simple so here here we mention pin ID after that we can simply mention like this way if ID inside inside our pin dictionary so if ID in pin then we are going to mention our second condition so copy it and then just paste it or let's just because we mention here our res area two so let's just remove all these things because when person Center Point if it is inside Area one we only want to save their ID and their current position with there there's no need to draw a rectangle and other things so we are only saving the saving their ID and their current position when the person Center Point inside our area one so if result if it is greater than is equal to one this is for area one then we are saving their ID and then we are going to create our new condition if the ID inside our pin means if the person is already part of our area one then we are going to Simply mention our Result One Condition which is same person ID is now crossing our area two area two so same method c2o polygon test method mention the area two so copy just area two and mention CX and Cy and then same way if Result One if it is greater than or is equal to zero then we are going to draw all these things then save the code now let's just start our while loop save it and run it so we started our while loop so person is entering inside our as you can see there is only pink color uh Circle not rectangle pink color circle because we mention only draw all these things when the same ID is basically Crossing area one and same ID is now entering inside our area to and inside the dictionary as you can see we are saving their ID done we have successfully detect our object we are successfully tracking our object now last and important thing we need to count so simply because we have their ID so ID is basically unique for each person so we are going to Simply create a list of ID and then we are going to mention the length of ID the list of length of ID so here we mention our all the condition so after that simply mention because I have mentioned here a list and the list name is basically enter simple so enter enter do append after all our condition match this is what our first condition this is what our first condition then we are saving their ID and their current position then we mention if the ID inside our pin dictionary then we are going to say that only only count or only detect those ID which already part of our area 1 because we know that ID is already part of area one because we are saving their ID then we are mention we are going to mention our second condition for area two then we are going to draw and all other things so after that enter aend and what we are going to append we are going to append their ID so now because the person will take some time for crossing our area one to area 2 so we need to mention here our condition meanwhile basically it will count a same ID again and again because it will take some time to crossing our area one to area two so for that we need to mention here a condition if enter dot count if enter do count and what we are counting we are counting their ID if it is if is equal to is equal to zero means please don't count same ID again and again and then we are going to append their list now we mention here list already there list file now if we go here and if we print length of our enter list now this is the number this is the number uh of uh a passenger counter enter save it and if I run because we mention our value so now we can count the person how many passenger is basically entering inside the bus using front door so right now as you can see there is a zero no count yet zero so when first passenger coming inside we detected and as you can see there is one then there is two we count two passenger then there is a three as you can see there is a three and then there is a four so we successfully count four passenger now simply we need to mention this counter on our frame so we can simply use here our C Zone put text method so let's just mention CV Zone putex method and now we need to mention this counter over here and then let's just mention as variable so like this way let's just say EP entering person so I have mentioned just EP as a variable you can mention any variable as per your idea so EP length enter and then Sone put text method here I need to mention uh count as a variable count or let's just say counter like this way and then we are going to mention a our counter which is EP that's it and then what else we want uh we need to mention the coordinates so 50 60 50 and 60 and then let's just say two is the rectangle size and two is the text size save the code run the code and as you can see there is a counter so right now zero so when the passenger is basically enter we mention our condition we mention our area when it's match our condition we have counter one we count one passenger two we count two passenger then third one three and then fourth one so friends as you can see this is how friends you can use yate you can create your own custom object detection model and you can simply create SMART Bus passenger counter 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: 1,582
Rating: undefined out of 5
Keywords:
Id: 1FZlxhCY_6o
Channel Id: undefined
Length: 61min 15sec (3675 seconds)
Published: Wed Dec 13 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.