Barcode Detection From An Image
Barcode Detection From An Image
INTRODUCTION
1.1 Problem Definition
1.2 Scope
1
2. The application can decode barcodes which make
use of the following symbologies :
a. Code 39
b. Code 128
i. Code 128 – A
ii. Code 128 – B
iii. Code 128 – C
c. Universal Product Code – A
2
2. PROJECT DESCRIPTION
2.1 Barcode
3
2.2 Barcode Symbologies
2.2.1 Code 39
4
2.2.2 Code 128
5
2.2.3 Universal Product Code – A
The "UPC-A bar code" is by far the most common and well-
known symbology, at least in the United States. An UPC-A
bar code is the bar code you will find on virtually every
consumer good on the shelves of your local supermarket,
as well as books, magazines, and newspapers. It is
commonly called simply a "UPC bar code" or "UPC
Symbol." This isn't entirely accurate since there are a
number of other UPC formats (UPC-E, UPC 2-Digit
Supplement, UPC 5-Digit Supplement).
UPC-A encodes 11 digits of numeric (0 through 9)
message data along with a trailing check digit, for a total
of 12 digits of bar code data.
8
4. PROJECT DESIGN
3.1 Technologies used :
3.1.1 Java
Java is a programming language originally
developed by James Gosling at Sun Microsystems
and released in 1995 as a core component of Sun
Microsystems’ Java Platform. The language derives
much of its syntax from C or C++ but as a simpler
object model and fewer low-level facilities. Java
applications are typically compiled to bytecode
( class file ) that can run on any Java Virtual
Machine ( JVM ) regardless of computer
architecture. Java is general-purpose, concurrent,
class-based, and object-oriented, and specifically
designed to have as few implementation
dependencies as possible. It is intended to let
application developers “write-once run anywhere”.
3.1.4 exe4j
exe4j is a Java .exe maker that helps you integrate
your Java applications into the Windows operating
evnvironment, whether they are service, GUI or
command line aplications. If you want your own
process name instead of Java.exe in the task
manager and a user-friendly task-bar grouping in
Windows XP exe4j does the job. Exe4j helps you
with starting your java applications in a safe way
displaying native splash screen,detecting or
distributing suitable JREs and JDKs, startup error
handling and much more.
10
11
3.2 Flowchart for detection
Start
Accept
Image
Identify the
orientation of the
barcode
Display
Result
Stop
12
The barcode detection begins with acceptance of a static image
which has to be done by taking the input as the path to the
static image which is stored on the computer. To make the
input easy, instead of taking the path as string the user is
provided with an ‘Open’ Dialog Box . When the user clicks the
‘Select File’ option the dialog box prompts user to select the file
from file storage system. This can be implemented by using
‘JFileChooser’ class in java. JFileChooser provides the user a
simple mechanism to choose a file. It is done as follows :
13
Now, we need to set the environment for detection of the
barcodes by setting the types of barcodes which we want to
detect. To implement this, we create an object of the type
BarcodeReader which is defined in the library used.
BarcodeCollection barcodes =
barReader.ReadFromImage(buffImage);
14
Thus, the barcode is retrieved from the image and displayed on
the screen.
15
4. IMPLEMENTATION
4.1 Hardware requirements
1. Digital Camera ( 5 megapixel or higher).
2. A transfer medium such as USB connector.
16
4.4 Screenshots
Screenshot 1:
17
Screenshot 2 :
18
Screenshot 3 :
19
Screenshot 4 :
20
5. APPENDIX
Source Code:
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.awt.event.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import dtkbarcode.*;
public Barcodereaderproject()
{
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
frame = new JFrame("THE Barcode Detector");
frame.setLayout(new FlowLayout()) ;
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
button = new JButton("Select File");
barcode = new JLabel();
label = new JLabel();
frame.add(button);
frame.getContentPane().add(label);
frame.add(barcode);
frame.pack();
frame.setSize(500,500);
button.addActionListener(this);
frame.setVisible(true);
if (returnValue == JFileChooser.APPROVE_OPTION)
{
File selectedFile = fileChooser.getSelectedFile();
path = selectedFile.getAbsolutePath();
System.load("C:\\DTKBarReader.dll");
BarcodeReader barReader = new BarcodeReader();
String barcodeStr = new String();
barReader.setPDFReadingType(PDFReadingTypeEnum.PDF_Images);
barReader.setBarcodeOrientation(
BarcodeOrientationEnum.BO_LeftToRight.getValue() +
BarcodeOrientationEnum.BO_RightToLeft.getValue() );
BarcodeCollection barcodes =
barReader.ReadFromImage(buffImage);
if (barcodes.getCount() > 0)
{
Barcode bar = barcodes.getItem(0);
if (bar.barcodeString.length() > 0)
{
barcodeStr = bar.barcodeString;
System.out.println("Barcode: " + barcodeStr);
label=null;
if(barcodeStr.length()>0)
{
String p = "C:\\SEMINAR\\Images\\1.jpg";
File file = new File(path);
image = null;
22
try
{
image = ImageIO.read(file);
}
catch(Exception e)
{}
label = new JLabel(new ImageIcon(image));
barcode.setText("The barcode in given image
is :"+barcodeStr);
}
frame.getContentPane().setLayout(new
GridLayout(3,1,10,10));
frame.getContentPane().add(label);
frame.add(barcode);
frame.setVisible(true);
}
else
{
frame.getContentPane().setLayout(new
GridLayout(3,1,10,10));
File file = new File(path);
image = null;
try
{
image = ImageIO.read(file);
}
catch(Exception e)
{}
label = new JLabel(new ImageIcon(image));
frame.getContentPane().add(label);
barcode = new JLabel("No valid barcode detected");
frame.add(barcode);
frame.setVisible(true);
}
}
}
}
23
6. REFERENCES
Books:
Patrick Naughton and Herbert Schildt, Java Complete Reference.
Technical Papers:
1. Robert Adelmann, Marc Langheinrich, Christian
Flörkemeier, “Toolkit for Bar Code Recognition and
Resolving on Camera Phones – Jump Starting the
Internet of Things”.
Websites:
1. www.dtksoft.com
2. www.wikipedia.com
3. www.barcodeisland.com
4. java.sun.com/docs/books/tutorial
24
7. ACKNOWLEDGEMENT
We would like to thank our guide and seminar project in-
charge, Mr.Aejazul Khan guiding us through our research
and the actual project implementation. Her expertise and
guidance have helped us immensely to understand the
topic well as well as implement it in the best way possible.
25