Automatic number plate recognition (ANPR) with Yolov9 and EasyOCR
Summary
TLDRIn this tutorial, Ari demonstrates how to use the YOLO v9 algorithm and Easy OCR Library for automatic number plate recognition. The video guides viewers through cloning the YOLO v9 GitHub repository, installing necessary modules, and training the model on a custom dataset. It then shows how to detect license plates using the trained YOLO v9 model and crop the detected areas. The cropped images are fed into the Easy OCR module to extract text. The process includes setting up the environment, training the model, and using Easy OCR to read license plate numbers from images and videos.
Takeaways
- 🚗 The video demonstrates how to perform automatic number plate recognition using YOLO v9 and Easy OCR.
- 📈 YOLO v9 is an advanced object detection model, while Easy OCR is a library for optical character recognition.
- 🔍 The process starts by detecting license plates using the YOLO v9 model and then cropping the detected areas.
- 📚 The cropped images are then fed into the Easy OCR module to extract the text, which represents the license plate numbers.
- 💾 To train the YOLO v9 algorithm, a dataset of images with license plates is required, which the presenter sourced from 'overflow universe'.
- 🛠️ The presenter guides through the installation of necessary modules and cloning of the official YOLO v9 GitHub repository.
- 🔧 The training process involves fine-tuning the pre-trained YOLO v9 model on a custom dataset, using a specific command in the terminal.
- 📊 The video shows how to check the model's performance through metrics like the confusion matrix and mAP (mean Average Precision).
- 📹 The detection is tested on a video, and the output is stored in a specific folder, showcasing the detected license plates.
- 🔎 After detection, a function is used to crop the license plate area from the image and pass it to Easy OCR for text extraction.
- 📝 The final step involves modifying the detect.py file to integrate the Easy OCR function for extracting text from the detected license plates.
Q & A
What is the main topic of Ari's video?
-The main topic of Ari's video is demonstrating how to perform automatic number plate recognition using the YOLO v9 algorithm and Easy OCR Library.
What are the two main components used in the video to recognize number plates?
-The two main components used are the YOLO v9 object detection model and the Easy OCR Library for optical character recognition.
What does YOLO v9 stand for?
-YOLO v9 stands for You Only Look Once version 9, which is an object detection model.
What is the purpose of the Easy OCR Library mentioned in the video?
-The Easy OCR Library is used to extract text from images, specifically to read number plates after they have been detected by the YOLO v9 model.
How does the process of number plate recognition start in the video?
-The process starts by detecting license plates using the YOLO v9 model, then cropping the areas where the objects are detected, and finally using Easy OCR to extract the text.
What is required to train the YOLO v9 algorithm for number plate recognition?
-To train the YOLO v9 algorithm, a dataset of images with license plates is required, which the algorithm can learn from to detect similar plates.
Where can one find the dataset used in the video for training?
-The dataset used in the video can be found on a platform called 'overflow universe', and it is available for download as a zipped folder.
What is the purpose of the 'data.yml' file in the YOLO v9 project?
-The 'data.yml' file is crucial as it provides the YOLO v9 algorithm with the paths to the training, validation, and test images, as well as the number and names of the classes to be detected.
How does the video demonstrate the training process of the YOLO v9 model?
-The video demonstrates the training process by showing the command used to train the model, including the number of epochs, batch size, image size, and the path to the data file and pre-trained weights.
What does the 'runs' folder contain after the training of the YOLO v9 model?
-The 'runs' folder contains various files and folders including the trained weights, confusion matrix, and results of the model's performance at different threshold values.
How is the detection process of license plates performed in the video?
-The detection process is performed by running the 'detect.py' file with the best weight file obtained after training, and setting a confidence threshold for detection.
What modifications are made to the 'detect.py' file to integrate Easy OCR?
-The modifications include creating a function to crop the detected license plate areas and use Easy OCR to extract text, and then calling this function after the detection by YOLO v9.
What is the final output of the video after integrating YOLO v9 and Easy OCR?
-The final output is the successful extraction of license plate numbers from images and videos using the integrated YOLO v9 for detection and Easy OCR for text recognition.
Outlines
🚗 Introduction to Automatic Number Plate Recognition with YOLO v9
In this segment, the presenter, Ari, introduces the tutorial's focus on automatic number plate recognition (ANPR) using the YOLO v9 algorithm and the Easy OCR library. YOLO v9 is an advanced object detection model, and Easy OCR is a library for optical character recognition (OCR). The process involves detecting license plates using YOLO v9, cropping the detected areas, and then using Easy OCR to extract text from these images. The tutorial will guide through downloading the dataset, training the YOLO v9 model, and testing the object detection model. It also covers the installation of required modules by cloning the YOLO v9 GitHub repository and installing dependencies from the 'requirements.txt' file. The presenter shares the Python and Torch versions used, and provides a link to download a small dataset consisting of 307 images with a single class, 'license', from 'overflow universe'.
🔧 Setting Up and Training the YOLO v9 Model
This part of the script details the setup and training process for the YOLO v9 model. The presenter explains the importance of the 'data.yml' file, which directs the YOLO v9 algorithm to the dataset's location, including paths for training, validation, and test images. The model is trained using a specific command that includes parameters for workers, batch size, image size, and the data file path. The training process uses pre-trained weights from the COCO dataset and fine-tunes them on the custom dataset. The presenter also mentions the use of a GPU for training and shows the results folder structure after training, including best and last weight files, confusion matrix, and mAP scores at different thresholds. The video demonstrates the detection of license plates in an input video, and the presenter outlines the next steps, which involve cropping the detected areas and using Easy OCR to extract text.
📝 Implementing Easy OCR for Text Extraction
In the final paragraph, the focus shifts to implementing Easy OCR for extracting text from the cropped license plate images. The presenter instructs viewers to install the Easy OCR module and demonstrates a modified version of the 'detect.py' file to integrate OCR functionality. A function is defined to crop the image based on bounding box coordinates, convert it to grayscale, and use Easy OCR to read the text. The extracted text is then stored in a variable. The presenter modifies the detection script to call this OCR function after YOLO v9 detects an object, storing the extracted text in a label variable. The script is executed to demonstrate the successful extraction of license plate numbers using Easy OCR. The presenter concludes the tutorial by inviting viewers to like, share, and subscribe to the channel for more helpful content.
Mindmap
Keywords
💡Automatic Number Plate Recognition (ANPR)
💡YOLO v9
💡Easy OCR
💡Object Detection
💡Optical Character Recognition (OCR)
💡Deep Learning
💡Dataset
💡Training
💡Pre-trained Model
💡Bounding Box
💡Confusion Matrix
Highlights
Introduction to automatic number plate recognition using YOLO v9 and Easy OCR
YOLO v9 is the latest object detection model used for detecting license plates
Easy OCR is an optical character recognition library for extracting text from images
The process involves detecting license plates, cropping detected areas, and extracting text
Training the YOLO v9 algorithm on a dataset is necessary for extracting license plates
Instructions on downloading the dataset for training the model
Demonstration of cloning the official YOLO v9 GitHub repository
Installation of required modules for running the YOLO v9 object detection
Details on the Python and Torch versions used for the tutorial
Explanation of the data.yml file which directs YOLO v9 to the dataset
Training command for the YOLO v9 model using pre-trained weights and custom dataset
Description of the training process and the expected output files
How to use the trained model to make predictions on new data
Cropping the detected license plate areas from the images
Installation and usage of Easy OCR for text extraction from cropped images
Modification of the detect.py file to integrate Easy OCR for text extraction
Final demonstration of the automatic number plate recognition in action
Conclusion and call to action for viewers to like, share, and subscribe
Transcripts
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
浏览更多相关视频
YOLOv7 | Instance Segmentation on Custom Dataset
Reading text from images with either Tesseract or Darknet/YOLO
Python ANPR with OpenCV and EasyOCR in 25 Minutes | Automatic Number Plate Recognition Tutorial
YOLOv8: How to Train for Object Detection on a Custom Dataset
Image classification + feature extraction with Python and Scikit learn | Computer vision tutorial
Running YoloV5 with TensorRT Engine on Jetson Nano | Rocket Systems
5.0 / 5 (0 votes)