Document Verification System Using Blockchain: Submitted by
Document Verification System Using Blockchain: Submitted by
USING BLOCKCHAIN
A PROJECT REPORT
Submitted by
of
BACHELOR OF ENGINEERING
in
JUNE, 2023
i
K.RAMAKRISHNAN COLLEGE OF TECHNOLOGY
(AUTONOMOUS)
SAMAYAPURAM – 621 112
BONAFIDE CERTIFICATE
SIGNATURE SIGNATURE
ii
INTERNAL EXAMINER EXTERNAL EXAMINER
DECLARATION
Signature
____________________
MOHAMED ASLAM A
____________________
MOHAMED JAMEER N
____________________
RISHIKESH B
____________________
iii
SUBASH CHANDRABOSE P
Place: Samayapuram
Date:
ACKNOWLEDGEMENT
It is with great pride that we express our gratitude and in-debt to our
institution “K.Ramakrishnan College of Technology (Autonomous)”, for
providing us with the opportunity to do this project.
iv
I express my deep and sincere gratitude to my project guide Mr. R.
RAJAVARMAN, M.E., Department of COMPUTER SCIENCE AND
ENGINEERING, for his incalculable suggestions, creativity, assistance and
patience which motivated me to carry out this project.
ABSTRACT
records transactions or even digital events that have been executed and shared
among the participating parties. Our project is a management system for the
generating certificates and reduces the cost and manual work needed for the
verification of the same. The idea of our system is about uploading a certificate
by a body or institution. Then the system will hash it and then stores the
the blockchain file system. A QR code is given for verification purposes. The
verifier gives a file or QR code, then the system will compare this hash with the
v
hashes of certificates previously stored in the blockchain to verify whether it
actually exists or not. If the certificate hash has existed in the blockchain, the
same certificate will be retrieved from the blockchain file system. But if the
certificate hash hasn't existed in the blockchain, the request will be answered
negatively.
TABLE OF CONTENTS
ABSTRACT v
LIST OF TABLES vi
LIST OF ABBREVIATIONS ix
1 INTRODUCTION
1
1.1 BACKGROUND 1
1.2 PROBLEM STATEMENT 1
1.3 OBJECTIVES 2
1.4 IMPLICATION 2
2 LITERATURE REVIEW 3
2.1 HANDWRITTEN OPTICAL CHARACTER
RECOGNITION(OCR): A COMPREHENSIVE
vi
SYSTEMATIC LITERATURE REVIEW(SLR) 3
2.2 COMPARATIVE ANALYSIS OF TESSERACT
AND CLOUD VISION FOR THAI VEHICLE
REGISTRATION CERTIFICATE 3
2.3 A DETAILED ANALYSIS OF OPTICAL
CHARACTER RECOGNITION TECHNOLOGY 4
3 SYSTEM ANALYSIS 6
3.1 EXISTING SYSTEM 6
3.2 PROPOSED SYSTEM 6
3.3 APPROACH USED 6
4 MODULE DESCRIPTION 7
4.1 PERMISSION GRANTING PROCESS 7
4.2 TAKE THE IMAGE 7
4.3 DETECT FROM THE IMAGE 7
4.4 COPY THE RESULT 7
5 SYSTEM SPECIFICATION 8
5.1 HARDWARE SPECIFICATIONS 8
5.2 SOFTWARE SPECIFICATIONS 8
6 SYSTEM DESIGN 9
6.1 DESIGN 9
6.2 UML DIAGRAMS 9
6.3 GOALS 10
6.4 USECASE DIAGRAM 10
6.5 CLASS DIAGRAM
6.6 SEQUENCE DIAGRAM
7 TESTING
7.1 PURPOSE
vii
7.2 FUNCTIONAL TEST
7.3 SYSTEM TESTING
7.3.1 WHITE BOX TESTING
7.3.2 BLACK BOX TESTING
APPENDICES I
APPENDICES II
REFERENCES
LIST OF FIGURES
FIGURE NO. TITLE PAGE NO.
viii
LIST OF ABBREVIATIONS
ABBREVIATIONS
OCR - Optical Character Recognition
ix
x
CHAPTER 1
INTRODUCTION
1.1 OVERVIEW
1
1.2 PROBLEM STATEMENT
1.3 OBJECTIVES
The aim and objective of the project is to verify the documents using
blockchain. The following are the benefits that come with document
verification system using blockchain:
1.4 IMPLICATION
2
system offers streamlined processes, eliminating manual document handling
and accelerating verification timelines. This not only improves efficiency but
also reduces costs associated with paper-based documentation, postage, and
third-party verification services.
3
CHAPTER 2
LITERATURE SURVEY
YEAR: 2019
YEAR: 2018
4
and security analysis. The paper also discusses the potential applications and future
directions for blockchain-based document verification systems.
YEAR: 2018
This article discusses the application of blockchain technology for securing documents
and preventing document forgery. It provides an overview of different blockchain
architectures and consensus mechanisms suitable for document verification. The
authors analyze the security properties offered by blockchain, such as transparency,
immutability, and consensus, and how they contribute to document integrity. The
article also explores the challenges and limitations of using blockchain for document
verification, including scalability and privacy concerns. The authors provide insights
into potential solutions and future research directions in this domain.
YEAR: 2020
This paper focuses on the use of blockchain technology for securing and verifying
academic credentials. It discusses the benefits of blockchain-based systems, such as
eliminating the need for central authorities and enabling secure and transparent
verification processes. The authors present a comprehensive analysis of existing
blockchain-based credentialing systems, highlighting their features, advantages, and
limitations. The study also addresses privacy and legal considerations related to the
implementation of blockchain in the academic context. The paper concludes with
5
recommendations and future research directions for blockchain-based academic
credential systems.
CHAPTER 3
SYSTEM ANALYSIS
6
blockchain , associating it with the document's metadata and the document is stored in
IPFS. To verify the document's authenticity, the recipient recalculates the hash of the
received document and compares it with the hash stored on the blockchain. If the
hashes match, the document is considered valid and has not been tampered with.
CHAPTER 4
THEORETICAL CONSIDERATIONS
In August 2014, the bitcoin blockchain file size, containing records of all
transactions that have occurred on the network, reached 20 GB (gigabytes). In January
2015, the size had grown to almost 30 GB, and from January 2016 to January 2017,
the bitcoin blockchain grew from 50 GB to 100 GB in size. The ledger size had
exceeded 200 GB by early 2020.
7
The words block and chain were used separately in Satoshi Nakamoto's
original paper, but were eventually popularized as a single word, blockchain, by 2016.
In May 2018, Gartner found that only 1% of CIOs indicated any kind of
blockchain adoption within their organisations, and only 8% of CIOs were in the
short-term "planning or active experimentation with blockchain". For the year 2019
Gartner reported 5% of CIOs believed blockchain technology was a 'gamechanger' for
their business.
8
Figure 4.1: (a) Legacy Ledgers (Centralized); (b) Distributed Ledger.
Every person who wishes to trade any asset across a private or public network
requires access to the network. This access occurs via a software application
that mediates between user and blockchain. The software application, often
called a “wallet,” can be installed directly on a device or accessed via a web
browser. Depending on how it is designed, a blockchain wallet can be used to
send and/or receive digital assets. Some wallets allow for direct transacting
without a mediating third-party, while other wallets are run by third parties
who maintain custodianship of users’ digital assets on their behalf.
Those users wishing to participate in validating transactions through consensus
must generally to install the blockchain software on their device. This is used to
9
write to the ledger, store an entire copy of the entire ledger and keep all the
copies of the ledger perfectly synchronised. Because public blockchains allow
anyone to install the software and have a copy of the entire ledger, anyone can
transact directly on the Blockchain within the network, and no third parties can
impose conditions for access. In permissioned blockchains, a centralized
authority determines who has access to run a node and participate in the
consensus process.
The transaction-records, or blocks, in a blockchain are linked together
cryptographically, rendering them tamper-proof. Unlike records in digital
databases, which can be altered, once a transaction is recorded and
timestamped on the Blockchain, it is impossible to alter it, or delete it.
The blockchain records the fact of the transaction, that is, what has been
transferred, the parties involved, as well as structured information (metadata)
related to the transaction and a cryptographic hash (“digital fingerprint”) of
transaction content. This unique signature is used to verify transactions later: if
someone alters the transaction content, its resulting unique code no longer
matches the version that is on the chain, and the blockchain software will
highlight the discrepancy.
All parties involved in a transaction, and only those parties, must provide their
consensus before a new transaction record is added to the network. All other
nodes in the network will only verify that the two parties have the appropriate
capacity to enter into the transaction. Thus, as soon as one party agrees to send
the asset, and the other party agrees to receive the asset, and the nodes verify
that each party has the capacity to conduct the transaction, it is completed.
All computers in the network continually and mathematically verify that their
copy of the blockchain is identical to all the other copies on the network. The
version running on the majority of computers is assumed to be the ‘real’
version, so the only way to ‘hack’ the records would be to take control of over
half of the computers on the network. For a blockchain running on thousands
(or even, in the future, millions) of computers, as public blockchains like
10
Bitcoin and Ethereum do, this would-be a near-impossible task. Destroying the
ledger entirely would require deleting every copy of it in the world.
For decades, these mechanisms have been used to establish consensus among
database nodes, application servers, and other enterprise infrastructure. In recent
11
years, new consensus mechanisms have been invented to allow crypto economic
systems, such as Ethereum, to agree on the state of the network.
Broadly speaking, there are three different types of blockchain solutions which
may be applied, each of which has significant differences in architecture and
governance:
12
1. Public blockchains:
Public blockchains are open for anyone to download, run and transact
on. Solutions built using this rely on public consensus to reach decisions, and
typically may run on up to millions of machines. Thus, public blockchains
produce maximum immutability, decentralisation and transparency – however,
this is at the cost of high inefficiency in the form of high storage costs, high
electricity usage, as well as low transaction speed and volume.
2. Private blockchains:
Private blockchains are by invitation only, and operate according to a set
of rules put in place by those inviting. Such a blockchain may be used by a
small number of parties to trade exclusively amongst themselves, or it may be
open to anyone to transact upon, but only allow a select group of users to
change the rules and/or to validate transactions. Effectively, a private
blockchain reduces the immutability, and transparency of the chain, and is
highly centralised (while still offering these advantages more than a traditional
database) – however, the reduced number of parties involved means that the
chain itself tends to be much smaller and specialised – leading to high
efficiency, high transaction volume and speed, and consequently lower costs
and resources usage.
3. Consortium Blockchains:
Consortium blockchains are effectively a hybrid of the two models. A
consortium blockchain is a private blockchain, i.e. by invitation only, but all
persons invited have equitable voting rights, with decisions taken by consensus.
Thus, from a governance perspective it keeps the decentralised nature of a
public blockchain. In terms of immutability, transparency and resource usage it
provides a midway between the features of private and public chains.
13
Cost reductions by eliminating third-party verification.
Decentralization makes it harder to tamper with.
Transactions are secure, private, timestamped and efficient.
Immutable.
Transparent technology.
Provides a banking alternative and a way to secure personal information for
citizens of countries with unstable or underdeveloped governments.
4.2.5 TRANSACTIONS:
4.2.5.1 GAS:
Gas refers to the unit that measures the amount of computational effort required
to execute specific operations on the Ethereum network. Since each Ethereum
transaction requires computational resources to execute, each transaction requires a
fee. Gas refers to the fee required to conduct a transaction on Ethereum successfully.
14
4.2.5.2 DIGITAL SIGNATURE:
15
Certification authorities can verify the identity of persons to whom keys
are issued, thus linking public-keys to real-world identities.
Everyone can have confidence of the date of signature, since the ‘clock’
is maintained only by the certification authority.
Public Key means the public address where other wallets send transaction
values.
Private Key means an encryption key uniquely linked to the owner and known
only to the parties exchanged in a transaction; it is secretly held in a digital wallet.
16
Figure 4.4: Anatomy of a Digitally Signed Document.
4.2.5.3 HASHING:
A hash is the output of a hash function that expects an input value - in this case,
PDF documents - and generates an output value in the form of a string of fixed length.
The main feature of hash functions is that it is almost impossible to find two different
input values that generate the same hash value. The hash function used in this
approach is SHA-3 with a length of 256 bits. SHA-3, unlike MD5, is considered
collision resistant, which means that the chance that two different input values
produce different output values is very high. Hashes can be used to prove the
authenticity of software artifacts. In this case, one speaks of checksums. To inform a
17
user about the authenticity of downloaded software, companies often highlight the
checksum on their website. The software can also generate a checksum which has to
match with the checksum from the website. The checksum functionality can also be
used for diplomas. If someone makes even the smallest changes to the document, the
hash will change completely. SHA-3 is a one-way function, which means that it is not
possible to recreate the input from the output. This property and also the uniqueness of
hashes make it possible to encrypt diplomas without revealing confidential
information. No one can interpret the 18 content of the diploma with the resulting
hash, but it can be regarded as a unique link pointing to the official certificate.
There are several ways to create a blockchain, the most important of which are:
1. Bitcoin:
18
Bitcoin is an online equivalent of cash. Cash is authenticated by its physical
appearance and characteristics, and in the case of banknotes by serial numbers and
other security devices. However, in the case of cash there is no ledger that records
transactions and there is a problem with forgeries of both coins and notes. In the case
of Bitcoins, the ledger of transactions ensures their authenticity. Both coins and
Bitcoins need to be stored securely in real or virtual wallets respectively — and if
these are not looked after properly, both coins and Bitcoins can be stolen.
It can only store the sender, receiver, amount of cash transferred and a
hash.
It can only process fewer than 10 transactions per second (compared to
tens of thousands for a typical credit card network), a limit which has
already been reached.
Its size is growing exponentially, leading to a situation where only users
with massive amounts of computing power can keep a copy of the entire
Blockchain, reducing the number of computers in the network, and
decreasing security overall.
2. Ethereum:
Furthermore, Ethereum can process more transactions per second, and is more
flexible in the amount and kinds of data which can be stored on it. In our project we
will create our own blockchain based on the Ethereum network.
3. Hyperledger Fabric:
Fabric’s architecture is far more complex than any blockchain platform while
also being less secure against tampering and attacks. You would think that a “private”
blockchain would at least offer scalability and performance, but Fabric fails here as
well. Simply put, pilots built on Fabric will face a complex and insecure deployment
that won’t be able to scale with their businesses.
20
regular contract where after reaching an agreement, parties must execute the contract
for it to take place, a smart contract is self-executing - that is, once the instructions are
written to a blockchain, the transaction will take place automatically when the
appropriate conditions are detected.
The Ethereum network is the most famous example of a smart contract based
blockchain. It provides a virtual machine that executes, and charges for it, code on
every single node of the network.
4.3.1.1 EVM:
The Ethereum Virtual Machine or EVM is the runtime environment for smart
contracts in Ethereum. It is not only sandboxed but actually completely isolated,
which means that code running inside the EVM has no access to network, filesystem
or other processes. Smart contracts even have limited access to other smart contracts.
4.3.1.2 SOLIDITY:
It was influenced by C++, Python and JavaScript and is designed to target the
Ethereum Virtual Machine (EVM)[S]. Solidity is statically typed. It supports complex
member variables for contracts, including arbitrarily hierarchical mappings and
structs. Solidity contracts support inheritance, including multiple inheritance with C3
linearization. Solidity uses ECMAScript-like syntax which makes it familiar for
existing web developers;[citation needed] however unlike ECMAScript it has static
typing and variadic return types. Solidity introduces an application binary interface
(ABI) that facilitates multiple type-safe functions within a single contract.
21
It is possible to create contracts for voting, crowdfunding, blind auctions,
multi-signature wallets and more.
4.3.1.2.1 ABI:
4.3.1.3 IDE:
4.3.1.3.1 REMIX:
Remix is a web browser based IDE that allows to write Solidity smart
contracts, then deploy and run the smart contracts. The best way to try out Solidity
right now is using Remix.
4.3.1.4 GANACHE:
Another IDE for running smart contract. Ganache is a personal blockchain for
rapid Ethereum distributed application development. You can use Ganache across the
entire development cycle; enabling you to develop, deploy, inspect state and test your
22
dApps in a safe and deterministic environment while controlling how the chain
operates. All versions of Ganache are available for Windows, Mac, and Linux.
4.3.1.5 TRUFFLE:
Ethereum wallets are applications that let you interact with your Ethereum
account. Think of it like an internet banking app – without the bank. Your wallet lets
you read your balance, send transactions and connect to applications.
Your wallet is only a tool for managing your Ethereum account. That means
you can swap wallet providers at any time. Many wallets also let you manage several
Ethereum accounts from one application. That's because wallets don't have custody of
your funds, you do. They're just a tool for managing what's really yours.
23
MetaMask allows users to store and manage account keys, broadcast
transactions, send and receive Ethereum-based cryptocurrencies and tokens, and
securely connect to decentralized applications through a compatible web browser or
the mobile app's built-in browser. Developers achieve a connection between
Metamask and their decentralized applications by using a JavaScript plugin such as
Web3js or Ethers to define interactions between Metamask and Smart Contracts.
4.3.3 WEB3.JS:
4.5 IPFS:
IPFS is a peer-to-peer (P2P) distributed system for storing and accessing files.
IPFS creates a hash of every single file stored in it. The files are, subsequently,
accessed using these same hashes. Besides, it also features file versioning and
duplicate file removal. Its uses are mostly for creating distributed file-sharing services.
It is also widely used coupled with the Ethereum blockchain.
24
4.6 PROOF OF EXISTENCE:
CHAPTER 5
MODULE DESCRIPTION
5.1 UI DESIGN:
The UI Design consists of five pages – Home, Upload, Verify, Delete, Admin.
Home is the index page of system which the user visits first.
Upload is the page to upload the document.
Verify is the page to verify the authenticity of the document.
Delete page is to delete the document.
Admin page is to control the overall system.
25
5.2 ADMIN PANEL:
The person who integrate the system with the blockchain has the Super Admin
access.
Super Admin can add sub admins through their public key and the exporter
name.
Admin has the rights to add, edit and delete the exporter(sub-admin).
With the public key, the sub-admin can upload the documents.
5.4 VERIFICATION:
Organizations need to validate the applicant’s document, so they will visit the
official website of the document provider for the purpose of verification.
Once the document file is uploaded (or through a QR code), the document will
be hashed.
When the “verify” button is clicked, the system checks the document hash with
the previously archived document hashes in the blockchain.
5.5 DELETION:
26
Through the “Choose File” entry, the document file is uploaded. Once the
document file is uploaded, the document will be hashed.
When the “Delete Document" button is clicked, it will wait for confirmation or
rejection of the transaction.
CHAPTER 5
SYSTEM SPECIFICATION
27
Operating System – Android 5 or Higher.
Languages Used – Java.
Framework – MLKit.
CHAPTER 6
SYSTEM DESIGN
6.1 DESIGN
28
Figure 6.1 Working of the system
The goal is for UML to become a common language for creating models of
object oriented computer software. In its current form UML is comprised of two major
components: a Meta-model and a notation. In the future, some form of method or
process may also be added to; or associated with, UML.
The UML represents a collection of best engineering practices that have proven
successful in the modelling of large and complex systems.
29
The UML is a very important part of developing objects oriented software and
the software development process. The UML uses mostly graphical notations to
express the design of software projects.
6.3 GOALS
30
Figure 6.2 Use case Diagram
31
Figure 6.3 Class Diagram
32
Figure 6.4 Sequence Diagram
CHAPTER 7
TESTING
7.1 PURPOSE
Software testing is the act of examining the artifacts and the behaviour of
the software under test by validation and verification. Software testing can also
33
and viability of implementation, usability, performance, security,
infrastructure considerations, etc.
reviewing the product architecture and the overall design of the product
working with product developers on improvement in coding techniques,
design patterns, tests that can be written as part of code based on various
techniques like boundary conditions, etc.
executing a program or application with the intent of examining behaviour
reviewing the deployment infrastructure and associated scripts and
automation
take part in production activities by using monitoring and observability
techniques
Software testing can provide objective, independent information about the quality of
software and risk of its failure to users or sponsors
34
successive processes must be considered for testing. Before functional testing
is complete, additional tests are identified and the effective value of current
tests is determined.
System testing ensures that the entire integrated software system meets
requirements. It tests a configuration to ensure known and predictable results. An
example of system testing is the configuration-oriented system integration test.
System testing is based on process descriptions and flows, emphasizing pre-driven
process links and integration points.
White Box Testing is a testing in which in which the software tester has
knowledge of the inner workings, structure, and language of the software, or at least
its purpose. It is purpose. It is used to test areas that cannot be reached from a black
box level. White Box Testing is a testing in which in which the software tester has
knowledge of the inner workings, structure and language of the software, or at least its
purpose. It is purpose. It is used to test areas that cannot be reached from a black box
level.
Black Box Testing is testing the software without any knowledge of the inner
workings, structure or language of the module being tested. Black box tests, as most
other kinds of tests, must be written from a definitive source document, such as
specification or requirements document, such as specification or requirements
document. It is a testing in which the software under test is treated, as a black box you
cannot “see” into it. The test provides inputs and responds to outputs without
considering how the software works.
35
7.5 UNIT TESTING
Unit testing is usually conducted as part of a combined code and unit test phase
of the software lifecycle, although it is not uncommon for coding and unit testing to be
conducted as two distinct phases. Unit testing is usually conducted as part of a
combined code and unit test phase of the software lifecycle, although it is not
uncommon for coding and unit testing to be conducted as two distinct phases.
Field testing will be performed manually, and functional tests will be written in
detail.
Test Results: All the test cases mentioned above passed successfully. No defects
encountered.
36
7.7 ACCEPTANCE TESTING
Test Results: All the test cases mentioned above passed successfully. No defects
encountered.
37
CHAPTER 8
8.1 CONCLUSION
After making this project we assure that this project will help its users to
extract text from the image. It will help the users to save their valuable time. This
project successfully avoids the need for manual typing large amount of data from the
documents. The modules are developed with efficient and also in an attractive manner.
In short, this project will help its users to save time by extracting text from the
document.
38
APPENDIX A
Sample code
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black_shade_1"
tools:context=".MainActivity">
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:src="@drawable/scanner"
android:layout_marginTop="120dp"
android:id="@+id/idIVLogo"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/idIVLogo"
39
android:id="@+id/idTVHead"
android:layout_centerHorizontal="true"
android:layout_marginStart="20dp"
android:layout_marginTop="39dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="10dp"
android:gravity="center"
android:textAlignment="center"
android:textColor="@color/yellow"
android:textSize="18sp"
android:textStyle="bold" />
<Button
android:id="@+id/idBtnCapture"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below= "@id/idTVHead"
android:layout_marginStart="28dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="20dp"
android:background="@drawable/button_back"
android:text="Capture Image"
40
android:textAllCaps="false"
app:backgroundTint="@color/yellow" />
</RelativeLayout>
MainActivity.java
package com.example.ocr;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
captureBtn = findViewById(R.id.idBtnCapture);
captureBtn.setOnClickListener(new View.OnClickListener() {
@Override
});
}}
activity_scanner.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black_shade_1"
tools:context=".ScannerActivity">
<ImageView
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:src="@drawable/scanner"
android:id="@+id/idIVCaptureImage"/>
<TextView
android:id="@+id/idTVDetectedText"
42
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/idIVCaptureImage"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:gravity="center"
android:padding="4dp"
android:textAlignment="center"
android:textColor="@color/yellow"
android:textSize="18sp"
android:textStyle="bold" />
<EditText
android:id="@+id/idTVE"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/idTVDetectedText"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
43
android:layout_marginBottom="20dp"
android:gravity="center"
android:padding="4dp"
android:textAlignment="center"
android:textColor="@color/yellow"
android:textSize="18sp"
android:textStyle="bold" />
<Button
android:id="@+id/idBtnSnap"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/idTVE"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="20dp"
android:background="@drawable/button_back"
android:text="Snap"
android:textAllCaps="false"
app:backgroundTint="@color/yellow" />
<Button
android:id="@+id/idBtnDetect"
44
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/idBtnSnap"
android:layout_marginStart="20dp"
android:layout_marginTop="38dp"
android:layout_marginEnd="20dp"
android:background="@drawable/button_back"
android:text="Detect"
android:textAllCaps="false"
app:backgroundTint="@color/yellow" />
</RelativeLayout>
ScannerActivity.java
package com.example.ocr;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.content.Intent;
import android.content.pm.PackageManager;
45
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.ml.vision.common.FirebaseVisionImage;
import com.google.mlkit.vision.common.InputImage;
import com.google.mlkit.vision.text.Text;
import com.google.mlkit.vision.text.TextRecognition;
import com.google.mlkit.vision.text.TextRecognizer;
import com.google.mlkit.vision.text.TextRecognizerOptions;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scanner);
captureIV = findViewById(R.id.idIVCaptureImage);
resultTV = findViewById(R.id.idTVDetectedText);
resultYT=findViewById(R.id.idTVE);
snapBtn = findViewById(R.id.idBtnSnap);
detectBtn = findViewById(R.id.idBtnDetect);
detectBtn.setOnClickListener(new View.OnClickListener() {
@Override
detectText();
});
snapBtn.setOnClickListener(new View.OnClickListener() {
47
@Override
if (checkPermissions()) {
captureImage();
} else {
requestPermission();
});
48
private void captureImage() {
if (takePicture.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePicture, REQUEST_IMAGE_CAPTURE);
@Override
if (grantResults.length > 0) {
PackageManager.PERMISSION_GRANTED;
if (cameraPermission) {
Toast.LENGTH_SHORT).show();
} else {
49
@Override
data) {
RESULT_OK) {
captureIV.setImageBitmap(imageBitmap);
InputImage image=InputImage.fromBitmap(imageBitmap,0);
(TextRecognizerOptions.DEFAULT_OPTIONS);
OnSuccessListener<Text>() {
@Override
Rect blockFrame=block.getBoundingBox();
Point[] lineCornerPoint=line.getCornerPoints();
Rect linRect=line.getBoundingBox();
String elementText=element.getText();
result.append(elementText);
resultYT.setText(blockText);
}).addOnFailureListener(new OnFailureListener() {
@Override
image.."+e.getMessage(), Toast.LENGTH_SHORT).show();
});
51
}}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.ocr">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@drawable/scanner"
android:label="@string/app_name"
android:roundIcon="@drawable/scanner"
android:supportsRtl="true"
android:theme="@style/Theme.Ocr"
tools:targetApi="31">
<activity
android:name=".ScannerActivity"
52
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
</intent-filter>
</activity>
</application>
</manifest>
build.gradle(Ocr)
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.3.13'
}// Top-level build file where you can add configuration options common to all sub-
projects/modules.
plugins {
53
}
delete rootProject.buildDir
build.grade(:app)
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
android {
compileSdk 32
defaultConfig {
applicationId "com.example.ocr"
minSdk 21
targetSdk 32
54
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
'proguard-rules.pro'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
55
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.firebase:firebase-core:19.0.0'
implementation 'com.google.android.gms:play-services-mlkit-text
recognition:16.2.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation platform('com.google.firebase:firebase-bom:30.4.1')
implementation 'com.google.firebase:firebase-core:15.0.2'
implementation 'com.google.firebase:firebase-ml-vision:15.0.0
56
APPENDIX B
SAMPLE OUTPUT
activity_main
57
activity_scanner
58
Final Output
REFERENCES
59