Development of An Android Application For Recognizing Handwritten Text On Mobile Devices

Download as pdf or txt
Download as pdf or txt
You are on page 1of 56

A Project Report on

Development of an Android Application for


Recognizing Handwritten Text on Mobile
Devices

Submitted in partial fulfillment of award of


BACHELOR OF TECHNOLOGY
Degree
in
COMPUTER SCIENCE & ENGINEERING

By
AKARSH SAXENA (1508210013)
DIVYA GUPTA (1508210045)
AAKASH KUMAR (1508210001)
BABITA (1508210037)

(2019-20)

Mr. Vikas Kumar


Associate Professor

SUPERVISOR

Deptt. of Computer Science & Engineering

Moradabad Institute of Technology


Moradabad (U.P.)
ii

CERTIFICATE

Certified that the Project Report entitled “Development of an Android


Application for Recognizing Handwritten Text on Mobile Devices”
submitted by AKARSH SAXENA (1508210013), DIVYA GUPTA
(150821045), AAKASH KUMAR (1508210001), BABITA (1508210037) is
their own work and has been carried out under my supervision. It is
recommended that the candidates may now be evaluated for their project work
by the University.

Date: VIKAS KUMAR MITTAL


Place: Moradabad PROJECT GUIDE
Head Of Dept.
iii

ACKNOWLEDGEMENT

We extend our sincere efforts and gratitude towards VIKAS KUMAR (Head Of Dept.)

forgiving invaluable knowledge and wonderful technical guidance. We are thankful to all the

personals in the Department of Computer Science and Engineering, Moradabad Institute of

Technology, Moradabad for their valuable guidance and technical comments with

motivation. We are highly grateful to them for their guidance, constant encouragement, moral

support, and valuable suggestions during preparation of this project report.

We wish to express our gratitude to all other faculty members of Computer Science &

Engineering Department, who with their encouraging and most valuable suggestions have

contributed directly or indirectly towards completion of this project report. We owe a debt

of gratitude to our parents for their consistent support and meaningful suggestions.

AKARSH SAXENA (1508210013)


DIVYA GUPTA (1508210045)
AAKASH KUMAR (1508210001)
BABITA (1508210037)
Deptt. of CSE
(2015-19)
iv

ABSTRACT

In todays’ world advancement in sophisticated scientific techniques is pushing

further the limits of human outreach in various fields of technology. One such

field is the field of character recognition commonly known as OCR (Optical

Character Recognition).

In this fast paced world there is an immense urge for the digitalization of printed

documents and documentation of information directly in digital form. And there

is still some gap in this area even today. OCR techniques and their continuous

improvisation from time to time is trying to fill this gap. This project is about

devising an algorithm for recognition of hand written characters also known as

HCR (Handwritten Character Recognition) leaving aside types of OCR that

deals with recognition of computer or typewriter printed characters.

A novel technique is proposed for recognition English language characters

using Artificial Neural Network including the schemes of feature extraction of

the characters and implemented. The persistency in recognition of characters by

the AN network was found to be more than 90% of times.


v

TABLE OF CONTENTS

List of Figures vii

Chapter 1: Introduction 8

1.1: Objective Of the project 9

1.2: Approach 9

Chapter 2: Tools and Technology Used 10

2.1: Android Studio 10

2.2: Flask 11

2.3: Python 11

Chapter 3: Artificial Neural Network 13

3.1: Introduction 13

3.2: Creating and Training of Network 14

Chapter 4: Image Processing Involved in Character Recognition 22

4.1: Pre-Processing of Sample Image 22

4.2: Feature Extraction 23

Chapter 5: Simulation and Results 25

5.1: Simulation 25

5.1.1: Pre-processing of the Image 25

5.1.2: Feature Extraction of Character from Image 26

5.1.3: Creating an Artificial Neural Network 29

5.1.4: Training and Testing the Network 30

5.2: Results 31

5.2.1: Identification of Character 31

Chapter 6: Modules of The Project 32

6.1: Adaptive Thresholding 33

6.2: Dilation 33

6.3: Segmentation 33

6.4: Features Extraction 34


vi

6.5: Training/Testing of Neural Network 34

Chapter 7: Adaptive Thresholding 35

Chapter 8: Segmentation 37

Chapter 9: Character Normalization 39

Chapter 10: Feature Extraction 44

Chapter 11: Training/Testing of Neural Network 46

Chapter 12: Language Translation 47

Chapter 13: Software Requirements Specification (SRS) 48

13.1: Introduction 48

13.1.1: Purpose 48

13.1.2: Scope 48

13.1.3: References 49

13.1.4: Overview 49

13.2: Overall Description 49

13.2.1: Product Perspective 50

13.2.2: Operating Environment 50

13.3: Functional Requirements 50

