Mastering Face Detection with YOLOv8 | AI Tutorial for Beginners

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today we are diving into the word of face detection using YOLO V8 one of the PowerHouse of object detection join me as we explore the fascinating journey of YOLO V8 in sporting faces with precision and speed whether you are a season developer or just curious about AI this tutorial will unravel the secrets behind face detection like never before if you are excited about this tutorial kindly give me a thumbs up and also subscribe to the channel and most importantly put on the notification Bell icon on so that you don't get to miss any of my future goodies enough with my self promotion stuffs let's get right into it finally guys welcome to the fun path let's get our hands dirty and write some code but before we get started with the code the files the code and everything we'll be using in this particular tutorial will be on my GitHub repository where you can leverage and use it in your own use case and also don't worry about installation because I will include the requirement. TS file where it to include all the packages you need to install in order to follow along so we are not going to waste time on installing any packages so the link to the code the files and everything will be in the YouTube video description so just click on the link and it will send you to my GitHub repository where you can download all these files and use so we first have to download the model we use the face detection model the link to this particular repository will also be under the video description where you can download this model so you have to scroll down and at the down here we have several face detection model we have the Nano which is the smallest one so that means you have more speed when running it but it's less accurate we have the medium you have the large and we have other models there as well our focus in this particular tutorial will be on the Nano model you can explore the other models as well you can just download them so you have to just go ahead and click on the Nano model and it will get downloaded so make sure after downloading this model you place it in the same directory you are writing your code so I've gone ahead and downloaded this beforehand all you need is to just click on it with this step down we'll head back to our ID and start to write some code so you can see I have my model downloaded here and it's in the same directory where I'm working so I can go ahead now and write some code so we are going to start with the import as usual and with this particular tutorial we import opcv ultral and finally we import CV zone opcv for loading in our video feed and also display our video feed CV Zone we use it to play some nice text on our video feed and finally aties which we use to load our model and do our face detection with this out of the way we'll go ahead and specify the path to our video so I have a video file on my desktop so here are the video so I'll just copy this particular path past it here don't forget to put R here and also specify one of the video names so I'll cross check and I think one is people MP4 so I'll just write people. MP4 here with this we have successfully loaded the video file we'll be using I also teach you how to use your own webcam to detect your own face now let's go ahead and create a video capture object so we are using CV2 the video capture and in here we can fed in our video file so in case you don't want to use your video file then you can specify your camera index you can start off by putting zero here which will pick up your first camera or your camera connected to your computer if you have many cameras you can start from Z 1 2 and so on but in this case you are going to do it on a video file and we've loaded that video file so all you need is to specify it here the next step is go ahead and show this video file we have done this ton of times in this channel so I'll just go ahead and show the video file all right so with this few lines of code we'll be able to show our video file so I'll go ahead and run it and let's see what pops up so you can see here is our video file we'll be using but straight out from the batch you can see this video file is very big and we need to resize so that's what we are going to do next to resize it we use the resize function in opcv we still call this video and we use the cv23 size okay so we use the resize function we provided our video and the size we want feel free to change this size on your own so if you don't like the size you can specify your own height and WID here let's run it to see our video file in action okay so you can see we have got a much smaller video size now and with this now we can work and fit this particular video file into our model for detecting faces you can't wait for that right I know so let's go ahead speaking of detecting faces we have to go ahead and load our model so we have to first load the model then we can fit this particular video file into the model so I'm going to call this face model P my choice of variable and then we use the YOLO and in here we specify the name of the model which is Yolo V8 face Nando face. PT so this is it so we can come down here and now feed this particular video file into the model and then we are ready for detections so we will see our face model do predit and in here you have to give it a video file and additionally you can specify the confidence value so right from the start I'm going to set this confidence value to 40% you can modify it as well so this will return TOS our result so we call this phore result so now we can look over this face result to get our bounding B coordinate on each detected pH so I'll just go ahead and loop over it some number of times and now get those coordinates then we can use those coordinates to draw the rectangle on each pH detected all right guys so what I've done here is to iterate through the face result save everything to parameters and over here we are just getting info do boxes so this info do boxes will return return to us our confidence our class which is pH in this case and our bounding box coordinates but we are only interested in our bounding box coordinates so we also iterate through the our parameters and we use box here to refer so we get our bounding box coordinate by doing box. xyxy we are taking out the first index so we go ahead now and cast this particular coordinate into in integer values because by default they are float values and we can't use float values to draw our bounding box okay so guys I went ahead and casted all these values into integer values so the next thing is to draw our bounding box so you can use the CV2 rectangle method to draw a bounding box but I find out that using the CV Zone to draw a bounding rectangle looks very nice but for that you need to do some additional test by getting the width and the height of each bounding box coordinates so we have to calculate for our height and our width which is simple by subtracting some coordinates from one another so we start off by subtracting y1 from Y2 and for the WID we have to do the same thing so all we have to do now is to go ahead and draw the bounding rectangle on each detected face and that's the last thing we are going to do so we use C zone. Corner R and in here we specify our video then the next thing we need to specify here is the coordinates so it takes this as a list and we give it the X1 y1 then finally we give it our width and height okay so these are all you need to specify you can add some things as the border of the width and all those stuffs so uh we can do l = 9 and RT is also equal to three okay so that's it so this is the final thing we need to do let's run it now and see how it performs and here we go guys you can see it's accurately detecting the faces this is awesome guys what do you think let me have your opinions in the comment section below I think this is D accurate this is detecting each and every face in the frame this lady here or is it a guy face is not that facing the camera but still detecting it at the sideways I think this works great so we'll test this on some couple of videos we have about three videos there this the first one so let's run it on the remaining two videos and see how it performs so we have 10. MP4 let's see how it performs on that video as well and boom here we go guys you can see it's performing accurately it's still detecting the faces so guys in my opinion this model works great and I think it's a model you can trust it's a model you can use for your product your project and everything because it's detecting the faces and I think it's it's accurate it's accurate it's perfect and bear in mind this is the Nando version of the model so imagine using the large model the medium model you can get more accuracy than this but in my case this was great so finally we load in the last video and then we'll bring this tutorial to an end and here we go this video have a lot of people in it but you can see the model still do a great job some faces are very small here but it's still working great so guys this is it if you like this tutorial give me a thumbs up if you are new kindly subscribe and also share this tutorial with someone one most importantly put on the notification Bell icon so that you don't miss any of my future goodies as usual thanks for watching and I will see you in the next tutorial
Info
Channel: Tech Watt
Views: 1,231
Rating: undefined out of 5
Keywords:
Id: ugI8E5GzKyM
Channel Id: undefined
Length: 11min 40sec (700 seconds)
Published: Sat Dec 16 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.