ANPR Final Project Report
ANPR Final Project Report
ANPR Final Project Report
1. Introduction
1.1. Identification of Need
1.2. Preliminary Investigation
1.3. Feasiability Study
2. Literature Survey.
21. Previous Work
22 Existing System
2.3. Proposed System.
24. History
3. Proposed Methodology.
4. Project Analysis,
4.1. Testing
4.2. Inference.
4.3. Application
4.4. Advantages
4.5. Disadvantages
5. Conclusion.
6. Future Scope
References
Chapter 1: Introduction
It is seen that the security forces and authorities face problems whenever security forces
chase a vehicle or they cannot catch a vehicle which broke traffic rules. Authorities find it
very hectic on a busy day to log the vehicle numbers manually in a parking lot. So, in order to
make the entire process autonomous, we can install this system to automatically detect the
vehicle which breaks the traffic rules, take a picture of it and store the number in the database
so as to fine the respective owner afterwards. The system can be used in parking to take the
picture of the vehicle and log the vehicle number in the database (or the cloud, if connected to
the internet). This technology reduces the unnecessary hectic manual work required on any
busy day, saves the labour cost and is far more efficient than humans. The number of any
vehicle once obtained as text, can be displayed, saved in the database, or can be searched
through the entire database for the details. This project is so versatile that can be used as an
entire application once converted to a software or can be used as a part of any big project.
Inconsistency in number plate designs is the restraint for the ANPR market. Number plates
differ in terms of their size or fonts in every part of the globe; due to which, it becomes
difficult to construct an algorithm that would read all fonts without any discrepancy.
The automatic number plate recognition market is expected to exhibit high growth in near
future across the globe, some of the major driving factors contributing to the growth are
rising acceptance of smart parking concept in developed as well as developing countries and
infrastructure growth in emerging countries. However, development of a shared platform for
exchange of data from distinct sources and technological advancements are some of future
trends of automatic number plate recognition market during the forecast period.
The emergence of the Automatic Number Plate Recognition concept was mainly focused
upon monitoring the vehicles. Various countries of the world face crimes of several types and
vehicular based crimes were on the rise due to ease of escape through vehicles. Curbing of
such crimes had become necessary and hence the use of ANPR systems integrated into the
security systems have proved to be of great use.
Detailed investigation has really helped in knowing the feasibility of various Software and
hardware components as well as the overall project model in terms of technical, operational,
and economical respects. Thus, this project is feasible in all respect.
The OCR engine used here is Tesseract OCR. Tesseract is an optical character recognition
engine for various operating systems. It is free software, released under the Apache License
Originally developed by Hewlett-Packard as proprietary software in the 1980s, it was
released as open source in 2005 and development has been sponsored by Google since 2006.
In 2006, Tesseract was considered one of the most accurate open-source OCR engines then
available. The Tesseract engine was originally developed as proprietary software at Hewlett
Packard labs in Bristol, England and Greeley, Colorado between 1985 and 1994, with some
more changes made in 1996 to port to Windows, and some migration from C to C++ in 1998.
A lot of the code was written in C, and then some more was written in C++. Since then, all
the code has been converted to at least compile with a C++ compiler. Very little work was
done in the following decade. It was then released as open source in 2005 by Hewlett Packard
and the University of Nevada, Las Vegas (UNLV). Tesseract development has been
sponsored by Google since 2006. Tesseract was in the top three OCR engines in terms of
character accuracy in 1995. It is available for Linux, Windows, and Mac OS X. However, due
to limited resources it is only rigorously tested by developers under Windows and Ubuntu.
2) High cost.
2. Number is displayed and with some modification can be stored in a database or be searched
or processed.
In one of the papers by Anisha Goyal and Rekha Bhatia, from department of CSE, Punjabi
University Regional Centre for Information Technology and Management, Mohali, Punjab,
India, they proposed that till now, all the LPR systems have been created using neural
networks. They proposed to execute the system using Gabor filter, OCR, and Vision
Assistant to make the system quicker and more proficient. Different recognition strategies
have been produced and number plate recognition systems are today used in different
movement and security applications, for example, parking, access and border control, or
tracking of stolen autos.
In another paper by Amr Badr, Mohamed M. Abdelwahab, Ahmed M. Thabet, and Ahmed
M. Abdelsadek, proposed that Automatic recognition of car license plate number became a
very important in our daily life because of the unlimited increase of cars and transportation
systems which make it impossible to be fully managed and monitored by humans, examples
are so many like traffic monitoring, tracking stolen cars, managing parking toll, red-light
violation enforcement, border and customs checkpoints. This paper mainly introduces an
Automatic Number Plate Recognition System (ANPR) using Morphological operations,
Histogram manipulation and Edge detection Techniques for plate localization and characters
segmentation. Artificial Neural Networks are used for character classification and
recognition.
In the third paper by Hamed Shanghai, an automatic and mechanized license and number
plate recognition system is proposed that can extract license plate number of the vehicle
passing through a given location using image processing algorithms. The resulting data is
applied to compare with the records on a database. Experimental results reveal that the
presented system successfully detects and recognizes the vehicle number plate on real
images. This system can also be used for security and traffic control.
2.4 History
Digital Image Processing means processing digital image by means of a digital computer. We
can also say that it is a use of computer algorithms, in order to get enhanced image either to
extract some useful information. One of the first applications of digital image was in the
newspaper industry, when pictures were first sent by submarine cable between London and
New York. Introduction of the Bart Lane cable picture transmission system in the early 1920s
reduced the time required to transport a picture across the Atlantic from more than a week to
less than three hours. Specialized printing equipment coded pictures for cable transmission
and then reconstructed them at the receiving end. Some of the initial problems in improving
the visual quality of these early digital pictures were related to the selection of printing
producers and the distribution of intensity levels. In fact, digital images require so much
storage and computation power that progress in the field of digital image processing has been
dependent on the development of digital computers and of supporting technologies that
include data storage, display and transmission. The digital image is composed of a finite
number of elements, each of which has a location and values. These elements are referred to
as picture elements, image elements, pixels or pels. Pixels used to denote the element of a
digital image.
The process of acquiring an image of the area containing the text, pre-processing that image,
extracting the individual characters, describing the character in the form suitable for computer
processing & recognizing those individual characters are Digital Image Processing. Digital
image processing techniques began in the late 1960s and early 1970s to be used in medical
imaging, remote Earth resource observations and astronomy. The invention in the early 1970s
of computerized axial tomography (CAT) also called computerized tomography (CT) is one
of the most important events of image processing in medical diagnosis. Computerized axial
tomography is a process in which a ring of detectors encircles a patient and an X-Ray source,
concentric with a detector ring, rotates about the patient. The X-ray passes through the object
and is collected at the opposite end by the corresponding detectors in the ring. As the source
rotates, this procedure is repeated. Image processing methods have successfully restored
blurred pictures that were the only available records of rare artefacts lost or damaged after
being photographed. Image processing methods have successfully restored blurred pictures
that were the only available records of rare artefacts lost or damaged after being
photographed.
Early optical character recognition may be traced to technologies involving telegraphy and
creating reading devices for the blind. In 1914, Emanuel Goldberg developed a machine that
read characters and converted them into standard telegraph code. Concurrently, Edmund
Fournier d'Albe developed the Octophone, a handheld scanner that when moved across a
printed page, produced tones that corresponded to specific letters or characters. In the late
1920s and into the 1930s Emanuel Goldberg developed what he called a "Statistical
Machine" for searching microfilm archives using an optical code recognition system.
In 1931 he was granted USA Patent number 1,838,389 for the invention. The patent was
acquired by IBM. With the advent of smart-phones and smart glasses, OCR can be used in
internet connected mobile device applications that extract text captured using the device's
camera. These devices that do not have OCR functionality built into the operating system will
typically use an OCR API to extract the text from the image file captured and provided by the
device. The OCR API returns the extracted text, along with information about the location of
the detected text in the original image back to the device app for further processing (such as
text-to-speech) or display. In 1951, a young Department of Defence engineer named David
Shepard developed a scanning device in his home that he nicknamed ‘Gismo.’ This device
could read twenty-three letters of the alphabet, interpret Morse Code, and read aloud letter by
letter. While crude by today’s standards, it nevertheless captured the imagination of scientists
and businessmen alike with its potential as a practical business tool in the data entry field.
‘Gismo’ garnered quite a bit of publicity and consequently spurred on the further
development of OCR tools.
3: Proposed Methodology
3.1 Problem Formulation
It is seen that the security forces and authorities face problems whenever security forces
chase a vehicle or they cannot catch a vehicle which broke traffic rules. Authorities find it
very hectic on a busy day to log the vehicle numbers manually in a parking lot. So, in order to
make the entire process autonomous, we can install this system to automatically detect the
vehicle which breaks the traffic rules, take a picture of it and store the number in the database
so as to fine the respective owner afterwards. The system can be used in parking to take the
picture of the vehicle and log the vehicle number in the database (or the cloud, if connected to
the internet). This technology reduces the unnecessary hectic manual work required on any
busy day, saves the labour cost and is far more efficient than humans. The number of any
vehicle once obtained as text, can be displayed, saved in the database, or can be searched
through the entire database for the details. This project is so versatile that it can be used as an
entire application once converted to a software or can be used as a part of any big project.
In the input unit, a preconfigured camera is arranged such that it is interfaced with a display
device like a TFT monitor and a switch or a key is attached. Whenever the subject (the car) is
in the frame of the picture, the key is pressed in order to capture the picture.
3.2.2 Block Diagram of the output unit
In the Output Unit, the input image is taken from the input unit and then processed in the
processing unit. In the processing unit all sorts of enhancement and extraction is done and
then the number on the license plate is extracted using Optical Character Recognition and
then it can either be stored in a database or be displayed on a display device or both or can be
used to excite an actuator.
Basics of Digital Image Processing: The image of a vehicle whose number plate
is to be recognised is taken from a digital camera which is then loaded to a local
computer for further processing. OpenCV (Open-Source Computer Vision) is a
library of programming functions mainly aimed at real-time computer vision. In
simple language it is a library used for Image Processing. It is mainly used to do all
the operations related to Images. Python, being a versatile language, is used here as a
programming language. Python and its modules like NumPy, SciPy, Matplotlib and
other special modules provide the optimal functionality to be able to cope with the
flood of pictures. To enhance the number plate recognition further, we use a median
filter to eliminate noises but it not only eliminates noise. It concentrates on high
frequency also. So, it is more important in edge detection in an image, generally the
number plates are in rectangular shape, so we need to detect the edges of the
rectangular plate. Image Processing mainly involves the following steps:
1. Image acquisition: This is the first step or process of the fundamental steps of
digital image processing. Image Acquisition is the capturing of an image by
any physical device (in this case the primary camera of the computer) to take
the input as a digital image in the computer.
2. Image Enhancement: Image enhancement is among the simplest and most
appealing areas of digital image processing. Basically, the idea behind
enhancement techniques is to bring out detail that is obscured, or simply to
highlight certain features of interest in an image. Such as, changing brightness
& contrast etc. In this step the quality or rather the clarity of the input image is
enhanced and the image is made clear enough to be processed.
3. Morphological Processing: Morphological operations apply a structuring
element to an input image, creating an output image of the same size. The
image is converted to a binary image, making it more to apply structural
extraction to the image and extract any structure related to a particular
mathematical model from it, in this case a license plate.
4. Segmentation: Segmentation procedures partition an image into its constituent
parts or objects. In general, autonomous segmentation is one of the most
difficult tasks in digital image processing. A rugged segmentation procedure
brings the process a long way toward a successful solution of imaging
problems that require objects to be identified individually.
5. Representation: Representation and description almost always follow the
output of a segmentation stage, which usually is raw pixel data, constituting
either the boundary of a region or all the points in the region itself. Choosing a
representation is only part of the solution for transforming raw data into a
form suitable for subsequent computer processing. Description deals with
extracting attributes that result in some quantitative information of interest or
are basic for differentiating one class of objects from another.
6. Recognition: Recognition is the process that assigns a label, such as, “Plate” to
an object based on its descriptors.
Optical Character Recognition: Optical character recognition or optical character
reader, often abbreviated as OCR, is the mechanical or electronic conversion of
images of typed, handwritten, or printed text into machine-encoded text, whether from
a scanned document, a photo of a document, a scene-photo (for example the text on
signs and billboards in a landscape photo) or from subtitle text superimposed on an
image (for example from a television broadcast). The Techniques in OCR involve:
2. Character recognition: There are two basic types of core OCR algorithm,
which may produce a ranked list of candidate characters. Matrix matching
involves comparing an image to a stored glyph on a pixel-by-pixel basis; it is
also known as "pattern matching", "pattern recognition", or "image correlation".
This relies on the input glyph being correctly isolated from the rest of the image,
and on the stored glyph being in a similar font and at the same scale. This
technique works best with typewritten text and does not work well when new
fonts are encountered. This is the technique the early physical photocell-based
OCR implemented, rather directly. Feature extraction decomposes glyphs into
"features" like lines, closed loops, line direction, and line intersections. The
extraction features reduce the dimensionality of the representation and makes the
recognition process computationally efficient. These features are compared with
an abstract vector- like representation of a character, which might reduce to one
or more glyph prototypes. General techniques of feature detection in computer
vision are applicable to this type of OCR, which is commonly seen in
"intelligent" handwriting recognition and indeed most modern OCR software.
Nearest neighbour classifiers such as the k-nearest neighbour algorithm are used
to compare image features with stored glyph features and choose the nearest
match.
Knowledge of the grammar of the language being scanned can also help determine
if a word is likely to be a verb or a noun, for example, allowing greater accuracy.
The Lowenstein Distance algorithm has also been used in OCR post-processing to
further optimize results from an OCR API.
In this project, a prototype of Digital Image processing and OCR are executed using
different python libraries such as OpenCV 4.2 and pyTesseract respectively.
The primary camera of the computer is accessed and the image is clicked after any
key is pressed, when the vehicle is in the frame.
The input image is then fed in the system, for further processing.
The Morphed image and the input image and the morphed image are then displayed
when any key is pressed. The Morphed image is obtained after morphological
transformation.
After pressing one more key, the segmented plate is displayed from the morphed
image in a new window which is performed using contour extraction on the morphed
image.
The final step involves performing optical character recognition on the segmented
plate using Tesseract engine and a library known as pyTesseract in python. The
vehicle number is displayed on the terminal and the plate region is highlighted in a
new image in a new window, after pressing one more key.
Python was conceived in the late 1980s as a successor to the ABC language.
Python 2.0, released 2000, introduced features like list comprehensions and a garbage
collection system capable of collecting reference cycles. Python 3.0, released 2008,
was a major revision of the language that is not completely backward-compatible, and
much Python 2 code does not run unmodified on Python 3. Due to concern about the
amount of code written for Python 2, support for Python 2.7 (the last release in the 2.x
series) was extended to 2020. Language developer Guido van Rossum shouldered
sole responsibility for the project until July 2018 but now shares his leadership as a
member of a five-person steering council. Python interpreters are available for many
operating systems. A global community of programmers develops and maintains
CPython, an open-source reference implementation. A non-profit organization, the
Python Software Foundation, manages Python and CPython.
The assignment statement (token '=', the equals sign). This operates differently than in
traditional imperative programming languages, and this fundamental mechanism
(including the nature of Python's version of variables) illuminates many other features
of the language. Assignment in C, e.g., x = 2, translates to "typed variable name x
receives a copy of numeric value 2". The (right-hand) value is copied into an allocated
storage location for which the (left-hand) variable name is the symbolic address. The
memory allocated to the variable is large enough (potentially quite large) for the
declared type. In the simplest case of Python assignment, using the same example, x =
2, translates to "(generic) name x receives a reference to a separate, dynamically
allocated object of numeric (int) type of value 2." This is termed binding the name to
the object. Since the name's storage location does not contain the indicated value, it is
improper to call it a variable. Names may be subsequently rebound at any time to
objects of greatly varying types, including strings, procedures, complex objects with
data and methods, etc. Successive assignments of a common value to multiple names,
e.g., x = 2; y = 2; z = 2 result in allocating storage to (at most) three names and one
numeric object, to which all three names are bound. Since a name is a generic
reference holder it is unreasonable to associate a fixed data type with it. However, at a
given time a name will be bound to some object, which will have a type; thus there is
dynamic typing.
The if statement, which conditionally executes a block of code, along with else and
elif (a contraction of else-if).
The for statement, which iterates over an iterable object, capturing each element to a
local variable for use by the attached block.
The while statement, which executes a block of code if its condition is true.
The try statement, which allows exceptions raised in its attached code block to be
caught and handled by except clauses; it also ensures that clean-up code in a finally
block will always be run regardless of how the block exits.
The raise statement, used to raise a specified exception or re-raise a caught exception.
The class statement, which executes a block of code and attaches its local namespace
to a class, for use in object-oriented programming.
The def statement, which defines a function or method.
The with statement, from Python 2.5 released on September 2006, which encloses a
code block within a context manager (for example, acquiring a lock before the block
of code is run and releasing the lock afterwards, or opening a file and then closing it),
allowing Resource Acquisition Is Initialization (RAII)-like behaviour and replaces a
common try/finally idiom.
The pass statement, which serves as a NOP. It is syntactically needed to create an
empty code block.
The assert statement, used during debugging to check for conditions that ought to
apply.
The yield statement, which returns a value from a generator function. From Python
2.5, yield is also an operator. This form is used to implement coroutines.
The import statement, which is used to import modules whose functions or variables
can be used in the current program. There are three ways of using import: import
<module name> [as <alias>] or from <module name> import * or from <module
name> import <definition 1> [as <alias 1>], <definition 2> [as <alias 2>], ....
The print statement was changed to the print () function in Python 3. Expressions:
Some Python expressions are like languages such as C and Java, while some are not:
Addition, subtraction, and multiplication are the same, but the behaviour of division
differs. There are two types of divisions in Python. They are floor division and integer
division. Python also added the ** operator for exponentiation. From Python 3.5, the
new @ infix operator was introduced. It is intended to be used by libraries such as
NumPy for matrix multiplication.
In Python, == compares by value, versus Java, which compares numeric by value and
objects by reference. (Value comparisons in Java on objects can be performed with
the equals () method.) Python's is operator may be used to compare object identities
(comparison by reference). In Python, comparisons may be chained, for example a <=
b <= c.
Python uses the words and, or, not for its Boolean operators rather than the symbolic
&&, ||, used in Java and C.
Python has a type of expression termed a list comprehension. Python 2.4 extended list
comprehensions into a more general expression termed a generator expression.
Anonymous functions are implemented using lambda expressions; however, these are
limited in that the body can only be one expression. Conditional expressions in
Python are written as x if c else y (different in order of operands from the c? x: y
operator common to many other languages).
Python makes a distinction between lists and tuples. Lists are written as [1, 2, 3], are
mutable, and cannot be used as the keys of dictionaries (dictionary keys must be
immutable in Python). Tuples are written as (1, 2, 3), are immutable and thus can be
used as the keys of dictionaries, provided all elements of the tuple are immutable. The
+ operator can be used to concatenate two tuples, which does not directly modify their
contents, but rather produces a new tuple containing the elements of both provided
tuples. Thus, given the variable t initially equal to (1, 2, 3), executing t = t + (4, 5)
first evaluates t + (4, 5), which yields (1, 2, 3, 4, 5), which is then assigned back to t,
thereby effectively "modifying the contents" of t, while conforming to the immutable
nature of tuple objects. Parentheses are optional for tuples in unambiguous contexts.
Python features sequence unpacking where multiple expressions, each evaluating to
anything that can be assigned to (a variable, a writable property, etc.), are associated
in the identical manner to that forming tuple literals and are put on the left-hand side
of the equal sign in an assignment statement. The statement expects an iterable object
on the right-hand side of the equal sign that produces the same number of values as
the provided writable expressions when iterated through, and will iterate through it,
assigning each of the produced values to the corresponding expression on the left.
Python has a "string format" operator %. These functions analogous to printf format
strings in C, e.g., "spam=%s eggs=%d" % ("blah", 2) evaluates to "spam=blah
eggs=2". In Python 3 and 2.6+, this was supplemented by the format () method of the
str class,
e.g. "spam= {0} eggs= {1}".format("blah", 2). Python 3.6 added "f-strings": blah =
"blah"; eggs = 2; spam={blah} eggs={eggs}'. Python has various kinds of string
literals:
Strings delimited by single or double quote marks. Unlike in Unix shells, Perl and
Perl- influenced languages, single quote marks and double quote marks function
identically. Both kinds of string use the backslash (\) as an escape character. String
interpolation became available in Python 3.6 as "formatted string literals".
Triple-quoted strings, which begin and end with a series of three single or double
quote marks. They may span multiple lines and function like here documents in
shells, Perl, and Ruby.
Raw string varieties, denoted by prefixing the string literal with an r. Escape sequence
are not interpreted; hence raw strings are useful where literal backslashes are
common, such as regular expressions and Windows-style paths. Compare "@-
quoting" in C#.
Python has array index and array slicing expressions on lists, denoted as a[key],
a[start: stop] or a[start:stop:step]. Indexes are zero-based, and negative indexes are
relative to the end. Slices take elements from the start index up to, but not including,
the stop index. The third slice parameter, called step or stride, allows elements to be
skipped and reversed. Slice indexes may be omitted, for example a[:] returns a copy
of the entire list. Each element of a slice is a shallow copy. In Python, a distinction
between expressions and statements is rigidly enforced, in contrast to languages such
as Common Lisp, Scheme, or Ruby. This leads to duplicating some functionality. For
example:
List comprehensions vs. for-loops
Conditional expressions vs. if blocks
The eval () vs. exec() built-in functions (in Python 2, exec is a statement); the former
is for expressions, the latter is for statements.
Methods: Methods on objects are functions attached to the object's class; the syntax
instance. Method(argument) is, for normal methods and functions, syntactic sugar for
Class. Method (instance, argument). Python methods have an explicit self-parameter
to access instance data, in contrast to the implicit self (or this) in some other object-
oriented programming languages (e.g., C++, Java, Objective-C, or Ruby).
Libraries: Python's large standard library, commonly cited as one of its greatest
strengths, provides tools suited to many tasks. For Internet-facing applications, many
standard formats and protocols such as MIME and HTTP are supported. It includes
modules for creating graphical user interfaces, connecting to relational databases,
generating pseudorandom numbers, arithmetic with arbitrary precision decimals,
manipulating regular expressions, and unit testing.
Some parts of the standard library are covered by specifications (for example, the
Web Server Gateway Interface (WSGI) implementation follows PEP 333), but most
modules are not. They are specified by their code, internal documentation, and test
suites (if supplied). However, because most of the standard library is cross-platform
Python code, only a few modules need altering or rewriting for variant
implementations.
As of March 2018, the Python Package Index (PyPI), the official repository for third-
party Python software, contains over 130,000 packages with a wide range of
functionality, including:
1. Graphical user interfaces
2. Web frameworks
3. Multimedia
4. Databases
5. Networking
6. Test frameworks
7. Automation
8. Web scraping [100]
9. Documentation
10. System administration
11. Scientific computing
12. Text processing
13. Image processing
Installation: Python 3.7 for Windows 7 64-bit MSI installer can be downloaded from
python.org/downloads/release/ and installed accordingly. The same URL contains the
installer for various other operating systems but this project is built on Windows 7.
After installation of python, add the path of python to the environment variables of
the system by accessing the advanced System settings from the control panel as
shown below.
Python Install Package (pip): pip is the package installer for Python. You can use pip
to install packages from the Python Package Index and other indexes.
python get-pip.py
One major advantage of pip is the ease of its command-line interface, which makes
installing Python software packages as easy as issuing a command:
Most importantly pip has a feature to manage full lists of packages and corresponding
version numbers, possible through a "requirements" file.[4] This permits the efficient
re-creation of an entire group of packages in a separate environment (e.g., another
computer) or virtual environment. This can be achieved with a properly formatted
requirements.txt file and the following command:
Install some package for a specific version python, where ${version} is replaced for
2, 3, 3.4, etc.:
In early 2005, NumPy developer Travis Oliphant wanted to unify the community
around a single array package and ported Numarray's features to Numeric, releasing
the result as NumPy 1.0 in 2006. This new project was part of SciPy. To avoid
installing the large SciPy package just to get an array object, this new package was
separated and called NumPy. Support for Python 3 was added in 2011 with NumPy
version 1.5.0. In 2011, PyPy started development on an implementation of the NumPy
API for PyPy. It is not yet fully compatible with NumPy.
NumPy is the fundamental package for scientific computing with Python. It contains
among other things:
Besides its obvious scientific uses, NumPy can also be used as an efficient multi-
dimensional container of generic data. Arbitrary data-types can be defined. This
allows NumPy to integrate with a wide variety of databases seamlessly and speedily.
NumPy is licensed under the BSD license, enabling reuse with few restrictions.
When we say "Core Python", we mean Python without any special modules, i.e.,
especially without NumPy.
Arrays
A NumPy array is a grid of values, all the same type, and is indexed by a tuple of
nonnegative integers. The number of dimensions is the rank of the array; the shape of an
array is a tuple of integers giving the size of the array along each dimension.
We can initialize NumPy arrays from nested Python lists, and access elements using square
brackets:
import NumPy as np
import numpy as np
# [ 0. 0.]]"
# [ 7. 7.]]"
# [ 0. 1.]]"
# [ 0.68744134 0.87236687]]"
You can read about other methods of array creation in the documentation.
Array indexing:
NumPy offers several ways to index into arrays.
Slicing: Similar to Python lists, NumPy arrays can be sliced. Since arrays may be
multidimensional, you must specify a slice for each dimension of the array:
import NumPy as np
# [[ 1 2 3 4]
# [ 5 6 7 8]
# [ 9 10 11 12]]
# Use slicing to pull out the subarray consisting of the first 2 rows
# [[2 3]
# [6 7]]
b = a[:2, 1:3]
You can also mix integer indexing with slice indexing. However, doing so will yield an array
of lower rank than the original array:
import NumPy as np
# [[ 1 2 3 4]
# [ 5 6 7 8]
# [ 9 10 11 12]]
# Two ways of accessing the data in the middle row of the array.
# Mixing integer indexing with slices yields an array of lower
rank, # while using only slices yields an array of the same rank as
the
# original array:
col_r1 = a[:, 1]
# [ 6]
Integer array indexing: When you index into NumPy arrays using slicing, the resulting array
view will always be a subarray of the original array. In contrast, integer array indexing allows
you to construct arbitrary arrays using the data from another array. Here is an example:
import NumPy as np
# When using integer array indexing, you can reuse the same
One useful trick with integer array indexing is selecting or mutating one element from each
row of a matrix:
import numpy as np
# [ 4, 5, 6],
# [ 7, 8, 9],
b = np.array([0, 2, 0, 1])
# [ 4, 5, 16],
# [17, 8, 9],
Boolean array indexing: Boolean array indexing lets you pick out arbitrary elements of an
array. Frequently this type of indexing is used to select the elements of an array that satisfy
some condition. Here is an example:
import numpy as np
# [ True True]]"
# of bool_idx
For brevity we have left out a lot of details about NumPy array indexing; if you want to know
more you should read the documentation.
Datatypes:
Every NumPy array is a grid of elements of the same type. NumPy provides a large set of
numeric datatypes that you can use to construct arrays. NumPy tries to guess a datatype when
you create an array, but functions that construct arrays usually also include an optional
argument to explicitly specify the datatype. Here is an example:
import numpy as np
Array math:
Basic mathematical functions operate elementwise on arrays, and are available both as
operator overloads and as functions in the NumPy module:
import numpy as np
x = np.array([[1,2],[3,4]], dtype=np.float64)
y = np.array([[5,6],[7,8]], dtype=np.float64)
# [[ 6.0 8.0]
# [10.0 12.0]]
print(x + y)
print(np.add(x, y))
# [[-4.0 -4.0]
# [-4.0 -4.0]]
print(x - y)
print(np.subtract(x, y))
# [[ 5.0 12.0]
# [21.0 32.0]]
print(x * y)
# [ 0.42857143 0.5 ]]
print(x / y)
print(np.divide(x, y))
array # [[ 1. 1.41421356]
# [ 1.73205081 2. ]]
print(np.sqrt(x))
import numpy as np
x = np.array([[1,2],[3,4]])
y = np.array([[5,6],[7,8]])
v = np.array([9,10])
w = np.array([11, 12])
print(v.dot(w))
print(np.dot(v, w))
# Matrix / vector product; both produce the rank 1 array [29 67]
print(x.dot(v))
print(np.dot(x, v))
# [[19 22]
# [43 50]]
print(x.dot(y))
print(np.dot(x, y))
NumPy provides many useful functions for performing computations on arrays; one of the
most useful is sum:
import numpy as np
x = np.array([[1,2],[3,4]])
You can find the full list of mathematical functions provided by NumPy in the documentation.
Apart from computing mathematical functions using arrays, we frequently need to reshape or
otherwise manipulate data in arrays. The simplest example of this type of operation is
transposing a matrix; to transpose a matrix, simply use the T attribute of an array object:
import numpy as np
x = np.array([[1,2], [3,4]])
# [3 4]]"
# [2 4]]"
v = np.array([1,2,3])
NumPy provides many more functions for manipulating arrays; you can see the full list in the
documentation.
Broadcasting:
Broadcasting is a powerful mechanism that allows NumPy to work with arrays of different
shapes when performing arithmetic operations. Frequently we have a smaller array and a
larger array, and we want to use the smaller array multiple times to perform some operation
on the larger array.
For example, suppose that we want to add a constant vector to each row of a matrix. We
could do it like this:
import NumPy as np
v = np.array([1, 0, 1])
y[i, :] = x[i, :] + v
# [[ 2 2 4]
# [ 5 5 7]
# [ 8 8 10]
# [11 11 13]]
print(y)
This works; however when the matrix x is very large, computing an explicit loop in Python
could be slow. Note that adding the vector v to each row of the matrix x is equivalent to
forming a matrix vv by stacking multiple copies of v vertically, then performing elementwise
summation of x and vv. We could implement this approach like this:
import numpy as np
v = np.array([1, 0, 1])
# [1 0 1]
# [1 0 1]
# [1 0 1]]"
# [ 5 5 7]
# [ 8 8 10]
# [11 11 13]]"
Numpy broadcasting allows us to perform this computation without actually creating multiple
copies of v. Consider this version, using broadcasting:
import numpy as np
# We will add the vector v to each row of the matrix x,
v = np.array([1, 0, 1])
# [ 5 5 7]
# [ 8 8 10]
# [11 11 13]]"
The line y = x + v works even though x has shape (4, 3) and v has shape (3,) due to
broadcasting; this line works as if v had shape (4, 3), where each row was a copy of v, and
the sum was performed element-wise.
If the arrays do not have the same rank, prepend the shape of the lower rank array with 1s until
both shapes have the same length.
The two arrays are said to be compatible in a dimension if they have the same size in the
dimension, or if one of the arrays has size 1 in that dimension.
The arrays can be broadcast together if they are compatible in all dimensions.
After broadcasting, each array behaves as if it had shape equal to the element-wise maximum
of the shapes of the two input arrays.
In any dimension where one array had size 1 and the other array had size greater than 1, the
first array behaves as if it were copied along that dimension
If this explanation does not make sense, try reading the explanation from the documentation
or this explanation.
Functions that support broadcasting are known as universal functions. You can find the list of
all universal functions in the documentation.
import numpy as np
and w: # [[ 4 5]
# [ 8 10]
# [12 15]]
x = np.array([[1,2,3], [4,5,6]])
# x has shape (2, 3) and v has shape (3,) so they broadcast to (2, 3),
# [[2 4 6] # [5 7 9]]
print(x + v)
# Add a vector to each column of a matrix # x has shape (2, 3) and w has shape (2,).
# yields the final result of shape (2, 3) which is the matrix x with
# [[ 5 6 7]
# [ 9 10 11]]
print((x.T + w).T)
output.
# x has shape (2, 3). Numpy treats scalars as arrays of shape ();
# following array:
# [[ 2 4 6]
# [ 8 10 12]]
print(x * 2)
Broadcasting typically makes your code more concise and faster, so you should strive to use
it where possible.
After successful installation of numpy, one can open the python terminal in the command
prompt and import numpy to test the version of numpy installed as follows:
copy: In Python, Assignment statements do not copy objects, they create bindings
between a target and an object. When we use = operator user thinks that this creates a
new object; well, it doesn’t. It only creates a new variable that shares the reference of
the original object. Sometimes a user wants to work with mutable objects, in order to
do that the user looks for a way to create “real copies” or “clones” of these objects.
Or, sometimes a user wants copies that the user can modify without automatically
modifying the original at the same time, in order to do that we create copies of
objects.
A copy is sometimes needed so one can change one copy without changing the other.
In Python, there are two ways to create copies :
Deep copy
Shallow copy
In order to make these copies, we use a copy module. We use copy module deep copy
operations.
Deep copy is a process in which the copying process occurs recursively. It means first
constructing a new collection object and then recursively populating it with copies of
the child objects found in the original. In case of deep copy, a copy of an object is
copied to another object. It means that any changes made to a copy of an object do not
reflect in the original object. In python, this is implemented using the “deepcopy()”
function.
# initializing list 1
print("\r")
li2[2][0] = 7
# Change is reflected in l2
print("\r")
# as it is a deep copy
Installation: copy module in python is normally pre installed but if not, can be installed using
pip commands as:
Note: new python installers come hands on with pre pre-installed copy module.
Pillow: Python Imaging Library (abbreviated as PIL) (in newer versions known as
Pillow) is a free library for the Python programming language that adds support for
opening, manipulating, and saving many different image file formats. It is available
for Windows, Mac OS X and Linux. The latest version of PIL is 1.1.7, was released in
September 2009 and supports Python 1.5.2–2.7, with Python 3 support to be released "later".
Development appears to be discontinued with the last commit to the PIL repository coming in
2011. Consequently, a successor project called Pillow has forked the PIL repository and
added
Python 3.x support. This fork has been adopted as a replacement for the original PIL in Linux
distributions including Debian and Ubuntu (since 13.04).
Pillow offers several standard procedures for image manipulation. These include:
1. per-pixel manipulations,
2. masking and transparency handling,
3. image filtering, such as blurring, contouring, smoothing, or edge finding,
4. image enhancing, such as sharpening, adjusting brightness, contrast or color,
5. adding text to images and much more.
Some of the file formats supported are PPM, PNG, JPEG, GIF, TIFF, and BMP. It is also
possible to create new file decoders to expand the library of file formats accessible. This
example loads an image from the hard drive and blurs it.
blurred.show()
Installation: The project uses Pillow 2.2.1 as the Python image library and uses its functions.
The pip statement to install Pillow in the system is : pip install Pillow==2.2.1
The image is first scanned and the text and graphics elements are converted into a bitmap,
which is essentially a matrix of black and white dots. The image is then pre-processed where
the brightness and contrast are adjusted to enhance the accuracy of the process. The image is
now split into zones identifying the areas of interest such as where the images or text are and
this helps kickoff the extraction process. The areas containing text can now be broken down
further into lines and words and characters and now the software is able to match the
characters through comparison and various detection algorithms. The final result is the text in
the image that we're given. The process may not be 100% accurate and might need human
intervention to correct some elements that were not scanned correctly. Error correction can
also be achieved using a dictionary or even Natural Language Processing (NLP).
We will use the Python-Tesseract, or simply PyTesseract, library which is a wrapper for
Google's Tesseract-OCR Engine. Python-tesseract is an optical character recognition (OCR)
tool for python. That is, it will recognize and “read” the text embedded in images. Python-
tesseract is a wrapper for Google’s Tesseract-OCR Engine. It is also useful as a stand-alone
invocation script to tesseract, as it can read all image types supported by the Python Imaging
Library, including jpeg, png, gif, bmp, tiff, and others, whereas tesseract-ocr by default only
supports tiff and bmp. Additionally, if used as a script, Python-tesseract will print the
recognized text instead of writing it to a file.
img = cv2.imread(r'/<path_to_image>/digits.png')
print(pytesseract.image_to_string(Image.fromarray(img))
Add the following config, if you have a tessdata error like: “Error opening data file…”
Parameters:
INSTALLATION:
Prerequisites:
You will need the Python Imaging Library (PIL) (or the Pillow fork). Under
Debian/Ubuntu, this is the package python-imaging or python3-imaging.
Install Google Tesseract OCR (additional info how to install the engine on Linux,
Mac OSX and Windows). You must be able to invoke the tesseract command as
tesseract. If this isn’t the case, for example because tesseract isn’t in your PATH, you
will have to change the “tesseract_cmd” variable
pytesseract.pytesseract.tesseract_cmd. Under Debian/Ubuntu you can use the package
tesseract-ocr. For Mac OS users. Please install homebrew package tesseract. Installing
via pip: pip install pytesseract
The whole process of Tesseract-OCR is depicted below:
The library has more than 2500 optimized algorithms, which includes a comprehensive set of
both classic and state-of-the-art computer vision and machine learning algorithms. These
algorithms can be used to detect and recognize faces, identify objects, classify human actions
in videos, track camera movements, track moving objects, extract 3D models of objects,
produce 3D point clouds from stereo cameras, stitch images together to produce a high
resolution image of an entire scene, find similar images from an image database, remove red
eyes from images taken using flash, follow eye movements, recognize scenery and establish
markers to overlay it with augmented reality, etc. OpenCV has more than 47 thousand people
in the user community and an estimated number of downloads exceeding 18 million. The
library is used extensively in companies, research groups and by governmental bodies.
Along with well-established companies like Google, Yahoo, Microsoft, Intel, IBM, Sony,
Honda, Toyota that employ the library, there are many startups such as Applied Minds,
VideoSurf, and Zeitera, that make extensive use of OpenCV. OpenCV’s deployed uses span
the range from stitching street view images together, detecting intrusions in surveillance
video in Israel, monitoring mine equipment in China, helping robots navigate and pick up
objects at Willow Garage, detection of swimming pool drowning accidents in Europe,
running interactive art in Spain and New York, checking runways for debris in Turkey,
inspecting labels on products in factories around the world on to rapid face detection in
Japan.
2. Egomotion estimation
4. Gesture recognition
6. Mobile robotics
7. Motion understanding
8. Object identification
Installation: The project uses OpenCV (4.4.0) as the computer vision library and requires
some prerequisites as :
1. Python-3.7.x.
2. Numpy.
3. Matplotlib (Matplotlib is optional, but recommended since we use it a lot in our
tutorials).
Install all packages into their default locations. Python will be installed to C:/Python37/.After
installation, open command prompt and write command:
The primary camera of the computer is accessed and the image is clicked after any
key is pressed, when the vehicle is in the frame.
The input image is then fed in the system, for further processing.
The Morphed image and the input image and the morphed image is then displayed
when any key is pressed. The Morphed image is obtained after morphological
transformation.
After pressing one more key, the segmented plate is displayed from the morphed
image in a new window which is performed using contour extraction on the morphed
image.
The final step involves performing optical character recognition on the segmented
plate using the Tesseract library known as pytesseract in python. The vehicle number
is displayed on the terminal and the plate region is highlighted in a new image in a
new window, after pressing one more key.
The project is tested on various sets of test data and the system is found to work fine
with certain pictures with particular frame measurements.
def preprocess(img):
cv2.imshow("Input",img)
threshold_img = cv2.threshold(sobelx,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
return threshold_img
def cleanPlate(plate):
im1,contours,hierarchy = cv2.findContours(thresh.copy(),cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_NONE)
if contours:
max_index = np.argmax(areas)
max_cnt = contours[max_index]
max_cntArea = areas[max_index]
x,y,w,h = cv2.boundingRect(max_cnt)
if not ratioCheck(max_cntArea,w,h):
return plate,None
return cleaned_final,[x,y,w,h]
else:
return plate,None
def extract_contours(threshold_img):
morph_img_threshold = threshold_img.copy()
dst=morph_img_threshold)
cv2.imshow("Morphed",morph_img_threshold)
cv2.waitKey(0)
im2,contours, hierarchy=
cv2.findContours(morph_img_threshold,mode=cv2.RETR_EXTERNAL,method=cv2.CHAI
N_APPROX_NONE)
return contours
def ratioCheck(area, width, height):
ratio = 1 / ratio
rmin = 3 rmax = 6
if (area < min or area > max) or (ratio < rmin or ratio > rmax):
return False
return True
def isMaxWhite(plate):
avg = np.mean(plate)
if(avg>=115):
return True
else:
return False
def validateRotationAndRatio(rect):
if(width>height):
angle = -rect_angle
else:
angle = 90 + rect_angle
if angle>15:
return False
else:
return True
def cleanAndRead(img,contours):
x,y,w,h = cv2.boundingRect(cnt)
plate_img = img[y:y+h,x:x+w]
if(isMaxWhite(plate_img)):
if rect:
x1,y1,w1,h1 = rect
x,y,w,h = x+x1,y+y1,w1,h1
cv2.imshow("Cleaned Plate",clean_plate)
cv2.waitKey(0)
plate_im = Image.fromarray(clean_plate)
text = tess.pytesseract.image_to_string(plate_im,lang='eng')
img = cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)
img = cv2.imread("testData/test.jpeg")
threshold_img = preprocess(img)
contours=
extract_contours(threshold_img)
cleanAndRead(img,contours)
Screenshots: The screenshots of the implementation of the project is attached below:
4 : Project Analysis
4.1 Testing
The project script is tested on various pictures and was successful with certain
pictures that were available under certain dimension frames.
The image was successfully enhancing the image quality and was converting the
image to binary and morphed image.
The project extracts the number plate from the car image and displays it separately.
The project successfully prints half of the License plate number after performing
Optical Character Recognition using pytesseract. The accuracy issues are there in the
Tesseract engine and can be enhanced after enhancing the configuration of the engine.
4.2 Inference
The final prototype is performing all the functions including the image acquisition, License
plate extraction, pre-processing, character segmentation and character recognition along with
printing it on the display or terminal. The project can be modified to store the number in a
database.
4.3 Application
Automatic Number Plate Recognition has a wide range of applications since the license
number is the primary, most widely accepted, human readable, mandatory identifier of motor
vehicles.
ANPR provides automated access to the content of the number plate for computer systems
managing databases and processing information of vehicle movements.
Below we indicated some of the major applications, without the demand of completeness:
Parking: One of the main applications of ANPR is parking automation and parking
security: ticketless parking fee management, parking access automation, vehicle
location guidance, car theft prevention, "lost ticket" fraud, fraud by changing tickets,
simplified, partially or fully automated payment process, amongst many others.
Access Control: Access control in general is a mechanism for limiting access to areas
and resources based on users' identities and their membership in various predefined
groups. Access to limited zones, however, may also be managed based on the
accessing vehicles alone, or together with personal identity. License plate
recognition brings
automation of vehicle access control management, providing increased security, car
pool management for logistics, security guide assistance, event logging, event
management, keeping access diary, possibilities for analysis and data mining.
Motorway Road Tolling: Road Tolling means that motorists pay directly for the usage
of a particular segment of road infrastructures. Tolls are a common way of funding the
improvements of highways, motorways, roads and bridges: tolls are fees for services.
Efficient road tolling increases the level of related road services by reducing travel
time overhead, congestion and improve roadways quality. Also, efficient road tolling
reduces fraud related to non-payment, makes charging effective, reduces required
manpower to process events of exceptions. License plate recognition is mostly used as
a very efficient enforcement tool, while there are road tolling systems based solely on
license plate recognition too.
4.4 Advantages
Automatic number plate recognition cameras are used to measure the average
vehicle speed over longer distances
Used to identify a motorist when he/she drives away without paying for their fuel
Targeted advertisement
Automatic number plate recognition cameras are used for Traffic management
systems.
Used to Analyse the behaviour (route choice, origin-destination etc.) of a motorist
for transport planning purposes
ANPR camera solutions automatically recognize customers based on their license
plate and provide them the complete information about the items that they ordered
the last time they used the service.
Automatic license plate recognition camera solutions are used to recognize the guest
vehicles in order to assist visitor management systems.
4.5 Disadvantages
The disadvantage of the license plate recognition system could be privacy rights advocates as
well as from citizens concerned with how the cameras are used to track people’s movements,
and what is done with the data they produce. Others, however, believe the cameras reduce the
need for agencies to hire more officers and are the future of law enforcement.
5 : Conclusion
This project performs mainly four tasks. The first task is to input an image of the car and this
will happen with help of the webcam of the computer for the prototype. When the image is
fed the image is enhanced in quality. The enhancement is done in the resolution and the
thresholding. The image is constraint to a fixed image frame size.
After the enhancement the image is processed to segment the number plate from the full
picture based on the mathematical model of the rectangle. The segmented plate is shown in a
new window with all the characters in binary form.
The enhanced segmented plate is then processed for OCR or Optical Character Recognition
to segment all the characters in the picture in the form of Text and then it can be stored in a
database or can be displayed as in this prototype.
The project is designed so that we can understand the technology used in now-a-days
Automatic license plate systems and OCR systems used in most of the developed countries
like Germany, France, Singapore, Japan, etc.
It is seen that security forces all over the world face problem to locate or register vehicle
number to track any culprit. It is also seen that technology can greatly help us in this situation
by solving it.
6 : Future Enhancement
As a future work the developed system would be concentrated upon increasing the accuracy
of text localization and graphics removal in caption text images. It can be evaluated using
various other available image data bases and using various other classifiers. The proposed
methods can be further improvised and applied for automatic mixed mail sorting.
REFERENCES
https://www.marketsandmarkets.com/Market-Reports/anpr-system-marke t-
140920103.html
https://opensource.google/projects/tesseract
https://www.linuxjournal.com/article/9676
https://pdfs.semanticscholar.org/bdca/d2b56e3a38ef543f6fb0a602deb5f4
53493b.pdf?_ga=2.28647292.1514298175.1598968225-502553827.1598 968225
https://pdfs.semanticscholar.org/4d31/46d2b4bf23558ec0baf93506be5b9 6437fc2.pdf
https://www.researchgate.net/publication/299858935_Proposal_for_Auto
matic_License_and_Number_Plate_Recognition_System_for_Vehicle_Id entification
https://opencv.org/#
https://pypi.org/project/Pillow/
https://www.python.org/about/gettingstarted/
https://numpy.org/learn