Automatic number plate recognition (ANPR) with Yolov9 and EasyOCR

Code With Aarohi
5 Mar 202411:37

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

00:00

πŸš— 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'.

05:03

πŸ”§ 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.

10:06

πŸ“ 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)

Automatic Number Plate Recognition, or ANPR, is a technology that uses optical character recognition to read vehicle registration plates. In the context of the video, ANPR is the main theme, where the presenter demonstrates how to use YOLO v9 and Easy OCR to detect and recognize license plates from images and videos. The script mentions that after detecting the license plates using YOLO v9, the cropped images are sent to Easy OCR to extract the text, which is the license plate number.

πŸ’‘YOLO v9

YOLO v9 refers to the ninth iteration of the You Only Look Once (YOLO) algorithm, a popular real-time object detection system in computer vision. The video script describes using YOLO v9 for detecting license plates, indicating that it is the core model for identifying regions of interest within images. The presenter mentions training YOLO v9 on a custom dataset to recognize the 'license' class, which is a specific category of objects the model learns to detect.

πŸ’‘Easy OCR

Easy OCR is an optical character recognition library that can extract text from images. In the video, after the license plates are detected by YOLO v9, Easy OCR is used to read and extract the alphanumeric characters from the cropped images of the license plates. The script outlines the process of installing Easy OCR and using it to convert the detected plate images into text.

πŸ’‘Object Detection

Object detection is a computer vision technique that locates and identifies multiple objects in an image or video frame. The video script focuses on using YOLO v9 for object detection, specifically to find license plates. The presenter explains the process of training the YOLO v9 model to recognize license plates within a given dataset.

πŸ’‘Optical Character Recognition (OCR)

Optical Character Recognition, or OCR, is the process of converting various types of documents, such as scanned paper documents, PDF files, or images captured by a digital camera, into editable and searchable data. In the video, OCR is used to extract text from the images of license plates after they have been detected by YOLO v9. The script describes how Easy OCR is applied to the cropped images to perform this task.

πŸ’‘Deep Learning

Deep learning is a subset of machine learning with neural networks having multiple layers, or a deep architecture, used for learning and modeling data representations. The video script implies the use of deep learning through the YOLO v9 model, which is trained on a dataset to perform object detection. The deep learning model is fine-tuned to recognize specific objects, such as license plates.

πŸ’‘Dataset

A dataset is a collection of data, typically used for analysis or to train machine learning models. In the video, the presenter refers to a dataset containing images of license plates, which is used to train the YOLO v9 model. The script mentions downloading a specific dataset from 'overflow universe' and using it to teach the model to detect the 'license' class.

πŸ’‘Training

In machine learning, training refers to the process of teaching a model to make predictions or decisions based on data. The video script describes the process of training the YOLO v9 model on a custom dataset to detect license plates. The presenter uses a command to initiate training, specifying parameters such as batch size, image size, and the dataset file.

πŸ’‘Pre-trained Model

A pre-trained model is a machine learning model that has already been trained on a large dataset and can be fine-tuned for specific tasks. The script mentions using pre-trained weights of YOLO v9, which were trained on the COCO dataset, and then fine-tuning it on a custom dataset for the task of license plate detection.

πŸ’‘Bounding Box

A bounding box is a rectangle that outlines an object in an image, used to define the spatial coordinates of the object. In the video, after a license plate is detected by YOLO v9, the script describes how the bounding box coordinates are used to crop the area around the license plate, which is then sent to Easy OCR for text extraction.

πŸ’‘Confusion Matrix

A confusion matrix is a table used to describe the performance of a classification model on a set of data for which the true values are known. The script mentions checking the confusion matrix to evaluate the performance of the YOLO v9 model after training. It helps in understanding the accuracy of the model in detecting the 'license' class.

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

play00:00

hello everyone my name is Ari and

play00:02

welcome to my channel so guys in my

play00:03

today's video I'll show you how to

play00:05

perform automatic number plate

play00:07

recognization using YOLO v9 algorithm

play00:11

and easy OCR Library YOLO v9 is a latest

play00:15

object detection model and easy OCR is a

play00:18

optical character recognization Library

play00:21

using which we can extract text from

play00:23

images so first we will detect the

play00:27

license plates once we detect the

play00:29

license plat using YOLO v9 model we will

play00:33

crop the areas where the objects are

play00:35

detected in the image and then those

play00:38

cropped images will become the input to

play00:40

our easy OCR module and easy OCR will

play00:44

then extract the text from those images

play00:48

so to extract license plates we need to

play00:51

train our YOLO v9 algorithm first on

play00:54

that kind of data set so let's start our

play00:56