13.3.1: Software Requirements 50

13.3.2: Hardware Requirements 50

13.4: Non-Functional Requirements 50

13.4.1 User Performance Requirements 50

13.4.2 Other Non-Functional Attributes 51

13.4.2.1 Security 51

13.4.2.2 Reliability 51

13.4.2.3 Maintainability 51

13.4.2.4 Portability 51

13.4: Use Case Diagram 52

Project Overview 53

References 56
vii

LIST OF FIGURES

3.1 Artificial Neural Network 13

3.2 Equivalent matrices of English alphabets 21

5.1 Original handwritten image sample 25

5.2 Binarization of the image 25

5.3 Inversion of binary image 26

5.4 Labelling and boxing of differentiated characters 26

5.5 Acquired character from the sample image 28

5.6 Image after resizing into a 7X5 sized image 28

5.7 Block diagram of an Artificial Neural Network 29

5.8 A character from ideal set 30

5.9 Programmatically adding some noise to the character 30

5.10 The character ‘A’ identified by network 31

6.1 Modules of text recognition 32

13.1 Use Case Diagram 52

14.1 Splash Screen 53

14.2 Service Chooser Activity 53

14.3 Source Chooser Activity 54

14.4 Image Cropper Activity 54

14.5 Recognized Text 55

14.6 Translation Activity 55


8

CHAPTER 1

INTRODUCTION

This project, ‘Handwritten Character Recognition’ is a software algorithm project to


recognize any handwritten text efficiently on android devices with image as an input
which can either be a previously stored image from the gallery or provided through
camera.

Character recognition, usually abbreviated to optical character recognition or shortened


OCR, is the mechanical or electronic translation of images of handwritten, typewritten or
printed text (usually captured by a scanner) into NM machine-editable text. It is a field of
research in pattern recognition, artificial intelligence and machine vision. Though
academic research in the field continues, the focus on character recognition has shifted to
implementation of proven techniques. Optical character recognition is a scheme which
enables a computer to learn, understand, improvise and interpret the written or printed
character in their own language, but present correspondingly as specified by the user.
Optical Character Recognition uses the image processing technique to identify any
character computer/typewriter printed or hand written. A lot of work has been done in this
field. But a continuous improvisation of OCR techniques is being done based on the fact
that algorithm must have higher accuracy of recognition, higher persistency in number of
times of correct prediction and increased execution time.

The idea is to device efficient algorithms which get input in digital image format. After
that it processes the image for better comparison. Then after the processed image is
compared with already available set of font images. The last step gives a prediction of the
character in percentage accuracy.
9

1.1 OBJECTIVE OF THE PROJECT

The objective of this project is to identify handwritten characters with the use of neural
networks. We have to construct suitable neural network and train it properly. The program
should be able to extract the characters one by one and map the target output for training
purpose. After automatic processing of the image, the training dataset has to be used to
train “classification engine” for recognition purpose. The program code has to be written
in JAVA and supported with the usage of Graphical User Interface (GUI) using android.

Another objective of this project is to translate language, so this application can also be
used as a language translator.

1.2 APPROACH

To solve the defined handwritten character recognition problem of classification we used


android user interface and python as a backend with Neural Network Toolbox and Image
Processing. The computation code is divided into the next categories:

• Pre-processing of the image

• Feature extraction

• Creating an Artificial Neural Network

• Training & Testing of the network

• Recognition

• Language translator
10

CHAPTER 2

TOOLS AND TECHNOLOGIES USED

2.1 ANDROID STUDIO (For user interface)

Android Studio is the official integrated development environment (IDE) for Google's

Android operating system, built on JetBrains' IntelliJ IDEA software and designed

specifically for Android development. It is available for download on Windows, macOS

and Linux based operating systems. It is a replacement for the Eclipse Android

Development Tools (ADT) as the primary IDE for native Android application

development.

Features

The following features are provided in the current stable version:-

• Gradle-based build support

• Android-specific refactoring and quick fixes

• Lint tools to catch performance, usability, version compatibility and other problems

• Pro Guard integration and app-signing capabilities

• Template-based wizards to create common Android designs and components

• A rich layout editor that allows users to drag-and-drop UI components, option to

preview layouts on multiple screen configurations.

• Support for building Android Wear apps

Built-in support for Google Cloud Platform, enabling integration with Firebase Cloud

Messaging (Earlier 'Google Cloud Messaging') and Google App Engine.

Android Virtual Device (Emulator) to run and debug apps in the Android studio.

Android Studio supports all the same programming languages of IntelliJ (and C Lion) e.g.

Java, C++, and more with extensions, such as Go; and Android Studio 3.0 or later
11

supports Kotlin and "Java 7 language features and a subset of Java 8 language features

that vary by platform version.".

2.2 FLASK (For interface between user interface and backend)

