Automatic number plate recognition (ANPR) with Yolov9 and EasyOCR

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone my name is Ari and welcome to my channel so guys in my today's video I'll show you how to perform automatic number plate recognization using YOLO v9 algorithm and easy OCR Library YOLO v9 is a latest object detection model and easy OCR is a optical character recognization Library using which we can extract text from images so first we will detect the license plates once we detect the license plat using YOLO v9 model we will crop the areas where the objects are detected in the image and then those cropped images will become the input to our easy OCR module and easy OCR will then extract the text from those images so to extract license plates we need to train our YOLO v9 algorithm first on that kind of data set so let's start our today's tutorial I'll show you all the steps how to download the data set then how to train your model then how to test your uh object detection model once your object detection model is ready then we'll see how to uh use Easy OCR to extract the text so let's start by installing all the required modules first in order to run this code so first thing is to clone this GitHub repo this is the official YOLO v9 GitHub repo so we are cloning this GitHub repo and in this there is a file with the name of this requirements.txt then we will install all all the requirements which are present in this file so that's what I'm doing cloning the repo then we are entering in that YOLO v9 folder after that we are installing the requirements that's it guys in these three lines your environment is ready to run the YOLO v9 object detection and I am showing you the python version which I'm using and this is the torch version my torch version is 2.1.0 and it is compiled with Cuda 11.8 and and this is the GPU and the data set which I'm using for today's tutorial is that data set I took from overflow universe and this is the link of the data set so this is a very small data set for my today's tutorial I'm just using a very simple data set and this data set have 307 images and there is only one class license Class you can click on the data set over here and then click on this and then you can select this download zip file and you can click on continue to download the folder this data set folder okay so guys this is the Jupiter notebook which I'm showing you and these two files are the uh pre-train weights of YOLO v9 YOLO v9 is pre-train on Coco data set and these are the two different uh pre-train weights and you can get these pre-train weights from this YOLO Vine repo only this official repo just scroll down and you will come to this uh section and from here here these are the different variants of YOLO v9 you can download whichever you want to download this is the data set folder and when you open the data set folder you will have these three folders inside train you have images and labels in the same way you will have images and labels in validation and in your test folder okay now let's open this YOLO v9 and here we have this data. yml file let's open it so guys this is the file this file is important because this is the file which tells your YOLO v9 algorithm that where your data set is so we have given the path of the training images validation images and test images you will change the paths according to your PC and number of class is one and the name of the class is license so this is a data. yl file and I have this data. yl file in my YOLO v9 okay now let's train our model to train our model we need this command python train du. py workers 8 bat size is8 image size is this I have trained this model for 200 EO and then I'm giving the path of the data. yl file which I've just shown you and weights I've given the uh basically guys what I'm doing here is I'm not training my model from scratch so this is the yo 9 pre-train model which is trained on Coco data set so I'm using that and then I'm fine-tuning it on my custom data set device Z means we are working on GPU and then these are the other things so by using this command you train your model so once this training gets completed you will see our runs folder in your YOLO v9 folder here runs folder let's open it you will get a train folder and then in inside that you will get this kind of different files and folder inside this weights file you will get a best weight and the last weight so we will use this best. PT to make detections and if you want to see the confusion Matrix then you can check that and we have only one class license Class okay so and if you want to see the map at different so this this is the map map when the threshhold value is 0.5 and the map when our threshold value is between 0.5 to 0.95 okay so and if you want to see the results you can see that over here so our model is trained and we have our weight file which we are going to use is over here now let's make predictions using this best. PT file so to make the predictions we will use the detect. p py file so guys this train duel and this detect. py file all these files are present in this YOLO v9 folder here you can see train duel and then detect okay so the all these files have their separate functions so if you want to train you will use this and if you want to detect you will use this okay now we are detecting and the confidence uh threshold value we have defined over here is 0.1 you can change it as per your requirement device zero and this is the path of the best weight file and on this video I want to perform the testing let me show you the video so this video is here so this is the video on which I will perform the testing so what is our task right now right now we are not extracting the text we just trained our YOLO v9 model so that it can detect the license plates okay so this is the input video now let's check the output to check the output run this so after executing this sale let's scroll down and here the results are stored in runs detect exp folder let's open that folder yo9 runs detect exp and this is the output see license plates are getting detected right now okay so now what we will do our next task is we will crop the image where this license plate is detected and we'll send that cropped image to the easy OCR to uh extract the text okay so for that we have written a small function I'll show you that now so first task is done now we want to use Easy OCR so for that you need to install this module pip install eocr once you install it after that I have created a separate file with the name of& prore predictor and I have created that file inside my YOLO v9 folder only here let's open this file so guys in this file so this is basically a code which is there in detect. py I copied that entire code over here and then I did a small modification in it to uh run it for this APR application okay so this is the function which is responsible for extracting the text from the image so let's understand this function so we are providing these two coordinates over here image and the coordinates these coordinates are the bounding box coordinates so we are getting the bounding box coordinates and then we are cropping the image as per that uh as per those bounding box coordinates then we are converting the image into a gray scale and then we are using a reader of OCR to read the text from that gray image and then we are fetching the results and we are storing the result in this text variable this is the variable which is empty in the beginning and then we are putting the text in extracted text in this variable okay so this is the function now we have created the function we want to apply this function when we want to apply this function once YOLO v9 detect the object so as I've told you like this is the code which entire code I took it from detect. py file only so now we'll scroll down we'll go to the section where YOLO v9 model is uh performing detection and after that step we will call this function okay so let's just scroll down here over here yeah here this is what I have done so we have another variable we are calling the eocr function over here we are providing the image and the bounding box coordinates from the above and then in the label we are storing the output of uh whatever we get in this variable and then using this annotator dob uh box label we are providing the label what is the label over here the extracted text and from where how we are extracting the text we are extracting the test from this function which we have defined above that's it gu this is the only thing which I've done in detect. py file and our YOLO v9 is able to extract the text now let's run this file and see the output now let's run this file so our results are stored in runs detect exp3 let's open this folder and see the output runs detect exp3 and this is the output here you can see we are getting the license plate uh number extracted using the easy OCR so so that's it guys this is how you can perform automatic number plate recognization using YOLO v9 and eocr so I hope this video is helpful so guys if you like my videos please like share and subscribe my channel thank you for watching
Info
Channel: Code With Aarohi
Views: 1,520
Rating: undefined out of 5
Keywords: yolov9, objectdetection, yolo, computervision, yolov8
Id: HL5s2XOmTY8
Channel Id: undefined
Length: 11min 37sec (697 seconds)
Published: Wed Mar 06 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.