Yolov8 Tutorial: Accurate People Counting in Queues with Object Detection | yolo object detection

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 friends in this session again we have new project for yate custom object detection 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 have again a new project for YOLO V so first just open Tony python ID as we always do a basic package installation so just open Tony python ID then go to the tools manage packages search for open CV hyen python then hit enter it will search for open CV hypen python first package then click on install button it will install open CV on our Windows machine this is Windows 11 of course you can use your Windows 10 machine also Now ultral litics package ultral litics just hit enter first package click on install button done it will install ultral litics on our Windows machine then CV Zone package just search for CV Zone first package click on install button done it will install CV Zone on our Windows machine so this is how we need to install first this basic package so open CV Hy python then tics and then C on so we have done with package installation now for today's session I have create a new repository yate counting people in Q so this is the name of our repository I will mention the link you need to Simply copy paste the link inside the browser then go to the code click on download zip and it will download our ZIP format repository as you can see we have successfully download so now just open folder file manager basically and then go to the downloads and this is what our repository right click vrar and extract with the folder name it will extract our repository as you can see we have now our folder so again go inside the folder we have again same name of folder yo at counting people in Q hyphen men and just click on the folder and then we have our all files for project so of course first we need our video file so VI .txt this is the text file inside that I have mentioned the video link so vi .txt just copy the link this is basically Mega Cloud link so just open Chrome browser new tab control+ V and hit enter it will open our Mega Cloud link and then simply click on download it will download our ZIP format file inside that file we have our video file so let's just first download our video file then I will start video again so friends as you can see we have download our ZIP format file and inside that we have our video file so again go to the downloads right click to cr. zip vrar extract with the folder name so it will basically extract our folder so just click on the folder and this is what our video file so simply we need to move our video file in same repository so right click cut downloads and our repository again same repository and then just paste video file so friends first let's just watch our video file so this is what our video file and Friends our goal is to create a counter for customer frequency simple so this is what our scenario as you can see we have here two counter basically this is the shopping mall center and we have here two counter so let's just say this is what our first counter and this is what our second counter so our goal is to count how many customer is basically right now on each counter so simply for that we know that we have a default object detection model for ovate which detect a person but I already used the default model YOLO s. PT and it's not perfect it's not perfect working so what we are going to do we are going to create our own custom object detection YOLO model which only detect their head or we can say their face so our goal is to create YOLO vate custom object detection model which detect person head and then it is really easy to detect our object and create the counter simple so this is what our scenario as I mentioned our goal is to create a counter for customer frequency or we can say create a counter which count how many customer is basically right now on each counter or we can say simply crowd management so this is what our scenario simple so first first we need images so for images we have our IMG dop an IMG dopy which basically capture each frame from our video file itself so here it is as you can see I have mention the video file name which is cr. MP4 as simple as and then for today's session we need 85 images you can simply increase the number as per your requirement I have mention 85 images is enough for this project so 85 images Max frames 85 this is what our video file and then CV2 do imite is basically the code line where it's capture the image from video file and it will save image inside the folder so first we need to create our folder so let's just create our folder this is what our repository inside that simply create a new folder images images simple just create images folder and then right click to the folder copy as a path and simply from this images folder as you can see just remove all the thing and press control+ V it will copy paste our folder path which we just created as you can see yolow counting people in Q hyph Main and then we have our images folder so here it is as you can see we have double coat so just remove the double coat and here also at the start line here also as you can see we have two double codes so remove one now as you can see the code line is in same color it means there is no error simple so here it is friends as you can see we have our images folder and then we have person so this person is basically the image name which we want to save so it will basically capture 85 images inside our repository and where we have our images folder and inside that folder it will save image name with person and the extension is basically jpg simple so let's just save our code and if I run the code as you can see it started our video file done so if you open our repository and if you go inside the images folder here it is as you can see we have 84 images it means we successfully capture 85 images of course the number 85 we mention here 85 frames so it will capture 84 frames that's it so we successfully capture our images for our own custom object detection model it is really easy now we need our label IMG software so for label IMG software we need python 3.8 version so just go here Microsoft store and then simply search for python so just search for Python and then python 3.8 version just selected the version click on install button done it will install python 3.8 most easy way so we have done with all basic steps we install our packages we have now our images we done with python 3.8 version so now we need to Simply change our version inside Tony python ID so go to the tools sorry not tools go to the Run config interpreter and here we need to select this option as you can see this one and then simply select python 3.8 exe because we need our python 3.8 version and insert shell as you can see now we have python 3.8.1 version done now simply open tools manage packages and label IMG this is what our application name which we are going to use for labeling our images label IMG and just hit enter application or we can simply say a package so label IMG and label IMG and then just click on install that's it it will install label IMG on our Windows machine which I have already installed done now go to the tools open system shell and let's just open our label IMG software label IMG this is what command hit enter it will open our label IMG software as you can see we successfully open now simply we need to select our images folder so open DI downloads our repository inside that we have images folder select it again change save di downloads our repository same repository and images folder done so we successfully mention open DI folder and chain save di folder the folder where we capture our images done now simply here we need to select YOLO and then create rect box and as I mentioned our goal is to detect person head so simply draw a rectangle on person head and mention the class name people click on okay create rectangle box draw rectangle box click on okay create rectangle box draw a rectangle box click on okay create rectangle box draw a rectangle box click on okay create rectangle box here also draw a rectangle box click on okay and then save it now if you open our folder uh downloads repository same repository and images and inside that as you can see we have person. dxt and we have all our rectangle coordinates which we draw with the help of label in so now simply go for next image same way draw rectangle box click on okay create rectangle box draw rectangle box click on okay create rectangle box then draw rectangle box click on okay create rectangle box draw rectangle box click on okay create rectangle box and draw a rectangle box click on okay so this is how and then simply click on save so this is how we need to draw a rectangle box on each person head with the help of label IMG simple so I have already done with this process so let me close label IMG software and then simply in downloads uh my training so let's just first delete the images folder because as I mentioned I have already trained images so let me delete images folder so if I go back again repository as you can see now there is no images because we deleted now inside downloads I have here my training folder and inside that we have images copy if I go inside the repository which we clone simply I'm going to paste the folder and images and inside that as you can see if I open or let's just say let's just open this images folder with our label IMG label IMG hit enter and then open DI download same repository and images folder select the folder as you can see as I mentioned I have already trained all images with the help of label mg here it is as you can see person person person class and I have already draw a rectangle on their face for each image for each image as you can see for each image I have draw a rectangle box on their faces simple so this is how you need to draw a rectangle box on their head and simply mention the class name Person done so we have done with our label IMG process now simply open our repository and here let me close my training folder so we have done with our label IMG process now simply here we need to create our freedom Tech folder so let's just create Freedom Tech folder new folder Freedom Tech this is what our name of the folder and again open Freedom Tech folder here again create two new folder images and label so images again new folder which is labels images and labels and then now simply select one of the folder so let's just select images folder first and here we are going to create again two new folder training and validation so right click new folder and mention the name training training and then validation so we create a two new folder inside Freedom Tech images so first we create Freedom Tech folder then inside Freedom Tech folder we create images and labels folder and now we are inside images folder and inside images folder we create training folder and validation folder again go back same way go inside labels folder and create two new folder training and validation so right click new training right click new validation done training and validation now simply copy paste all our data from images copy all the data from images go back and go inside Freedom Tech images training paste it go back validation paste it go back back labels validation paste it then training paste it simple so this is how we need to copy paste all our data from our images folder to Freedom Tech labels training validation and then Freedom Tech images training validation simple so we have done with this process also now simply create azip file of our freedom Tech folder so right click vrar add to archive. zip click on okay it will create our ZIP format file so we have done we create our fom tech. ZIP now simply upload upload our freedom tech. zip on your Google Drive so this is what my Google Drive right click file upload downloads repository again same repository and freedom tech. zip just click on open so it will upload our freedom tech. zip on our Google Drive so meanwhile simply open Google collap and inside the repository I have mentioned the training file for yate so click on upload browse downloads and our repository same repository and this is what our Google collap file click on open so now it will upload our collap file on our Google collap so friends as you can see we have successfully upload our collap file now simply go to the runtime change runtime type select python 324 GPU click on Save and then click on connect so friends as you can see we have 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 package so friends we successfully install our ultral ltic now simply import our modules then now we are going to cross check if ultral is perfectly working or not means if yellow V8 is perfectly working or not for that we are going to Simply use online image from media. roboplow docomo do jpeg so click on the code and then it will save our result inside our folder so here it is as you can see it save our result inside runs detect and predict and object which we detect from the images is basically here as you can see one person one car one dog this is the object which we have inside this image so it means we successfully install yolow on our collab now simply we want to mount our Google Drive so click on the next cell then click on connect to Google Drive select your Gmail ID click on continue scroll down click on unow and now it will Mount our Google Drive so friends as you can see we successfully Mount our Google Drive we have our freedom tech. zip inside our drive now simply create a folder named data set and inside that it will save Freedom tech. zip it will basically unzip all the data from Freedom tech. zip as you can see we have person person image and their text file so if you click on the folder data set directory which we create and freedom Tech folder inside images training and validation folder so if you click on person jpg and then here it is as you can see we have images it means we successfully upload our images for training purpose on our Google collab so let's just close image now what we want to do simply Freedom Tech click on these three dots just click on it and then it will open this kind of menu click on new file and we are going to create data. yl data. yl file just hit enter it will create empty file data. yml now double click on that file and inside this data. yl file as you can see it's open like this way here we are going to copy paste our code from our repository inside that I have mentioned data.txt text file copy the code close all the things and just paste the code over here inside data. yl and as I mentioned we have only one class which is person head so simply number of classes one and simply we are going to change the name so person done person then press control+ s it will save our code now we are ready and we are going to Simply start our training so just click on last sale it will start our training with 100 APO so friends as you can see it started our training 1 out of 100 so it will take some time meanwhile I will pause a video so friends as you can see we have completed our training and our model is basically save inside runs detect and train folder so just go to the runs folder then detect folder then train folder and inside that train folder we have weights folder click on it and then as you can see best. PT this is what our custom model custom object detection yellow model just click on here click on download and it will download our own model model so friends as you can see we download our model so just go inside downloads folder best. PT right click cut and just move our model inside our repository and then just paste it so here we are going to create our Coco 1.txt file so new and then text document Coco 1.txt Coco 1. txt is already there Coco Coco 1.txt this is what our file name and just open it and just mention our class name which is person person file save it done now let's just open our test.py and first close our IMG dopy and untal file and because we change our version as you can see so we need to go with our default version so just go here and select the first python version click on okay now we are python 3.10 our main version so here it is as you can see I have already mentioned best. PT so this is whatever test.py where I have already mentioned the basic code so if you don't know how to use YOLO V8 with python and open CV I have already create a playlist Watch Playlist and then you will get the idea how to use yate with Python and open CV so in test.py I have already mentioned the object detection basic code here it is as you can see Coco 1.txt the text file which we just create and then this is the video file name and here we have best. PT our model then we have our detection method and then we have rectangle as you can see we have rectangle then we have center point of rectangle of our object rectangle CX = to int X1 + X2 / 2 and C yal to int y1 + Y2 divided by two this is how we will get a center point and then we are going to use here a new rectangle method which is CV zone. corner rect for that we need width and height so wh is equal to X2 - X1 and Y2 - y1 we will get width and height so then CV zone. Corner Rec frame X1 and y1 then we are going to use width and height simple and then we mentioned CX and Cy so with the help of CX and Cy of course we can show the circle on our frame on our object so C2 Circle method CX and Cy coordinates radius color and minus one for filling our Circle then we are going to use cput text Rec method and we are going to put our person as a text on rectang top left corner this is the basic code for object detection simple now here as I mentioned uh we have our area but let's just first comment our area method let's just only detect our object so if I save the code if I run the code as I mentioned this is what basic code we have our own custom model we mention our video file and as you can see there is a rectangle on each person head each person head as you can see we have rectangle it means our custom object detection model is perfectly working it's not detecting full person body it's only detecting their head now it is really easy to create a counter here it is as you can see we only train 85 images but it's working perfect it's working for perfect and it's detecting only the person head simple so our model is ready and it's working perfectly now our goal is to create a counter for that as I mentioned we need a region of Interest area Ro oi simple so for Roi we have our mouse event function so mouse event function is here as you can see this is what our mouse event function so if you move your mouse on the frame inside shell we have coordinates we have XY coordinates so for this video as you can see our goal is to detect the person is basically in this area and in this area simple so let's just move your C over here and inside shell as you can see we have 547 and 75 so this is what my first coordinates then let's just say this is the second coordinates 573 365 this is the third coordinate 735 362 and this is the last coordinate then it will draw a poly lines in this particular area for this area also same just move your corser from here then here then here and then at the end here then it will draw the poly lines in this area so this is how I have mentioned the coordinates like this way I have already mentioned the coordinates inside the code so no problem here it is the coordinates for Area 1 and here it is the coordinates for area 2 now simply we are going to start our CB2 poline method it will use Area 1 and area two and it will draw our region of Interest area as a polyline so I have started a code and as you can see there is a red color polyline which is our region of Interest area it means now we can simply create our condition I just want to detect only the person if it is inside my selected region of Interest area simple so for this we have s2. Point polygon test method so here after where we have wh after that simply we can say result is equal to CV2 do Point P Capital polygon T Capital test Point polygon test inside that what our condition our condition for Point polygon test we need area and we need a point so for point we are going to use here their center point so CX and Cy so area is basically this so just copy as it is from NP to np. in 32 copy as it is mention over here simple then after that simply mention CX and Cy and then mention false now the result is basically 1 or minus one so if the result if it is greater than or is equal to Z then only we are going to draw a rectangle this circle and and then we are going to put our text on the frame on on basically the rectangle so if I save the code if I run the code and now as you can see here there is no rectangle on other area here we not mention our area here also we not mention our area but because our goal is to only create a counter for customer simple so for that we draw our region of Interest area here and here so right now only we are going to mention a condition for this particular area that's why here it is as you can see this person blue color Center Point is inside our area and it's detected the person but this person will not create our condition so let me start a while loop if I start while loop and now as you can see this person is still inside our area but when this person cross our area there is no detection there is no detection so simply we can create a counter so counter is basically the person center point so this is what our this is what basically our condition if the person here it is as you can see this person is cross over area now there is nothing so our condition if the person center point is if it is inside our area then only we are going to detect so simply here after our condition match simply we are going to create our list with their center point so list one. aen and what we are going to openend we are going to openend Simply CX and here we want to mention CX oh sorry not CX list list is equal to like this way and then if we go here on or let's just say here because after that we are going to show our counter on the frame so let's just mention here uh print print because we create a list and inside that list when the person Center Point if it is inside our area it will save there or it will create the list of CX list one so simply we can mention this is the list one with uh CX the coordinat so length of list is basically our count so print length of list one and if you start the code now inside shell there is a number there is a number for a person list one let me check oh I have mentioned here list so list one is basically the variable because we mention here list one. append so now it will work so insert shell watch there is two it means there is two person is basically inside our first area now there is one it means there is one person or One customer is in this particular area simple so same way for second counter let's just create a second counter condition same way just copy paste the code from result to list one and just mention over here check it is in line so I have copy paste the code now this is the result and here it's in line as you can see it's in line only we are going to change the variable so here we mention result so here we are going to mention result one so now if result F if it is greater than or is equal to zero and this is the condition for area two because we create area one condition now this is the condition for area two and let's just change uh Center Point color because we mentioned C Zone do corner rectangle rectangle method so it will not change their color so we can simply change the color of Center Point then we will get the idea so here for area one we mentioned blue color let's just mention here pink color so 255 0 uh 255 minus one then all things are same and here list one we are going to create list two so mention here list two and like this way and then simply now we know uh what we have inside our list so simply we are going to show our two list counter on our frame so let's just say here cr1 is equal to our length of list one and then CR2 is equal to length of our list two for area two now now simply copy paste the C on put text method mention over here and then uh then simply or let's just say cut after poly lines we are going to mention our our counter method on our counter we are going to put on our counter on the frame so C on put text Rec method and then the variable let's say counter one counter one for counter one we have cr1 so uh what else you want we want to mention here this is the variable counter one after that inside like this way inside curly bres C cr1 which is our first counter cr1 so we have done uh with our counter and then we need to mention here the frame coordinates where we want to put our text so let's just say 5060 5060 and then just copy paste the code and then mention a second counter which is counter two inside the curly Braes simply mention CR2 then 50 160 let's say and simply we are going to change rectangle size also the text size now we have our uh wait ke one means we start our while loop so simply save the code if I run the code and now as you can see we have our counter counter one we have we have right now two person so two is there counter two we have only one person as you can see there is a one so here it is as you can see it's little bit changing because because of our model so now as you can see it's it's frequently showing only one now the on the counter one we have zero person or we can say simply zero customer so here it is as you can see now we have two customer so the first customer is crossover region of Interest here now we have only one person so it's it's basically counting the person who is basically inside our region of Interest area so if this if this region of interest area if there is a two person or if there is a three person it will simply put that counter on the frame as you can see for this area we have one but on counter one there is no customer so zero is there simple so here it is as you can see there is another customer is basically coming inside this particular area and it's detected as you can see it's detected now there uh on counter two we have 2 person so now here it is as you can see One customer counter one we have one customer and counter two we have two one because of course there is a moment so if the person cross over area of course there is no counter but here it is as you can see it's perfectly working our model is perfectly working is counting the customer inside our selected region of Interest area as you can see there is two so we have two and here it is we have one we have one so this is how friends you can create your own custom object detection model for this kind of project I hope you learn something from this video I have mentioned the code inside repository we'll meet our next video till then thank you take care and bye-bye
Info
Channel: FREEDOM TECH
Views: 2,151
Rating: undefined out of 5
Keywords:
Id: t61EqN8ZwDQ
Channel Id: undefined
Length: 38min 46sec (2326 seconds)
Published: Tue Dec 19 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.