today's tutorial I'll show you all the

play00:59

steps how to download the data set then

play01:01

how to train your model then how to test

play01:03

your uh object detection model once your

play01:06

object detection model is ready then

play01:07

we'll see how to uh use Easy OCR to

play01:10

extract the text so let's start by

play01:13

installing all the required modules

play01:15

first in order to run this code so first

play01:17

thing is to clone this GitHub repo this

play01:20

is the official YOLO v9 GitHub repo so

play01:22

we are cloning this GitHub repo and in

play01:25

this there is a file with the name of

play01:26

this requirements.txt then we will

play01:29

install all all the requirements which

play01:30

are present in this file so that's what

play01:33

I'm doing cloning the repo then we are

play01:36

entering in that YOLO v9 folder after

play01:39

that we are installing the requirements

play01:41

that's it guys in these three lines your

play01:43

environment is ready to run the YOLO v9

play01:47

object detection and I am showing you

play01:50

the python version which I'm using and

play01:52

this is the torch version my torch

play01:54

version is 2.1.0 and it is compiled with

play01:58

Cuda 11.8 and and this is the GPU and

play02:01

the data set which I'm using for today's

play02:03

tutorial is that data set I took from

play02:06

overflow universe and this is the link

play02:08

of the data set so this is a very small

play02:11

data set for my today's tutorial I'm

play02:13

just using a very simple data set and

play02:15

this data set have 307 images and there

play02:19

is only one class license Class you can

play02:22

click on the data set over here and then

play02:24

click on this and then you can select

play02:27

this download zip file and you can click

play02:29

on continue to download the folder this

play02:32

data set folder okay so guys this is the

play02:34

Jupiter notebook which I'm showing you

play02:36

and these two files are the uh pre-train

play02:39

weights of YOLO v9 YOLO v9 is pre-train

play02:42

on Coco data set and these are the two

play02:44

different uh pre-train weights and you

play02:48

can get these pre-train weights from

play02:50

this YOLO Vine repo only this official

play02:53

repo just scroll down and you will come

play02:57

to this uh section and from here here

play03:00

these are the different variants of YOLO

play03:02

v9 you can download whichever you want

play03:04

to download this is the data set folder

play03:07

and when you open the data set folder

play03:08

you will have these three folders inside

play03:10

train you have images and labels in the

play03:13

same way you will have images and labels

play03:15

in validation and in your test

play03:19

folder okay now let's open this YOLO v9

play03:24

and here we have this data. yml file

play03:28

let's open it

play03:30

so guys this is the file this file is

play03:33

important because this is the file which

play03:35

tells your YOLO v9 algorithm that where

play03:37

your data set is so we have given the

play03:41

path of the training images validation

play03:44

images and test images you will change

play03:46

the paths according to your PC and

play03:49

number of class is one and the name of

play03:51

the class is license so this is a data.

play03:54

yl file and I have this data. yl file in

play03:59

my YOLO v9 okay now let's train our

play04:02

model to train our model we need this

play04:05

command python train du. py workers 8

play04:09

bat size is8 image size is this I have

play04:13

trained this model for 200 EO and then

play04:16

I'm giving the path of the data. yl file

play04:18

which I've just shown you and weights

play04:22

I've given the uh basically guys what

play04:25

I'm doing here is I'm not training my

play04:26

model from scratch so this is the yo 9

play04:29

pre-train model which is trained on Coco

play04:31

data set so I'm using that and then I'm

play04:35

fine-tuning it on my custom data set

play04:36

device Z means we are working on GPU and

play04:40

then these are the other things so by

play04:44

using this command you train your model

play04:46

so once this training gets completed you

play04:49

will see our runs folder in your YOLO v9

play04:53

folder here runs folder let's open it

play04:57

you will get a train folder and then in

play04:59

inside that you will get this kind of

play05:02

different files and folder inside this

play05:04

weights file you will get a best weight

play05:06

and the last weight so we will use this

play05:09

best. PT to make

play05:12

detections and if you want to see the

play05:14

confusion Matrix then you can check that

play05:18

and we have only one class license Class

play05:20

okay so and if you want to see the map

play05:25

at

play05:28

different so this this is the map map

play05:30

when the threshhold value is 0.5 and the

play05:32

map when our threshold value is between

play05:35

0.5 to 0.95 okay so and if you want to

play05:39

see the results you can see that over

play05:41

here so our model is trained and we have

play05:45

our weight file which we are going to

play05:47

use is over here now let's make

play05:50

predictions using this best. PT

play05:53

file so to make the predictions we will

play05:57

use the detect. p py file so guys this

play06:00

train duel and this detect. py file all

play06:04

