Real-time Fall Detection Using YOLOV8

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today I'll be teaching you the most easiest and  simplest way to implement F detection using YOLO   V8 I'll first take you through the theoretical  phase where you will learn how to use Simple   mathematical concept to determine whether  someone has fallen or not then from there   I'll teach you how to convert this mathematical  concept into python code that you'll be able to   use to determine whether someone has fallen  or not ready to do it let's get right into it [Music] all right guys so before we get our hands dirty  in writing some code let's first go through these   slides and see how we'll be implementing this okay  so uh we'll be implementing this considering these   two scenarios and the first scenario is when  someone is standing so in the first you can   see the first robot is standing and the second  robot has fallen so when someone is standing   generally we assume the height is longer than  the width so the H here donates the height and   the here donates the we so any time a person is  tumbling the height value is longer than that of   the weight and to the other image here you can  see the robot has fallen and we assume anytime   someone has fallen the weight becomes longer than  in height so considering this Vital Information   we'll be using some mathematical approach in  order to identify whether someone has fallen   or not so over here we'll be using Y V8 for object  detection and uh when we use V8 normally when we   detect objects we get the coordinates in the form  of U some values you get X1 y1 X2 and Y2 in order   to be able to calculate whether someone has fallen  or not we have to be able to calculate our WID and   height from these particular values because  the width and height is all that matters to   us so to get a width we have to subtract X1 from  X2 and to get the height you have to subtract y1   from Y2 so this will give us the values for the  width and the height the value of the width when   someone has falling will be higher than that  of the height in order to know whether someone   has falling or not we will subtract our width  from the height and what we get that this rain   has a value which we call the four threshold so  whenever the width value is higher than that of   the height we get the negative value which shows  that some has fallen because um I established the   point here that when someone has fallen the WID  here becomes larger than the height so when we   subtract the WID value from the height the value  that we are left with will be a negative value and   based on this negative value we are going to put  something on the screen that okay we the a fall   or deted that someone has fallen so this is the  algorithm using in order to detect a this a simple   one anyway let's go ahead and see the steps we'll  be using so the first steps we'll be using is to   implement our object detection so once we are able  to implement object detection using your L V8 you   can be able to extract the coordinates X1 X2 y1  and Y2 then right after getting this coordinates   we can be able to find our width and height by the  formulas with SC right here then getting our WID   and height we can calculate the four threshold and  whenever this four threshold fall Bel zero or we   get a negative value we know okay we've detected  a for so apply the falling condition and in this   case we just put it on the screen that somebody  has fallen or someone has fallen after this we   will conclude and that will be all for this  tutorial so this is the theoretical aspect of   this tutorial let's get right and get our hands  dirty so on my desktop I have this folder here   called for detection and when I open it everything  we need to complete this tutorial is right here so   um we have this video which we'll be using and  it's just a gentleman walking all of a sudden   he's sleep off and fell so we try to detect this  actions get whether the person has falling or not   that the video be using and this the python file  will be using these are the requirements file so   requirement TST and the only requirement we need  is neutralities so um I'll go ahead and open this   folder Vis studio all right so um right here  you can see we have all those files the viral   environment has created the classes TST file and  this contains all the objects in the PO data set   our pre-train model can detect and over here is a  video file I've show you beforehand then we have   the code here which is the main do spice so I'll  take you through this code um I'll teach you what   each and every line of code is doing right  here you have the pre-train with here which   in your case when you run the code for the first  time it's going to download for you so make sure   you have internet connection when you are running  this code for the first time or you can download   my pre-ra we I'll be putting on my gab repository  the link will be in the video description so all   these file you see here will be made available uh  on my kab repository so just follow the link and   you'll be able to get access to all these files  right okay so let's go into the code okay so first   things first we go ahead and import this liaries  and once you installes automatically it will go   ahead and install CV2 so for the math Library  when you install python it comes with it then   you need to install C Zone as well then after  importing this libraries what we need to do is   to read in our video file so I'll show you the  code responsible for reading in your video file   so right here you create a capture object and  the function is CV2 video capture and in here   you specify your video file if you don't have  a video file you want to use your webcam then   you just need to put zero right here and that this  will pick your first camera so that's your webcam   if you have a camera connected to it you can go  to one and so on but in our case we are going to   use the video file so we specify the name or the  PA to the video file right after this the next   step is to load in the YOLO model using so we'll  be using Yol V8s you can choose to use any of the   Y models just by changing the name there then  the next step is to read in this classes. TST   file we have right here so we have classes. TST  which I said earlier contains all the objects   you canect the next step is that since this is a  video feed and we'll be taking it frame by frame   we are reading it right here so red frame is three  and we are interested is this Frame this retains   youant value which shows your video is available  or not then we take off our frame and resize it   into this particular shape you guys should feel  free you can resize this into any shape you want   after resizing we fit this particular frame into  our model for predition so um all the objects   we detected in the video will be in this result  variable what we need to do is to R over it for   some couple of time in order to get our bounding  BS information I have a tutorial on all of these   how to get these informations so our link will be  in the description as well you can check them out   so we over here we are just running a for loop on  them getting our X1 y1 X2 Y2 since it's a FL value   right here we are casting them back to integer  then we get our confident value as well and you   can see we are also multiplying our confidence  value using the M we multiplying to by 100 so   that we can get it in perced straight away then  the next step is to also get the class we are   able to detect is it a person is it a bicycle  is it a phone in this case we are working with   person but since we are reading the whole class  classes. file we are matching the particular class   detected you V it gives you the class detected  as integer value so you can see class these are   integer value so we are just mapping the integer  value which corresponds to whatever we are getting   our classes. TST so if the value you get is one  then you know if a person if it's two you know a   bicycle but because we are using python it starts  from zero so whenever you detect person you V it   gives you zero and then we match the zero to  its corresponding value which is a person we   are also getting our confidence as okay so now  after getting all this Vital Information what   we go ahead and do is to calculate our height  and width and in the slide I told you to get   the height we subtract y1 from Y2 be in mind that  we are getting this vales here we do the same for   the width X1 from X2 and then we we have to go  ahead and calculate our falling threshold which   is we subtract the WID from the height in order to  get that falling threshold now after getting this   falling threshold we can ahead and know whether  someone is falling or not because we know whenever   the value here is less than Z that mean somebody  has fallen that mean our we value is bigger than   the height that mean someone has fallen something  has happened so we have to put on the screen that   okay we' deted that somebody has fallen so that's  what I'm doing right here so if threshold is less   than zero we just render this text here that okay  f is dictated and then we give the position and   the thickness and the skill so that's what we are  doing then the other line here is that we are also   rendering whatever we are detecting on the screen  so if our confidence value is greater than 70 and   our class that we are detecting is a person we  are just drawing the bounding box using C and   then we are also putting the text of whatever  we are detecting on the screen and in this case   it's class detect so if we detect a person person  will be on top of the Bing poxs after this we just   show whatever we are getting so we are showing  our frame here and we have also implemented that   when you press the T on your keyboard everything  breaks the quicks so this all for the code and I   think have done my best to explain it well if in  case you don't understand any line of it do your   best to comment and I I'm ready to give you more  feedback on that so I'll go ahead and run this   code and let's see how it performs okay so here  we go it's what no fall falling action is being   detected so far so let's see when he slips off  so as at now the height value is longer than the   WID so they in normal condition nothing happens  suddenly our guy SS off painful action let's see   and you can see now um our we becomes bigger than  the height so the value will be negative and I a falling activity so fall so this how easy  we can implement this using Python and you   it all guys so this is how it works even though  this may not be the best approach to detect for   but I think it works in this case so um in  upcoming videos you may also explore other   methods of detecting falling activities so  stay stay tuned and also if you like this   tutorial give me a thumbs up subscribe to the  channel and also share these videos with one   or two of your friends thanks for watching and  as usual I will see you in the next tutorial
Info
Channel: Tech Watt
Views: 1,221
Rating: undefined out of 5
Keywords: yolov8, segmentation, image segmentation, object detection, ai, machine learning, deep learning, pytorch, python, pytorch tutorial, computer vision, data science, pandas, programming, image processing, data processing, license plate detection, number plate detection, car detection, vehicle detection, yolov9, yolov9 on custom dataset, YOLOv9 custom model, REAL TIME OBJECT DETECTION, fall detection, ultralytics
Id: wrhfMF4uqj8
Channel Id: undefined
Length: 12min 13sec (733 seconds)
Published: Fri Mar 08 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.