Flask is a micro web framework written in Python. It is classified as a microframework

because it does not require particular tools or libraries. It has no database abstraction

layer, form validation, or any other components where pre-existing third-party libraries

provide common functions. However, Flask supports extensions that can add application

features as if they were implemented in Flask itself. Extensions exist for object-relational

mappers, form validation, upload handling, various open authentication technologies and

several common framework related tools. Extensions are updated far more regularly than

the core Flask program.

Applications that use the Flask framework include Pinterest, LinkedIn, and the

community web page for Flask itself.

2.3 PYTHON

Python is an interpreted, high-level, general-purpose programming language. Created by

Guido van Rossum and first released in 1991, Python has a design philosophy that

emphasizes code readability, notably using significant whitespace. It provides constructs

that enable clear programming on both small and large scales. Van Rossum led the

language community until July 2018.

Python is dynamically typed and garbage-collected. It supports multiple programming

paradigms, including procedural, object-oriented, and functional programming. Python

features a comprehensive standard library, and is referred to as "batteries included".


12

Python interpreters are available for many operating systems. C Python, the reference

implementation of Python, is open-source software and has a community-based

development model. Python and C Python are managed by the non-profit Python Software

Foundation.
13

CHAPTER 3

ARTIFICIAL NEURAL NETWORK

3.1 INTRODUCTION

An early phase of Neural Network was developed by Warren McCulloch and Walter Pitts
in 1943 which was a computational model based on Mathematics and algorithm. This
model paved the way for research which was focused on the application of Neural
Networks in Artificial Intelligence.

Artificial neural network is basically a mesh of large number of interconnected cells. The
arrangement of cells are such that each cell receives an input and drives an output for
subsequent cells. Each cell has a pre-defined

The diagram below is a block diagram that depicts the structure and work flow of a
created Artificial Neural Network. The neurons are interconnected with each other in a
serial manner. The network consist of a number of hidden layers depending upon the
resolution of comparison of inputs with the dataset.

Fig 3.1: Artificial Neural Network


14

3.2 CREATING AND TRAINING OF NETWORK

In case of character recognition we have to create a 2D vector of character images which


can be fed to the network as ideal set of input variables. In our case there is a total of 26
capital English letters which we are to recognize.

Below is a set of characters written in binary form of 7x5 sized matrix of 26 capital
English letters:
15

0 0 1 0 0
0 1 0 1 0
0 1 0 1 0
1 0 0 0 1
1 1 1 1 1
1 0 0 0 1
1 0 0 0 1

1 1 1 1 0
1 0 0 0 1
1 0 0 0 1
1 1 1 1 0
1 0 0 0 1
1 0 0 0 1
1 1 1 1 0

0 1 1 1 0
1 0 0 0 1
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 1
0 1 1 1 0

1 1 1 1 0
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 1 1 1 0
16

1 1 1 1 1
1 0 0 0 0
1 0 0 0 0
1 1 1 1 0
1 0 0 0 0
1 0 0 0 0
1 1 1 1 1

1 1 1 1 1
1 0 0 0 0
1 0 0 0 0
1 1 1 1 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0

0 1 1 1 0
1 0 0 0 1
1 0 0 0 0
1 0 0 0 0
1 0 1 1 1
1 0 0 0 1
0 1 1 1 0

1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 1 1 1 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
17

0 1 1 1 0
0 0 1 0 0
0 0 1 0 0
0 0 1 0 0
0 0 1 0 0
0 0 1 0 0
0 1 1 1 0

1 1 1 1 1
0 0 1 0 0
0 0 1 0 0
0 0 1 0 0
0 0 1 0 0
1 0 1 0 0
0 1 0 0 0

1 0 0 0 1
1 0 0 1 0
1 0 1 0 0
1 1 0 0 0
1 0 1 0 0
1 0 0 1 0
1 0 0 0 1

1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
1 1 1 1 1
18

1 0 0 0 1
1 1 0 1 1
1 0 1 0 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1

1 0 0 0 1
1 1 0 0 1
1 1 0 0 1
1 0 1 0 1
1 0 0 1 1
1 0 0 1 1
1 0 0 0 1

0 1 1 1 0
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
0 1 1 1 0

1 1 1 1 0
1 0 0 0 1
1 0 0 0 1
1 1 1 1 0
1 0 0 0 0
1 0 0 0 0
1 0 0 0 0
19

0 1 1 1 0
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 0 1 0 1
1 0 0 1 0
0 1 1 0 1

1 1 1 1 0
1 0 0 0 1
1 0 0 0 1
1 1 1 1 0
1 0 1 0 0
1 0 0 1 0
1 0 0 0 1

0 1 1 1 0
1 0 0 0 1
1 0 0 0 0
0 1 1 1 0
0 0 0 0 1
1 0 0 0 1
0 1 1 1 0

