Ho Chi Minh City University of Technology and Education High Quality Training Faculty
Ho Chi Minh City University of Technology and Education High Quality Training Faculty
Table of contents:
Contents
Table of contents:........................................................................................................................................1
Teacher comment.......................................................................................................................................3
Categories and abbreviated terms..............................................................................................................4
The introduce:.............................................................................................................................................5
1. Heading...............................................................................................................................................6
1.1. An overview of the topic..............................................................................................................6
1.2. Target..........................................................................................................................................6
1.3. Subject scope...............................................................................................................................6
2. Theoretical basis..................................................................................................................................8
2.1. Theory..........................................................................................................................................8
2.2. Tools and libraries:.......................................................................................................................8
3. Topic execution...................................................................................................................................9
3.1. Methods of implementation........................................................................................................9
3.2. Block diagram:...........................................................................................................................10
3.3. Implementation process............................................................................................................10
3.3.1. Detection License Plate with Wpod-Net............................................................................10
3.3.2. Plate character segmentation............................................................................................16
3.3.2.1. Image processing.......................................................................................................16
3.3.2.2. Determine contour of License characters..................................................................18
3.3.2.3. Visualize our segmented characters..........................................................................20
3.3.3. Recognize plate license characters with OpenCV and Deep Learning................................21
3.3.3.1. Dataset.......................................................................................................................21
3.3.3.2. Data Pre-processing...................................................................................................23
3.3.3.3. Initialize MobileNets architecture with pre-trained weights......................................25
3.3.3.4. Train and evaluate model..........................................................................................26
3.3.4. Combining everything........................................................................................................29
4. Design the theme..............................................................................................................................31
5. Conclusion and development direction.............................................................................................34
5.1. Conclude:...................................................................................................................................34
5.1.1. Result:................................................................................................................................34
Page 1
Digital Image Processing
5.1.2. Limitations:........................................................................................................................34
5.2. Development:............................................................................................................................34
References.................................................................................................................................................36
Page 2
Digital Image Processing
Teacher comment
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
............................................................................................
Page 3
Digital Image Processing
ML Machine Learning
Page 4
Digital Image Processing
The introduce:
Image processing is an area of interest and has become a specialized subject
of engineering staff, the bachelor's degree in information technology, as well as
other engineering disciplines in engineering universities. information, statistical
theory, artificial intelligence, identification, edge separation etc. Image processing
research all things related to image manipulation such as: Image rendering, image
acquisition, enhancement and restore the image to achieve the desired image. Each
problem requires some algorithmic processing in each pixel or image element.
Learning helps us to understand more deeply about the mechanism, principles of
image processing, color adjustment, brightness, contrast, .. make the image more
beautiful and artistic. Therefore, image processing is a field of great interest and
has become the passion of many students.
In this report, I would like to give the topic: Detect and Recognize Vehicle’s
License Plate
Due to limited knowledge, this essay material may still lack many
shortcomings, looking forward to the contribution of teachers and readers to make
the document more complete.
We sincerely thank!
Page 5
Digital Image Processing
1. Heading
1.1.An overview of the topic
- In this day and age, everything a human can do, almost any machine can do.
It is because programmers have turned computers and its peripherals into
intelligent systems that can do anything.
- As simple as parking a car, just a few years ago when we went to any
parking lot we saw that all cars had to be treated with paper by the staff,
which was inconvenient and much the risk of paper is very easy to be
damaged, torn or sticky ... not only that, the recording of paper cannot avoid
errors when the employee looks at the car for a moment, distracting and
incorrectly recording, so it is very time consuming.
- But now that is not a problem when we have technology to recognize license
plates with magnetic cards. This work consists of 3 main phases: Take the
image containing the license plate, process the image to get the code number
on the license plate, finally save them on the card.
- In which the most important stage is to collect the license plate number from
the image. In this topic we will present the method how to recognize that
code.
1.2.Target
- In the process of topic, the group sets out 2 main goals.
- Have basic knowledge of Python programming. Because this is an extremely
popular and important language, especially in the field of AI and Machine
Learning.
- Learn about the OpenCV library through which its application can identify
the license plate relatively accurately.
- Building an automatic license plate recognition system.
1.3.Subject scope
- Our report is created to give you step-by-step instructions on how to deploy
a typical ALPR system using pre-trained model Wpod-Net, Computer
Page 6
Digital Image Processing
Page 7
Digital Image Processing
2. Theoretical basis
2.1.Theory
- Using pre-trained mode Wpod-Net, Neural Network mode, MobileNets
architecture
2.2.Tools and libraries:
- Python 3.7
- Keras 2.3.1
- Tensorflow 1.14.0
- Jupyter Notebook
- Numpy 1.17.4
- Matplotlib 3.2.1
- OpenCV 4.1.0
Page 8
Digital Image Processing
3. Topic execution
3.1.Methods of implementation
Introducing the python programming language
- Python is a multi-purpose programming language created in the late 1980s
as an open source language with a feature of syntax that is easy to read and
understand. today, Python is one of the most popular programming
languages in the world besides C #, Java…. Especially in the field of AI and
Machine Learning, python shows its superiority.
Introduction to OpenCV.
- OpenCV is a leading open source library for computer vision, image
processing and machine learning, and GPU acceleration features in real-time
operations.
Introduce WPOD-Net
- Pre-trained model named Wpod-Net to detect and extract License Plates of
vehicle
Introduce CNN
- Convolutional Neural Network (CNNs) is one of the advanced Deep
Learning models. It helps us to build intelligent systems with high accuracy
today.
Page 9
Digital Image Processing
3.2.Block diagram:
Plate character
segmentation with
OpenCV
Train a Neural
Network to predict Characters
segmented
characters
3.3.Implementation process
3.3.1. Detection License Plate with Wpod-Net
- Open a new notebook and import all required libraries and packages as
shown below
import
cv2
import numpy as np
import matplotlib.pyplot as plt
from local_utils import detect_lp
from os.path import splitext, basename
from keras.models import
model_from_json
import glob
%matplotlib.inline
Page 10
Digital Image Processing
path = splitext(path)[0]
with open('%s.json' % path, 'r')
as json_file:
model_json = json_file.read()
model =
model_from_json(model_json,
custom_objects={})
model.load_weights('%s.h5' % path)
print("Loading model
successfully...")
return model
except Exception as e:
print(e)
wpod_net_path = "wpod-net.json"
wpod_net = load_model(wpod_net_path)
- Def preprocess_image(image_path,resize=False):
img = cv2.imread(image_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = img / 255
if resize:
img = cv2.resize(img, (224,224))
return img
Page 11
Digital Image Processing
Page 12
Digital Image Processing
plt.subplot(1,2,2)
plt.axis(False)
plt.imshow(LpImg[0])
Page 13
Digital Image Processing
Page 14
Digital Image Processing
Page 15
Digital Image Processing
for c in sort_contours(cont):
(x, y, w, h) = cv2.boundingRect(c)
ratio = h/w
if 1<=ratio<=3.5: # Only select contour with defined ratio
if h/plate_image.shape[0]>=0.5: # Select contour which
has the height larger than 50% of the plate
# Draw bounding box arroung digit number
cv2.rectangle(test_roi, (x, y), (x + w, y + h), (0,
255,0), 2)
Page 16
Digital Image Processing
print("Detect {} letters...".format(len(crop_characters)))
fig = plt.figure(figsize=(14,4))
grid =
gridspec.GridSpec(ncols=len(crop_characters),nrows=1,figure=fig
)
for i in range(len(crop_characters)):
fig.add_subplot(grid[i])
Page 17
Digital Image Processing
plt.axis(False)
plt.imshow(crop_characters[i],cmap="gray")
The result:
dataset_paths = glob.glob("dataset_characters/**/*.jpg")
cols=4
rows=3
fig = plt.figure(figsize=(10,8))
plt.rcParams.update({"font.size":14})
grid = gridspec.GridSpec(ncols=cols,nrows=rows,figure=fig)
Page 18
Digital Image Processing
rand =
np.random.randint(0,len(dataset_paths),size=(cols*rows))
Page 19
Digital Image Processing
image=load_img(image_path,target_size=(80,80))
image=img_to_array(image)
X.append(image)
labels.append(label)
X = np.array(X,dtype="float16")
labels = np.array(labels)
Page 20
Digital Image Processing
- Split our dataset into training set (90%) and validation set
(10%). This allows us monitoring our model accuracy and
avoiding overfitting.
(trainX, testX, trainY, testY) =
train_test_split(X, y, test_size=0.10, stratify=y,
random_state=42)
image_gen =
ImageDataGenerator(rota
tion_range=10,
width_shift_range=0.1,
height_shift_range=0.1,
shear_range=0.1,
zoom_range=0.1,
fill_mode="nearest"
Page 21
Digital Image Processing
def create_model(lr=1e-4,decay=1e-4/25,
training=False,output_shape=y.shape[1]):
baseModel = MobileNetV2(weights="imagenet",
include_top=False,
input_tensor=Input(shape=(80, 80,
3)))
headModel = baseModel.output
headModel = AveragePooling2D(pool_size=(3, 3))(headModel)
headModel = Flatten(name="flatten")(headModel)
headModel = Dense(128, activation="relu")(headModel)
headModel = Dropout(0.5)(headModel)
headModel = Dense(output_shape, activation="softmax")
(headModel)
if training:
# define trainable lalyer
for layer in baseModel.layers:
layer.trainable = True
Page 22
Digital Image Processing
# compile model
optimizer = Adam(lr=lr, decay = decay)
model.compile(loss="categorical_crossentropy",
optimizer=optimizer,metrics=["accuracy"])
return model
model = create_model(lr=INIT_LR,
decay=INIT_LR/EPOCHS,training=True)
EarlyStopping(monitor='val_loss', patience=5,
Page 23
Digital Image Processing
verbose=0),
ModelCheckpoint(filepath="License_character_recognitio
n.h5", verbose=1, save_weights_only=True)
]
Page 24
Digital Image Processing
Page 25
Digital Image Processing
labels = LabelEncoder()
labels.classes_ = np.load('license_character_classes.npy')
print("[INFO] Labels loaded successfully...")
- Remember that we configure the input layer of our model to receive input
images with the shape of (80,80,3). Thus we would need to convert our
image to the appropriate size and correct channel .We implement the loaded
label classes to inverse one-hot encoding label obtained from model to
digital characters. A loop is generated over each character image
in crop_characters, which stores all predictions from model in to
final_result, and plot each image with its corresponding predictions as
shown as Fig. 4.
fig = plt.figure(figsize=(15,3))
cols = len(crop_characters)
grid = gridspec.GridSpec(ncols=cols,nrows=1,figure=fig)
final_string = ''
for i,character in enumerate(crop_characters):
fig.add_subplot(grid[i])
title =
np.array2string(predict_from_model(character,model,labels)
Page 26
Digital Image Processing
)
plt.title('{}'.format(title.strip("'[]"),fontsize=20))
final_string+=title.strip("'[]")
plt.axis(False)
plt.imshow(character,cmap='gray')
Page 27
Digital Image Processing
- Browse the right image file (click the browse image button)
- If you don’t choose the image, the program will raise a warning message
box
Page 28
Digital Image Processing
- Get the plate image and give prediction on it (Click on the get result button)
- If the image quality is good and detect contour correctly it will give out the
result like this
Page 29
Digital Image Processing
- From the topic we can apply it directly to the identification of number plates
in parking lots.
- If it can be developed, it can be applied in the field of artificial intelligence
such as robot reading. Or develop into a character detector to assist the deaf,
blind ....
Page 31
Digital Image Processing
References
[1] Big exercise in image processing: identifying license plates - Ho Chi Minh City
University of Technology
https://www.123doc.net/document/5196410-bai-tap-lon-xu-ly-anh-nhan-dien-bien-
so-xe-dai-hoc-bach-khoa-tphcm.htm
[2] https://medium.com/@quangnhatnguyenle/detect-and-recognize-vehicles-
license-plate-with-machine-learning-and-python-part-1-detection-795fda47e922
[3] https://medium.com/@quangnhatnguyenle/detect-and-recognize-vehicles-
license-plate-with-machine-learning-and-python-part-2-plate-de644de9849f
[4] https://medium.com/@quangnhatnguyenle/detect-and-recognize-vehicles-
license-plate-with-machine-learning-and-python-part-3-recognize-be2eca1a9f12
Page 32