these files are present in this YOLO v9

play06:07

folder here you can see train duel and

play06:09

then detect okay so the all these files

play06:13

have their separate functions so if you

play06:15

want to train you will use this and if

play06:17

you want to detect you will use this

play06:19

okay now we are detecting and the

play06:23

confidence uh threshold value we have

play06:25

defined over here is 0.1 you can change

play06:28

it as per your requirement device zero

play06:30

and this is the path of the best weight

play06:33

file and on this video I want to perform

play06:36

the testing let me show you the

play06:38

video so this video is

play06:42

here so this is the video on which I

play06:45

will perform the

play06:47

testing so what is our task right now

play06:50

right now we are not extracting the text

play06:53

we just trained our YOLO v9 model so

play06:55

that it can detect the license plates

play06:57

okay so this is the input video now

play07:00

let's check the

play07:02

output to check the output run

play07:07

this so after executing this

play07:11

sale let's scroll down

play07:16

and here the results are stored in runs

play07:21

detect exp folder let's open that

play07:25

folder

play07:27

yo9 runs

play07:30

detect exp and this is the output see

play07:34

license plates are getting detected

play07:36

right now

play07:38

okay so now what we will do our next

play07:41

task is we will crop the image where

play07:45

this license plate is detected and we'll

play07:48

send that cropped image to the easy OCR

play07:51

to uh extract the text okay so for that

play07:55

we have written a small function I'll

play07:57

show you that now so first task is done

play08:01

now we want to use Easy OCR so for that

play08:04

you need to install this module pip

play08:07

install eocr once you install it after

play08:10

that I have created a separate file with

play08:13

the name of& prore predictor and I have

play08:17

created that file inside my YOLO v9

play08:21

folder only here let's open this file so

play08:25

guys in this file so this is basically a

play08:27

code which is there in detect. py I

play08:30

copied that entire code over here and

play08:32

then I did a small modification in it to

play08:36

uh run it for this APR application okay

play08:39

so this is the function which is

play08:41

responsible for extracting the text from

play08:44

the image so let's understand this

play08:46

function so we are providing these two

play08:49

coordinates over here image and the

play08:51

coordinates these coordinates are the

play08:53

bounding box coordinates so we are

play08:56

getting the bounding box coordinates and

play08:58

then we are cropping the image as per

play09:00

that uh as per those bounding box

play09:02

coordinates then we are converting the

play09:04

image into a gray scale and then we are

play09:06

using a reader of OCR to read the text

play09:11

from that gray image and then we are

play09:14

fetching the results and we are storing

play09:16

the result in this text variable this is

play09:18

the variable which is empty in the

play09:20

beginning and then we are putting the

play09:22

text in extracted text in this variable

play09:25

okay so this is the function now we have

play09:29

created the function we want to apply

play09:32

this function when we want to apply this

play09:34

function once YOLO v9 detect the object

play09:37

so as I've told you like this is the

play09:39

code which entire code I took it from

play09:41

detect. py file only so now we'll scroll

play09:44

down we'll go to the section where YOLO

play09:47

v9 model is uh performing detection and

play09:50

after that step we will call this

play09:52

function okay so let's just scroll

play09:56

down

play09:58

here

play10:00

over

play10:01

here yeah here this is what I have done

play10:06

so we have another variable we are

play10:08

calling the eocr function over here we

play10:11

are providing the image and the bounding

play10:14

box coordinates from the above and then

play10:17

in the label we are storing the output

play10:20

of uh whatever we get in this variable

play10:23

and then using this annotator dob uh box

play10:26

label we are providing the label what is

play10:31

the label over here the extracted text

play10:34

and from where how we are extracting the

play10:36

text we are extracting the test from

play10:38

this function which we have defined

play10:40

above that's it gu this is the only

play10:43

thing which I've done in detect. py file

play10:45

and our YOLO v9 is able to extract the

play10:49

text now let's run this file and see the

play10:54

output now let's run this

play10:58

file so our results are stored in runs

play11:01

detect exp3 let's open this folder and

play11:04

see the

play11:06

output runs detect exp3 and this is the

play11:11

output here you can see we are getting

play11:15

the license plate uh number extracted

play11:19

using the easy OCR

play11:21

so so that's it guys this is how you can

play11:24

perform automatic number plate

play11:26

recognization using YOLO v9 and eocr so

play11:30

I hope this video is helpful so guys if

play11:32

you like my videos please like share and

play11:34

subscribe my channel thank you for

play11:36

watching

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
YOLO v9Easy OCRObject DetectionLicense PlateAI TutorialMachine LearningImage ProcessingPython CodingOptical Character RecognitionDeep Learning