1 1 1 1 1
0 0 1 0 0
0 0 1 0 0
0 0 1 0 0
0 0 1 0 0
0 0 1 0 0
0 0 1 0 0
20

1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
0 1 1 1 0

1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
0 1 0 1 0
0 0 1 0 0

1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 0 1 0 1
1 1 0 1 1
1 0 0 0 1

1 0 0 0 1
1 0 0 0 1
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1
1 0 0 0 1
21

1 0 0 0 1
1 0 0 0 1
0 1 0 1 0
0 0 1 0 0
0 0 1 0 0
0 0 1 0 0
0 0 1 0 0

1 1 1 1 1
0 0 0 0 1
0 0 0 1 0
0 0 1 0 0
0 1 0 0 0
1 0 0 0 0
1 1 1 1 1

Fig 3.2: Equivalent matrices of English alphabets


22

CHAPTER 4

IMAGE PROCESSING INVOLVED IN CHARACTER RECOGNITION

4.1 PRE-PROCESSING OF SAMPLE IMAGE

Pre-processing of the sample image involves few steps that are mentioned as follows:

Grey-scaling of RGB image

Grey-scaling of an image is a process by which an RGB image is converted into a black


and white image. This process is important for Binarization as after grey-scaling of the
image, only shades of grey remains in the image, binarization of such image is efficient

Binarization

Binarization of an image converts it into an image which only have pure black and pure
white pixel values in it. Basically during binarization of a grey-scale image, pixels with
intensity lower than half of the full intensity value gets a zero value converting them into
black ones. And the remaining pixels get a full intensity value converting it into white
pixels.

Inversion

Inversion is a process in which each pixel of the image gets a colour which is the inverted
colour of the previous one. This process is the most important one because any character
on a sample image can only be extracted efficiently if it contains only one colour which is
distinct from the background colour. Note that it is only required if the objects we have to
identify if of darker intensity on a lighter background.
The flow chart shown below illustrates the physical meaning of the processes that are
mentioned above:

RGB => Grey-scaling => Binarization => Inversion


23

4.2 FEATURE EXTRACTION

Features of a character depicts the morphological and spatial characteristics in the image.
Feature extraction is a method of extracting of features of characters from the sample
image. There are basically two types of feature extraction:
Statistical feature extraction
Structural feature extraction

Statistical feature extraction


In this type of extraction the extracted feature vector is the combination of all the features
extracted from each character. The associated feature in feature vector of this type of
extraction is due to the relative positions of features in character image matrix.
Structural feature extraction
This is a primitive method of feature extraction which extracts morphological features of a
character from image matrix. It takes into account the edges, curvature, regions, etc. This
method extracts the features of the way character are written on image matrix.

The different methods used for feature extraction are


• Piecewise –linear regression
• Curve-fitting
• Zoning
• Chain code, etc.

The functions that are used in feature extraction are:

Indexing and labelling


This is a process by which distinct characters in an image are indexed and labelled in an
image. Thus helps in classification of characters in image and makes feature extraction of
characters simple.

Boxing and Cropping

This is a process of creating a boundary around the characters identified in an image. This
helps by making cropping of characters easier. After boxing the characters are cropped out
for storing them as input variables for recognition.
24

Reshaping and Resizing

Reshaping is done to change the dimensions of the acquired character in desired shape.
Resizing is done to reduce the size of characters to a particular minimum level.


25

CHAPTER 5

SIMULATION AND RESULTS

5.1 SIMULATION

5.1.1 Pre-processing of the image

First of all the image on which the characters are written by hand is required. Below is the
example of one case in which an image sample is taken.

Fig 5.1: Original handwritten image sample

Fig 5.2: Binarization of the image


26

Fig 5.3: Inversion of binary image

5.1.2 Feature Extraction of characters from image

Indexing and Boxing of characters

Fig 5.4: Labelling and boxing of differentiated characters


27

Cropping, Reshaping and Resizing

Differentiation of characters is done by cropping the boxed characters of the pre-


processed image. At first the sub-images are are cropped label by label in the sample
image, then the character image array is resized to form a 7X5 matrix pixelated image.
This is done because an image array can only be defined with all images of fixed size.

Also the size of the character image should be maintained to a size of 7X5 because the
ideal character set is defined as a set of images with 7X5 sized 2D matrix with binary
values.

For this to be achieved first the images are reshaped to a 7 by 5 aspect ratio image then
resized into a 7 by 5 size image
28

Fig 5.5: Acquired character from the sample image

Fig 5.6: Image after resizing into a 7X5 sized image


29

5.1.3 Creating an Artificial Neural Network

The input is fed through the network which traverses through each neuron as it compares
the input image with each neuron and gives the value in terms of a percentage of
similarity between the input image and the neurons.

