drone object detection and tracking yolov8 | yolov8 object counting and tracking | counting people

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 I have here drone video recording of marathon okay there are people which basically running for marathon and I have here a drone video recording of marathon so simply what we are going to do we are going to use our yellow V8 pre-trained model and we are going to create the counter for people ok but we are going to use drone video recording footage simple 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 for this project first you need to install opencv and yellow V8 on your Windows machine so this is Windows 11 of course you can use your Windows 10 machine also I have already created the video how to install Sony python Rd then opencv and yellow V8 on Windows machine I will mention video link watch video and install all these basic packages so for today's session I have created here a repository and the repository name is drone view people counter yellow V8 okay so I will mention the link you need to Simply copy and paste the link inside the browser then go to the code and we are going to Simply uh download zip format repository okay so remember one things friends if you don't know how to track and how to detect the object with the help of evaluate I have already created the video I will mention video link watch video then you will get the basic idea how we can use yellow V8 and how we can track the object with the help of yellow V8 and our tracker simple so we download our repository so this is what our repository simply what we are going to do we are going to Simply extract here our repository so let's just extract as a folder okay so this is what our folder go inside the folder and then first we need our video file of course so just open the download.txt file this is the link of our video a Drone footage okay so let's just minimize all these things open new tab and press Ctrl V it will paste our link and it will open the mega Cloud link simply click on download and it will download our video file so done friends as you can see we have our video file ready simply go in show in folder so this is not our video file so right click and what we are going to do we are going to extract our video file so simply click on extract here it will extract our video file so we need to move our video file inside our main repository so just right click and we are going to cut our video file cut and go inside our main repository and just paste it that's it so first what we are going to do we are going to run our video file so just open the video file and friends as I mentioned this is the Drone view or we can say this is the aerial view where a people are running for Marathon so our Target is what we need to create the counter for people with the help of yellow V8 okay so I have already created the video how to use yellow V8 for object detection so I'm not going to explain how to use yellow V8 for object detection we are going to start from tracking process okay so if you don't know how to use yellow V8 with the help of opencv and python I will mention video link watch video then you will get the idea so for this session I have mentioned the basic code where we have object detection with the help of YOLO V8 pre-trained model okay so this is Whatever video file and our Target is what we need to count each person okay each person simple so ready so what we are going to do we are going to first open our main dot Pi the basic code okay so I'm going to minimize all these things and right click and let's just open with our Tony python ID so this is what our basic code where we have yellow weirds.pt a pre-trained model and I have mentioned here a video file link also not link basically I have mentioned the video file name p3.mp4 then this is what our coco.txt file where we have all the classes and we are going to read the classes one by one with the help of our YOLO V8 class IDs so here it is as you can see because we want to detect here only one object which is the person so I have create the condition if the person in our C so C is basically our class uh variable okay as you can see class list this variable is represent our coco.txt file which we have inside our repository here it is as you can see coco.txt this is whatever file simple so this is the basic basic code for object detection so now we are going to run our code and of course it will download first our pre-trained model then we will have the object detection with the help of yellow V8 okay so let's just download uh our uh basic model first so friends as you can see it's detecting each person separately so we can simply say yellow V8s is the best model for object detection okay it's detecting each person separately so we have our object detection now what we want to do we want to track each person means we want to assign the ID for each person so for that we have our tracker so inside repository I have mentioned uh tracker dot Pi tracker dot Pi simply we are going to call our tracker dot Pi so here it is as you can see from tracker import all so I have mentioned the tracker file inside our main file and we are going to call our tracker.pi in our main dot Pi uh we are going to basically import all the things from our tracker.pi so let me show you here because I have already explained all these things in previous videos so this is whatever tracker dot Pi okay and here we have a Tracker class so we are going to Simply use here our class so I have created here a Tracker is equal to tracker class because inside our file we have tracker class so tracker is just a variable and this one is basically the class then we are going to use our update function and we are going to ascend object detection a rectangle coordinates okay simple so let's just scroll down and where we have detection if the person in C so we need to send our X1 y1 X2 Y2 in our tracker file so for that we need to create the list so I have mentioned here list so simply what we are going to do where we have our condition here we can say least Dot append list dot append and of course what we want to open we want to append our rectangle coordinates because the rectangle coordinates is basically our object so X1 then y1 X2 and Y2 simple that's it so now we have our list so simply what we are going to do we are going to create a new variable so first let's just check it is in line so it's in line now here so let's just create the new variable which is a b box ID okay let me check again if it is in line yes I think it's in line so B box ID is just a new variable and B box ID is equal to we need to mention our tracker so tracker variable which we mention here tracker is equal to our tracker so we need to call the tracker and we are going to mention our update function which we have inside our tracker.file okay so simply here we can say tracker dot our update function and inside that we need to pass our list list which we create okay our rectangle coordinates simple so we have our list ready or sorry not least we have our B box ID ready so now what we are going to do we are going to Simply create a for Loop so for B box in for B box in bbox ID for Big Box in bbox I did now with the help of tracker again we are going to track basically the person so again we have new uh rectangle coordinates and new variable which is the ID because with the help of tracker we are going to track the person so how to know we are tracking the person of course we have rectangle coordinates and then we are going to assign the ID for each person so we need a new variables for a rectangle so X3 Y3 and X4 and y4 and the new variable which is the ID is equal to our B box simple now we have our rectangle coordinates so simply we can draw the rectangle so we have already rectangle methods due to dot rectangle what we are going to do we are going to only change the coordinate so X1 will become X3 y1 will become y 3 then X4 and Y 4 simple X4 and Y four that's it now we need to put the ID on each rectangle top left corner so Str ID and top left corner our rectangle top left corner is basically x 3 and y 3 that's it so if I save the code if I run the code so friends as you can see we have enabled our tracker and we are tracking each person and we assign the ID for each person for this person as you can see we have 45 then for this person we have 96 for this person we have 107 okay so we are successfully tracking each person and we are assigning the ID for each person that's it we have done with object detection and tracking now what we want to do we want to create a counter so for that simply we are going to use C2 dot line function so let's just first chop our code means we need to freeze the frame we are working with one frame means a first frame so let's just first close our tracker dot Pi so this is what our first frame okay so what we are going to do we are going to Simply create the line and as I already explained in previous video how to count the objects with the help of line simply we are going to create here a line then we are going to create a center point for each object then simply we can say if the center point of object touch the line then we can simply count the person or we can simply create the counter okay so here we can see let's say here simply we can draw a line here okay so inside the shell because we have a mouse function so we can simply get the coordinate so let us see here we want to draw the line so start point is here 335383 so let's just mention here three three five three eight three so three three five three eight three okay three three five three eight three so three three five three eight three I think here okay here so if I go from here let's say over here end point six nine six three seven seven six nine six three seven seven okay six nine six three seven seven so now we have our coordinates simply we are going to draw a line so let's just create our CO2 dot line functions U2 dot line then we are going to draw the line on our frame frame then this is what our first coordinate our start coordinates three five three eight three and three three five three and three okay and then we have six nine six three double seven this is whatever n coordinate and then we are going to create a color so let's make 255 means zero two five five zero so let's make green and then thickness let's say two okay so if I save the code if I run the code and as you can see friends there is a line simple now what we are going to do for uh for creating our condition we need to mention the Y coordinates same as here means this is what our start line coordinates so this is the X and this is y so this is the n coordinate X and Y so if the 383 is here so here also we need to mention three eight three so let's just say three eight three okay so if I save the code if I run the code and as you can see now there is a perfect line that's it now we have our line ready now what we are going to do we need to create a new variable for line one which is c y one okay so let's just create here our cy1 Cy 1 is equal to what c y 1 is equal to our Y coordinates of line our y coordinate so our Y coordinates is basically 383 our line y coordinate so c y 1 is basically three eight three our line y coordinate so we have now 383 is basically C by one so simply instead of number we are going to mention C by one cy1 here also c y one simple that's it now we need offset so let's just mention our offset so offset is basically offset is equal to 6 that's it we have done now we need our Center points so we have our coordinates here this is whatever let us coordinate with the help of tracker so we are going to create the center point for that we need c x and c y so c x is equal to inch and then X3 plus x 4 divided by 2 X 3 plus x 4 divided by 2 and then C Y is equal to and X4 sorry not x four y three plus y 4 divided by 2 that's it we have our Center coordinates ready so simply with the help of a circle we can draw our center point so CV2 dot Circle and inside that we need to mention frame then our coordinate which is c x and c y then what else we want we want radius so let's say three then the color let's make pink one so two five five zero two five five and because you want to fill the circle so let's mention minus one so if I save the code if I run the code and friends as you can see we have Center Point for each person simple so we have done now what we want to do we are going to Simply create our condition so as I mentioned what is our condition when object Center Point touch the line then only we are going to create the counter so here we have our c x and c y simply we are going to use c y one and center point of c y this one c y okay so if our c y one is less than c y or Center Point c y plus offset plus offset and and cy1 is greater than c y one is greater than c y minus offset Cy minus offset then only we are going to say we want to draw the rectangle we want to draw the circle we want to put ID as a text on our person means on our person rectangle top lip corner so if I save the code if I run the code so now as you can see there is ID on the person the per which person the person those person Center Point touch the line then only we have the ID and the rectangle or this all these uh processes okay simple so here it is as you can see when the person watch for this person watch for this person okay so there is no rectangle there is there is no ID there is uh no Circle okay there is no Center Point so when the person touch this line there is a ID there is a rectangle there is a Center Point that's it we have done now simply what we are going to do we are going to create a counter so here we have our put text method so let's just say uh first we want to create the counter variable so here we need to create a counter and this one is basically our empty list empty list and here we can simply say counter Dot append and of course we need to pass our ID simple okay now I already explained in previous video when the person touched the line it will take some time to move or we can say to cross our area so in meanwhile we basically count the person again and again so we have same ID again and again so simply what we are going to do we are going to Simply create here again new condition please don't count same idea again and again okay so let's just say if counter our counter dot count and what we are basically account we count ID is equal to zero means don't count same ID again and again only count one once simple so here counter dot append that's it now simply after where we have CO2 dot line function if you watch my previous video then you definitely know what all these things okay so print uh counter and now we know what we have inside our counter we have each object ID this is the list okay so simply we can say length of our counter length of our counter is basically our counter for person simple so if I save the code if I run the code now as you can see we there is a one two three four the fourth person is basically touch the line and we have basically counter so let me show you as you can see the fifth one is touch the line there is a sixth one now seven one so we successfully counting the person when the person Center pointers the line of course we are counting the person simple so now what we are going to do we are going to Simply create here a variable let's say L is equal to length counter and then we are going to use CV Zone a put text erect method okay so I have installed CV Zone simply you need to go here tools then manage packages and just search for CV Zone hit enter and this one is the package just click on install and it will install CV Zone on our Windows machine so let's just mention our put text method so CV2 CV2 not CB2 we are going to use series on so we need to mention CV Zone CV Zone dot put text sirizone.hot text is capital put text wrapped r capital takes rect and then we are going to mention where we want to draw our where you want to put down text of course on our frame so frame frame is there then what else we want we want to mention now uh F and then like this way the variable let's say counter and inside that we need to mention our L because L is our counter so l and then what else we want uh F counter L then uh we want to mention the rectangle size because basically we are going to uh insert the text inside the rectangle so this one is basically the rectangle size and this one is basically our text size symbol so if I save the code and I forgot to mention where we want to put the text so we need to mention the coordinate so let's say 50 60 50 60 like this way 50 60 okay I hope you all clear so if I save the code if I run the code and as you can see there is a rectangle and inside that we have text so let's just increase the text size font size so here I need to mention two and if I save the code if I run the code so we increase the font size now it's look really good so we already count the fourth person because there because their Center Point is touching our line so now what we are going to do simply we are going to run our while loop and let's just watch magic okay friends so when the person uh Center Point touch our line we have counter we are basically counting the person okay we are basically counting the person as you can see watch for this one that's the line 38 okay so friends this is how uh with the help of you know we had we can basically count drone view drone view objects okay drone view objects so I hope you will learn something from this video we'll meet our next video till then thank you take care and bye
Info
Channel: FREEDOM TECH
Views: 5,990
Rating: undefined out of 5
Keywords:
Id: NFOQqnmgMDY
Channel Id: undefined
Length: 23min 10sec (1390 seconds)
Published: Tue May 02 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.