Real Time Object Detection with YOLOv10 and Webcam

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so by the end of this tutorial you will learn how to perform real time object detection using stateoftheart yo V10 model and your web account if you're a beginner don't worry this tutorial will be beginner friendly and we will start everything from scratch before we get started if today is your first time do me a favor by Smashing the Subscribe button and also click the like button so that many people will get to see this video and also learn as well enough with my self promotion stuff let's get right into it all right so the agenda for today is that I will be performing real time object detection via our webcam but uh before we actually do that I would love to show you some couple of things so I'll first teach you how to perform object detection on images using y v 10 and then we'll move on to how to assess important um information from detected objects so information such as maybe the bounding box the detection confidence and also the particular class in which an object is detected we also learn that before we move on to finally the last step where we detect object via our webcam um let's get into it and see the files we'll be using so over here I have b.png and this contains some images that will be trying to detect uh this particular B on I also have PNG and you can see how it looks and finally I have myself which I'll be using this image to try the model and see how best it detects me all right so with the images out of the way the next thing you have to do is to install some couple of libraries and today we are lucky enough we'll be using only two libraries orales and CV Zone okay so orales will help us to Leverage The Y model and CV zone is kind of a wrapper for the opcv library which will help us to um we are just basically using it to draw some text okay on our detected object so that's or by has other functionalities if you have been following this channel you should have known by now so um fast forward I'll just open my terminal so terminal new terminal and over here I've already created a vector environment so I'll just activate it and then install the packages okay so once you uh get this code from um gab because I'll be putting everything on gab just um write peip install hyphen R then you type requirement. TST and this will go ahead and install all the libraries in the requirement file for you you see I've already installed this so as usual requirement already satisfied but for you you have to make sure you are hook to the internet because it's going to take some time to install okay so I can click this off and the first thing I'll do here is to create my main.py file all right so inside main. Pi I'll first go ahead and import AAL so from utal I'm going to import y also I'll go ahead and import C so just write import sa all right so now to detect um objects on an image I'll it's very simple so instantiate a model and we call this model Yow an instance of a Yow model and the particular model we'll be using today is the y v 10n so we just Ty it inside here this is the particular model we'll be using and uh make sure you are connected to Internet because the first time we run this it will go ahead and install this particular model in your directory okay so after instantiating this model we can just say our result is equal to model and inside here you put in the image in which you want to perform the detection song so very very simple um we'll start with my image which is s. jpg so that's the image you do and after this we can just do results do show and this will show us our image um my bad it should be result at z. sh and this will show us um our objects and then detections as well so I'll quickly run this and this will take some time okay so over here you can see he downloading the model and it's done that's it you can see the model right here now so next we are waiting for our DET and let's see how we can get that as well and here we go guys so you can see it has detected me with an accuracy of 91% and this is the Nando version of YOLO V10 so you can see it's performing quite well on this particular image so let's go ahead and switch up to another image and see how it will perform on that image as well so instead of Sam I switch it to um I think let's do c PNG you get access to all this file on the gab repository so the link will be in the description so that you can leverage all these images and everything so that you practice on your own waiting and here we go so let's see how it performs on this particular cast so you can see deted a person a track over there that's actually not a track and the confidence is 0.42 so that really shows that but it's quite High though don't know okay so it perform this is how it performs from this particular image it's quite good considering the fact that we are using the Nano version of the model and he's doing this great job um I think it's fair enough let's out try this on the final image which is beds PNG and see so beds. PNG here we go so this howting these beds I don't know the some with very low confidence like this particular one 0.32 this ones with very high confidence so um YOLO V10 in action here I think you guys can uh judge comparing this to other YOLO models but I think uh straight off I can see that this particular model y v model suffers a lot detecting smaller objects it doesn't seem to detect smaller objects so well as compared to the other our previous yo model it predecessors all right so this is how you can easily detect objects using YOLO our V time so this bring us to our first um objective we've achieve our first objective so the next objective is to learn how to assess um the important information the bounding box information the um detection confidence and also the class names I think those are very important things we need how to assess them so that we can get them in variables and use them so let me quickly show you that um so I'll comment this then at the down here we can actually write so we will be accessing important information from all detected objects and for that we don't want to show the image again all we care about is the results we should comment this one out and then we can access this result variable and get um some output so first what are be doing is to print whatever is installed in this results and then from there we can know how we access everything we need so um I'll quickly run this to print that out let me collect the terminal and run this once again all right and here we go so when you print this you can see we are getting a lot of things this just gives you information about the time it took to run the inference and the image but we are interested in this particular thing so first you can see um this is giving us our bounding box information and this is stored in boxes okay so in order to assess bounding box information and confidence information we should access it from boxes our key point is none we are not doing post Max is none we are not doing segmentation here and also we get uh access to the names so you can see we have the names here one is a person zero is a person my bad one is a bicycle and so on then from there here is the image so to access the image we have to be able to get original image I think and then lastly you can also assess the shape the path and whatsoever so these are all the outputs we can get from the results variable so now let's see how we can access this um using the python code so now I'll comment printing of this results and then we are going to assess the data so first let's um learn how to assess the bounding box okay so for that we say our results at in there zero do boxes okay result at in the zero do what boxes and these boxes come in so many form um we can get it as XY XY you can get it as X X Y width and height you can access any of them or what I'll do is to print it so that we get a fair idea of how it looks like let me just wrap this in a print statement so here we go so you can see um after accessing the boxes we can get our class okay we can get our confidence we can get our data and all of these are tenses you can if if you can see they are all tenses okay so in order to use them you know we have to convert them to nonack also now to get our bounding box you can see the bounding box comes in uh different variations you can get what XY width and height you can get XY withd height and N we can get X YX Y which I prefer so X YX Y is like U normal bounding box we used to uh we use in opcv we have X yxn so we can choose from any of these so assessing um result the boxes we can get our class we can get our confidence and we can get our bounding box and that's what we need okay that's the informations we need so let's try and assess them so um this will do boxes. xyxy and this will give us that particular format it's a P Touch tensor so you can convert it to nonp by writing nonp and we can also convert the values to integer if you want and you just do it do as type in so inside here instead of mp. FL you can even do away with non and just right okay so this will assess it as um a nonp array and also give you the type as in all right so this is how we can access the bounding box all right so let's assess the rest of them okay so this how we can assess this key important thing so we are able to assess the confidence we are able to assess the class detected we are also able to access the Bing box but bear in mind that um this class detected is not going to be an actual name is going to be an integer so later on when we are learning about how to get object detected in our live webcam we are going to use that particular value or integer value to access the class name earlier when I printed it you saw the class names um and you know how we can access those ones as well all right so this exactly how you can access those things you just have to print them and you can get all of them okay all right so that that's exactly how it is so I'll just comment it out you guys can run them as well and that's going to quick we move on to the final PA and this path is what all of you are waiting for how to do object detection with Yol V 10 via your live webcam so um let let's quickly do that okay so let me give space here accessing item then finally we are going to do live I just do live um and that is it so for that um we need to still import these two things we need to instantiate our model and then I'll just comment this one out so the first thing is to access our webcam so to access our webcam we need to import opcv and once you've installed AAL open CV by default gets installed so you can just import CV2 and after importing CV2 you can now access your webcam so look up is equal to to sa it to video capture so inside here you give you your camera IND this if you're using your laptop camera just putting zero there but if you have additional cameras you can start from one two so on to get a particular camera you want to work with for mine I will be using one but I don't want to use my computer webcam I have a camera attached to the computer so the index is one I'll just put one there now we can initiate a while loop so that we take this video each frame so I'll say while through which is always through I'm going to get red which I don't need just um gives you true or false either you have your camera open or not so the next thing is my image and this is equal to app. read all right so now we've grab our webcam the next thing is to show it so I can just do CV2 show and inside here I can go ahead and show it I also do we key and I'll put we key of one so that this repeats so um let's test this out right guys so here I am you can see me live in the webcam so now we are able to get our video feed from the webcam the next step is to fit this video feed through the model and get our important details such as the bounding box the class detected and also the class confidence and then we are good to go so let's go ahead and do that okay so we go ahead and just um still write our results and this is equal to our model we' instantiated at the top and over here we pass in our image okay so inside this result now we can uh look through it and get our particular information that we need so um I can just say for my particular info in results so in this particular info I'm going to get uh the bounding box which I'll get from the bounding box as I showed you earlier we get um this informations from it so I can say uh my parameters is equal to our info do boxes all right so now I can look through this uh parameters and get my bounding box my class detected and so on box in parameters I think that so for boxing parameters we'll go ahead and get our rounding boxing for X1 y1 X2 Y 2 so X2 Y2 is equal to box do xyxy you remember how we assess the same thing um before coming here so this shouldn't be a problem and we are taking at the first index okay so um as usual this going to return to us a py TENS so we have to convert it to non pi and also not to forget to change the type to as Ty we don't want float because later on we'll be using opcv to render some rectangles and opcv accept integer for rendering rectangle so we have to make sure we convert it to integer values now we can also get our confidence I also go ahead and multiply this by 100 because um I will need the confidence to be in uh percentage so from 0 to 100 so that I know where is detecting something by 50% 40% and so on so by default it will just be a floating point value so 0 something so by multiplying it with 100 you are going to convert this based on percentage okay so the next thing to get is the class detected so I just call this class detected or let's call it class detected number since this is going to return return to us an integer number there a number and for this we have to convert this particular number to integer so we can just do the same thing class detected number is equal to integer value of class detected number and that's it so we've converted it to integer this will return as an integer value and now we have to go ahead and use this integer value to assess the particular class name so if it has detered a person is going to be zero okay so we have have to use this particular zero we are getting to assess the string person instead of just having zero which holds no information for us okay so I'll call that class detected name so this result as in the Z do names return to you a ditionary okay it will return to you aary value so the key Z is equal to person the key one will be equal to something else I think it to be bicycle or so I don't actually know I forgotten that so now let's we assess it by the number so any number detected we use that particular number to get the detected name so once we put that particular number as the key we just go ahead and get the name so class detected number okay so that's how we'll be able to access the particular name detected okay and with this out of the way we can just go ahead and now render this so for that we use CV2 rectangle to draw our rectangle on the dictated object and the final step now is to render the text the name of any detected object you are getting so for that we also do c to get a nice T So T Zone do put text right so this will just render the particular test and everything will now look great so let's let's test this out all right here we have here you can see I'm being detected there are other things being detected so as usual I got some couple of things here to use here we go you can see this is a pted plant it has detected it well I also have a brush here toothbrush let's see um will you get this no that's not a bat this is a toothbrush they got it finally I'm running this on um CPU so it's kind of lagging it's a little bit slow if you have GPU you can have a lot of speed okay what else do I have I think I have let me try it out can we detect this you got it it this is working so this Yow V 10 from our live webcam see my cell phone perfectly this is detecting the cell phone as well okay so this is how easy we can use YOLO V8 to run iner from our live webcam using your own ID this opens a lot of opportunities for you to use this in your python uh code or your projects be project right from your ID so you can see it's um doing the detection so great everything looks just good you guys can just try it out the code and everything will be on my gab so guys this is how easy you can perform object detection using your V via your webcam we've covered a lot in this particular tutorial so the code and everything will be on my gab repository you can leverage it and use it in your own projects once again thanks for watching and I will see you in another video
Info
Channel: Tech Watt
Views: 1,276
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
Id: NWbtJ_NALm0
Channel Id: undefined
Length: 21min 24sec (1284 seconds)
Published: Fri Jul 05 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.