The neuron with having highest percentage of similarity to the input image is considered
or estimated as the most favorable output which is most likely to that input.

In our case a network with 26 neurons and one hidden layer is enough.

Fig 5.7: Block diagram of an Artificial Neural Network


30

5.1.4 Training and testing the network

It is important to note that the network would not be immune to noisy hand written input
if it is not trained properly. Or in other words, if the network is not trained with noisy set
of characters along with the ideal set of characters, the network will not show the correct
output every time. In fact all the handwritten characters remain irregular. So to make the
network identify irregular shaped characters properly we must have to train the network
with a noisy set of characters. In this case a set of noisy characters is obtained by adding
some noise programmatically with some non-zero value of mean and variance.

Fig 5.8: A character from ideal set

Fig 5.9: Programmatically adding some noise to the character


31

5.2 RESULTS

5.2.1 Identification of characters

After proper training and testing of the network, the pixelated 7 by 5 sized image of ‘A’
is fed to the network as input. Then the out we get is the resultant 2D matrix plot same
as the character ‘A’ from the ideal dataset which was fed to the network as training
dataset.

Fig 5.10: The character ‘A’ identified by network


32

CHAPTER 6

MODULES OF PROJECT

Basically our project has been divided into five modules which are as follows:

ADAPTIVE THRESHOLDING

DILATION

SEGMENTATION

FEATURE
EXTRACTION

NEAURAL NETWORK

Fig.6.1 Modules
33

6.1. ADAPTIVE THRESHOLDING

 Firstly the optimal threshold for binarization is computed by using the Otsu
method.
 Threshold is calculated to separate the handwriting from the background.
 With this threshold, the image is converted to black and white, thus highlighting
the handwritten characters which it contains.

6.2 DILATION

• The value of the output pixel is the maximum value of all pixels in the
neighborhood. In a binary image, a pixel is set to 1 if any of the neighboring pixels
have the value 1.
• Morphological dilation makes objects more visible and fills in small holes in
objects.

6.3. SEGMENTATION

 The next step is to segment the areas corresponding to the letters of the
handwritten words from the image converted to black and white.
 For this we scan the image from left to right and from bottom to top, and finding a
black pixel, will consider it as the original area delimiting the character from which is
part of.
 This area is further expanded in three directions, namely top, left and right, so as
to include the rest of the pixels that are part of the handwritten character.
 Save the new area
 Convert the new area into a matrix of 0 and 1.
34

6.4. FEATURE EXTRACTION

This module was designed to extract the features from the segmented areas of the image
containing the characters to be recognized, traits that serve to distinguish an area
corresponding to a letter from an area corresponding to other letters. To begin with, the
first n components of the discrete cosine transformation of a segmented area are
considered to be the features that describe it. In the next phase, certain statistical details
of the area are added to the discrete cosine transformation components to define its
features.

6.5. TRAINING/TESTING NEURAL NETWORK

 It is mainly used for the purpose of machine learning i.e., we train the machine
with a particular problem by giving it the inputs with the respective outputs.

 And once the machine is trained for such kind of input, and then we can use it as a
solution to that problem.
 So the main task here is to train the machine and create the dataset for that.
 It mainly consists of two methods
 ANN_TRAIN(String arg[]) – It is used for training of the svm and the path
of the file with it name is passed as the parameter to it. It generates a model file which
is used as reference to the trained dataset.
 ANN_TEST(String arg[]) – IT is used for the testing purpose and the path
of model file, input file , output file is passed as the parameter to it. It writes the result
of the input in the output file.
35

CHAPTER 7

ADAPTIVE THRESHOLDING

An important step in pre-processing an image for handwriting recognition is


transforming it into black and white. Because such an image's histogram is bimodal, we
can calculate a threshold that separates the handwriting from the background. One
method which gives very good results in this case is developed by Nobuyuki Otsu
(1979). Otsu’s method is applied to images with gray levels and it considers that the
pixels of the image are divided into two classes and separated by a threshold t.

This method solves the problem of finding the optimum threshold that minimises the
error of classifying a background pixel as belonging to the foreground and vice versa
(Cheriet et al., 2007).Without loss of generalization, handwriting is defined as being the
dark characters placed on light background. For an image with gray levels in
G= {0,1,..., L-1} , handwriting and the background can be represented by two classes
as follows: C= { 0, 1,..., t} and C={t+1,t+2,...,L-1}. The within class variance,
between-class variance, and total-variance reach the maximum at equivalent threshold t.

Using to represent them, the Otsu method consists of an exhaustive


search for the threshold which minimises the variance within a class, which is defined
as a weighed sum of the variance of the two classes:

The weights represent the probabilities of the two classes separated by a threshold t
and the variance of these classes. Otsu shows that minimising the within-class
variance is equivalent to maximising the between-class variance.
36

Where represents the mean value of class i.


The probability is calculated based on the value of the t level from the histogram:

and the class mean is given by: where x(i)


represents the i-th value of the histogram.

Similarly, we can calculate for values that correspond to gray levels


higher than t.
37

CHAPTER 8

SEGMENTATION

The solution for the segmentation of the areas of the characters in the image was given
by an implementation of a new algorithm that, scanning the image from left to right and
from bottom to top, and finding a black pixel, will consider it as the original area
delimiting the character from which is part of. This area is further expanded in three
directions, namely top, left and right, so as to include the rest of the pixels that are part
of the handwritten character. Expansion in one direction is stopped when, among the
new pixels brought by that expansion there's no black one. Expansion in that direction
is resumed when the expansions in the other directions bring in its border new black
pixels.

This process ends when either no more expansions in any direction can be done or
when the algorithm finishes scanning the entire picture.

The steps of the algorithm are the following:

1-Scan the image from left to right and from bottom to top;

2-For each black pixel encountered which is not part of an area already found do:

2.1-Tag the up, left and right directions as possible expansions;


2.2-If there is a direction of which frontier contains no black pixels, mark this direction
as not possible for expansion;
2.3-For all directions marked for expansion, increase the coordinates of the area in that
direction coordinates with one unit
38

2.4-Repeat steps 2.2 - 2.3 as long as there is at least one direction marked for
expansion;
2.5-Save the new area in a list and advance the current pixel coordinates over this one;
2.6- Resume algorithm from step 2.
39

CHAPTER 9

CHARACTER NORMALIZATION

Normalization (Cheriet et al., 2007) is a process that results in regulating the size,
position and shape of the segmented images of the characters so as to reduce the
variation in size of the images belonging to the same class thus facilitating the
extraction of features and increasing the accuracy of classification. Mainly there are two
types of methods: linear and non-linear.

As presented in Fig. 8, we mark by the width and height of the original


character, and by width and height of the normalized character and by L
the size of the standard plane. This size is considered to be, usually, 32x32 or 64x64.
We define the aspect ratios of the original character and that of the normalized one

as:

which are always between [0,1].


40

Fig.9.1. The Original Character (1); The Normalized Character


Which Fills The Standard Plane (2).

In the so-called “Aspect Ratio Adaptive Normalization” (ARAN), the aspect ratio of
the normalized character is computed adaptively based on the original character
Using one of the functions in Table 8.1. In implementing this method, normalized
character image is placed over a plan with flexible
sizes , then the plan is moved so that it is superimposed on the standard plan by
aligning the centre. If the image fills one dimension of the normalized standard plane,
then L is considered to be equal to max and the other dimension is centred in
the standard plane. With and L, we can calculate min using the formula
given above. Thus, we can obtain the size of the normalized character.

Table 9.1
Functions For Aspect Ratio Mapping

Coordinate transformation from the original plan on the character in the normalized one
is done using forward or backward mapping. If we denote the original image,
respectively, the normalized one, by , the normalized image is
41

generated based on mapping coordinates. The forward and backward


mappings are given by:

In case of the forward mapping, the x and y coordinates take discrete values, but
are not necessarily the same, while in the case of backward mapping
the reverse is true. And furthermore, in the case of direct mapping the coordinates
do not necessarily occupy all the space in the normalized plane. Thusly, for
using the normalization we need to implement mesh coordinates and pixel
interpolation. By meshing, mapped coordinates , (x , y) are approximated by the
nearest integer .

In case of the mesh in the forward mapping, the discrete coordinates (x, y) scan the
Original image pixels and the pixel value f(x,y) are assigned to all the pixels that fall

within the range .

The forward mapping is mostly used because of the fact that meshing the mapped
coordinates (x, y) can be easily done.
The functions for the forward and backwards mapping are given in table. Denoted by
in the table, they are given by:
42

Table 9.2
Functions For Coordinate Mapping

For extracting the features that define the characters in the image we used the discrete
cosine transformation (Watson, 1994), which is a technique that converts a signal into
its elementary frequency components. Each line of M pixels from an image can be
represented as a sum of M weighted cosine functions, assessed in discrete points, as
shown by the following equation (in the one-dimensional case):

In the bidimensional case, we consider a matrix S of 8x8 elements defined by (Petrescu,


2006):
43

In equation it is considered that , otherwise

It can be said that the transformed matrix elements with lower indices correspond to
coarser details in the image and those with higher indices to finer details. Therefore, if
we analyze the matrix T obtained by processing different blocks of an image, we see
that in the upper left corner of the matrix we have high values (positive or negative) and
the more we explore down to the bottom right corner the values start to decline even
more, tending to 0. The next step is the actual selection of certain elements in the array.
The first operation that can be done is to order the elements of the matrix into a one
dimensional array so as to highlight as many values of zero as possible. The ordering is
done by reading the matrix in zigzag. To extract the necessary features for character
recognition we can select the first N values from this array. As N increases, so does the
recognition accuracy, but that happen at the expense of increasing the training time of
the support vector machine.
44

CHAPTER 10

FEATURE EXTRACTION

This module was designed to extract the features from the segmented areas of the image
containing the characters to be recognized, traits that serve to distinguish an area
corresponding to a letter from an area corresponding to other letters. To begin with, the
first n components of the discrete cosine transformation of a segmented area are
considered to be the features that describe it. In the next phase, certain statistical details
of the area are added to the discrete cosine transformation components to define its
features:

• Number of black pixels from a matrix (the so called “on”" pixels);

• mean of the horizontal positions of all the "on" pixels relative to the centre of the
image and to its width;

• mean of the vertical positions of all the "on" pixels relative to the centre of the
image and to its height;

• mean of horizontal distances between "on" pixels;

• mean of vertical distances between "on" pixels;

• mean product between vertical and horizontal distances of "on" pixels;

• mean product between the square of horizontal and vertical distances between all
"on" pixels;
45

• mean product between the square of vertical and horizontal distances between all
"on" pixels;

• mean number of margins met by scanning the image from left to right;

• Sum of vertical positions of the margins met by scanning the image from left to
right;

• mean number of margins met by scanning the image from bottom to top;

• sum of horizontal positions of the margins met by scanning the image from top to
bottom.

One last operation implemented by this module is the normalization of the results
obtained up until now so as they correspond to the format accepted by the support
vector machine module.
46

CHAPTER 11

TRAINING/TESTING NEURAL NETWORK

The module offers the possibility of selecting different types of kernel functions, such
as the sigmoid, RBF, linear functions, and the setting of the various parameters of these
kernels (Hsu et al., 2010). After setting the type of kernel and its parameters, the
support vector machine is trained with the set of features given by the other modules.
Once the training is over, the support vector machine can be used to classify new sets of
characters.

ANN mainly consists of two methods:-

ANN_TRAIN(String arg []) – It is used for training of the ann and the path of the file
with it name is passed as the parameter to it. It generates a model file which is used as
reference to the trained dataset.

ANN_TEST(String arg[]) – IT is used for the testing purpose and the path of model
file, input file , output file is passed as the parameter to it. It writes the result of the
input in the output file.
47

CHAPTER 12

LANGUAGE TRANSLATION

Translation is the communication of the meaning of a source-language text by means of


an equivalent target-language text. The English language draws a terminological
distinction (not all languages do) between translating (a written text) and interpreting
(oral or sign-language communication between users of different languages); under this
distinction, translation can begin only after the appearance of writing within a language
community.

A translator always risks inadvertently introducing source-language words, grammar, or


syntax into the target-language rendering. On the other hand, such "spill-overs" have
sometimes imported useful source-language calques and loanwords that have enriched
target languages. Translators, including early translators of sacred texts, have helped
shape the very languages into which they have translated.

Translation is the communication of meaning from one language (the source) to another
language (the target). Translation refers to written information, whereas interpretation
refers to spoken information.

The purpose of translation is to convey the original tone and intent of a message, taking
into account cultural and regional differences between source and target languages.

Translation has been used by humans for centuries, beginning after the appearance of
written literature. Modern-day translators use sophisticated tools and technologies to
accomplish their work, and rely heavily on software applications to simplify and
streamline their tasks.
48

CHAPTER 13

SOFTWARE REQUIREMENTS SPECIFICATION (SRS)

13.1 INTRODUCTION

This project, ‘Handwritten Character Recognition’ is a software algorithm project


to recognize any handwritten text efficiently on android devices with image as an
input which can either be a previously stored image from the gallery or provided
through camera.

13.1.1 Purpose
The objective of this project is to identify handwritten characters with the use of
neural networks. We have to construct suitable neural network and train it properly.
The program should be able to extract the characters one by one and map the target
output for training purpose. After automatic processing of the image, the training
dataset has to be used to train “classification engine” for recognition purpose. The
program code has to be written in JAVA and supported with the usage of Graphical
User Interface (GUI) using android.

13.1.2 Scope
In this fast-paced world, there is an immense urge for the digitalization of printed
documents and documentation of information directly in digital form. And there is
still some gap in this area even today. OCR techniques and their continuous
improvisation from time to time is trying to fill this gap. This project is about
devising an algorithm for recognition of hand written characters also known as
HCR (Handwritten Character Recognition) leaving aside types of OCR that deals
with recognition of computer or typewriter printed characters.
49

Intended Audience and Reading Suggestions

This project is a functioning prototype for a handwritten text recognizer, and it is


restricted within the college premises. This has been implemented under the
guidance of college professors. This project is useful for the students, teachers as
well as the business professionals who are trying to automate the handwritten to
digital text conversion.

13.1.3 References

• https://ieeexplore.ieee.org
• https://www.kaggle.in/datasets
• https://developer.android.com/docs

13.1.4 Overview
The rest of the SRS examines the specifications of Handwritten Text Recognition
and Translation. Section 2 of the SRS presents the overall description of the
Handwritten Text Recognition and Translation. Section 3 outlines the detailed,
specific functional, performance, system and other related requirements of the
Handwritten Text Recognition and Translation.

13.2 OVERALL DESCRIPTION

To solve the defined handwritten character recognition problem of classification we


used android user interface and python as a backend with Neural Network Toolbox
and Image Processing. The computation code is divided into the next categories:
• Pre-processing of the image
• Feature extraction
• Creating an Artificial Neural Network
• Training & Testing of the network
• Recognition
• Language translator
50

13.2.1 Product Perspective

 SOFTWARE: It includes a software based on Android platform which


is connected to the database of handwritten characters of more than
hundreds of writers.
 HARDWARE: No hardware is involved.

13.2.2 Operating Environment

Operating environment for Handwritten Text Recognition and Translation is as


listed below.
 Android enabled smartphone.
 An internet connected smartphone.

13.3 FUNCTIONAL REQUIREMENTS

13.3.1 Software Requirements

 An Android smartphone
 The proposed software installed along with all permissions granted.
 Minimum API 15
 Minimum Android version 4.0.3

13.3.2 Hardware Requirements

 NO HARDWARE REQUIRED

13.4 NON-FUNCTIONAL REQUIREMENTS

13.4.1 User Performance Requirements

The user's performance will be dependent on the speed of their Internet connection as
well as the performance of the network. The project will be designed to be compatible
51

with all major Internet browsers and for a low common denominator of phone
performance, so as to be widely accessible.

13.4.2 Other Non-Functional Attributes

13.4.2.1 Security

No security measures are expected to be involved excepting the web modification


interface for maintenance, which will be protected.

13.4.2.2 Reliability

Based on up-time of server on which application resides. Regular backup of


database, or backup server for application, may be required to ensure up-time and
reliability.

13.4.2.3 Maintainability

A web-based database management engine will be developed for the maintenance of


the database.

13.4.2.4 Portability

As a standards-driven web-based application, portability should not be an issue.


52

13.5 USE CASE DIAGRAM

The use case diagram representation of the project can be represented as shown in
figure.

Use case diagram of the project basically involve-


1. User
2. Handwritten Optical Character Recognition
3. Deep Learning Algorithm
4. Translator
5. Dataset.

Fig 13.1: Use Case Diagram


53

PROJECT OVERVIEW

Fig 14.1: Splash Screen

Fig 14.2: Service Chooser Activity


54

Fig 14.3: Source Chooser Activity

Fig 14.4: Image Cropper Activity


55

Fig 14.5: Recognized Text

Fig 14.6 Translation Activity


56

REFERENCES

[1] Eugen-Dumitru Tautu And Florin Leon(May 7,2012), Handwritten Text Recognition Using
Artificial Neural Networks.

[2] Android Studio Official website : https://developer.android.com/studio/

[3] Plamondon, Réjean, and Sargur N. Srihari. " Handwritten Text Recognition: a comprehensive
survey." Pattern Analysis and Machine Intelligence, IEEE Transactions on 22.1 (2000): 63-
84.

[4] Madhvanath, Sriganesh, and VenuGovindaraju. "The role of holistic paradigms in precision
text recognition." Pattern Analysis and Machine Intelligence, IEEE Transactions on 23.2
(2001): 149-164.

[5] Park, Jaehwa, Venu Govindaraju, and Sargur N. Srihari. " Handwritten Text Recognition in a
hierarchical feature space." Pattern Analysis and Machine Intelligence, IEEE Transactions on
22.4 (2000):400-407.

[6] Cohen, G., Afshar, S., Tapson, J., & van Schaik, A. (2017). Handwritten Text Recognition
using advanced techniques involving deep learning.

[7] Monali Paul, Santosh K. Vishwakarma, Ashok Verma (2015), ‘Analysis of Handwritten Text
using Data Mining Approach’, International Conference on Computational Intelligence and
Communication Networks

[8] A.T.M Shakil Ahamed, Navid Tanzeem Mahmood, Nazmul Hossain, Mohammad Tanzir
Kabir, Kallal Das, Faridur Rahman, Rashedur M Rahman (2015) , ‘Applying Data Mining
Techniques to Recognize Handwritten Text by collecting samples from various writers’ ,
(SNPD) IEEE/ACIS International Conference.

You might also like