recognition & conversion of barcode using camera image
DESCRIPTION
Term Project Report of Recognition & Conversion of Bar code using Camera Image. Implementation was done on Matlab2009. Report written in IEEE publication format.TRANSCRIPT
1
Abstract—In this report we present the method of
deciphering the barcode using image processing, and
its implementation on Matlab®. 1D barcode labeling
is a commercial method to store information about a
product for the checkout systems of large marts and
shopping centers. Nearly all products are labeled
with barcodes at the time of their manufacturing and
sometimes shop owners label products using their
own barcodes. The conventional bar code scanners
are not portable as they need both a power source
and a computer with the database of the product, to
be read. Also they are not readily available. It would
be convenient for the costumers to read and decipher
these barcodes using their portable devices such as
digital cameras and mobile phones, In order to gain
the specific information about the product provided
by the manufacturer. Our aim in this project was to
take those barcode images taken by cameras and
decipher them. We used edge detection to find the
edges of barcode and through the knowledge of the
standard that the barcode is encoded in; we convert
the image into the decimal code.
1. INTRODUCTION
Barcodes is a machine readable encoding process. It is
being used extensively throughout the world. There are
different standards of the barcode, each having its pros and
cons. The latest barcode standard is EAN, which was formerly
known as “European Article Number” but now is called
“International Article Number”. But we have chosen UPC,
Universal Product Code, because it is the most widely used
barcode and has an error detection mechanism in it, which aids
the deciphering process.
Barcodes are used to encode specific information about the
product, for the ease of consumers and shopkeepers. Several
types of devices are there to read these barcodes, e.g., LED
scanners, Laser scanners etc. These devices are cumbersome to
use and are neither readily available nor mobile. This limits the
product information to the shop owners only, to aid costumers
in extracting this information, portable solution to the
deciphering of barcodes must be provided. One of these
solutions is the deciphering of the barcode using handheld
devices such as mobile phones and digital cameras. These
devices take the picture of the barcode and then use either an
online platform to extract the information about the product or
use some other kind of connectivity to the database containing
the information about the product. Retrieval of such
information is vital for people with medical afflictions towards
some products and for the validation of price and legitimacy of
the product. Many efforts have been made to achieve the
deciphering using images of camera phone (see references for
details). These methods may be more accurate but they are
computationally expensive and time consuming. So we have
developed a method of robust deciphering [1] of the barcode
which is a practically viable solution. The details of our
method and its Matlab® implementation are discussed next.
2. OBJECTIVES
The main objectives of our project were:
Read a Barcode from a camera image
Decode the barcode
Remove any type of noise that may occur
Recognition & Conversion of Barcode using
Camera Image
Amna Meer Reg. No.442 Aneeba Masood Reg. No.443
Asadullah Hussain Reg. No.404 Rahma Shaukat Gill Reg. No.456
BEE-5D
2
3. BARCODE DETECTION
The first step in the deciphering is the detection of barcode.
This can be easily achieved by several edge detection
techniques. We have employed the fact that barcode is an
intensity image. It contains vertical strips of black and white
lines. So we use the gray thresh value of the image to detect
the start and the end of the barcode strips. This can be
achieved by the wavelet transform method [3] or by
morphological operations [10] but we want a method that is
both quick and efficient so we use scanline based approach.
This method uses the fact that a horizontal scanline is at the
center of the barcode. If the image of barcode is not centered
or the center region contains distortions then the algorithm will
simply shift the scanline above or below the center of the
image until we get non distorted region. The Matlab®
implementation is given in Appendix A.
Fig. 1 The Scanline Approach [1]
4. BINARIZATION
The next step is the Binarization of the image. We have to
distinguish the barcode i.e., black strips from the white
background i.e., spaces. First the start and the end of the
barcode is detected i.e., first black strip and last black strip.
Then scanline scans the pixels from the center. Then the gray
thresh values are used to assign 1s to spaces and 0 s to strips.
If the gray thresh is other than that of black or white. We have
defined two ranges for gray thresh values, one range is allotted
1 for white and other is assigned a binary 0 for black. If the
gray thresh value of a pixel lies within the white range it is
assigned binary 1 i.e., we say that this pixel is white or space
but has been discolored, if it lies in other range then it is
assigned the opposite binary number i.e., 0 we say that the
pixel was black but has been decolored. In this way the
decolored pixels that may arise in the barcode image are
accounted for and thus a type of noise is taken care of. This
method is derived from the luminous method described in [1].
In this method without searching for the edges the scanline
binarizes all the pixels. The pixel selected first is the middle
one. To cater for the noises first the scanline pixels are
smoothed and then the luminance value Y(x) Ԑ [0, 1] is
calculated for each pixel, whose position is given by:
.
Then the local minima and maxima are computed. The
Matlab® implementation is described in Appendix A.
Fig. 2 Block Diagram of our Algorithm, Input is an image of barcode.
Which is detected and binatized by scanline approach, then error
check and decimanl conversion are applied.
5. ERROR CHECKING
Once the image has been binarized then all we have to do is to
use our knowledge about the construction of the barcode, this
in our case is achieved by the knowledge of UPC‟s encoding
process. In nearly all the Barcode standards we have a total of
13 decimal digits. The last is the parity bit. This digit is used
to provide the second step of the double error check.
A. The UPC standard [12]
An UPC-A barcode consists of four areas:
i. The number system
ii. The manufacturer code
iii. The product code
iv. The check digit
3
Number System is for the class or type to which the product
belongs.
The manufacturer code is given to each manufacturer by UCC
council for companies.
The product code is a 5-digit number that the manufacturer
gives to his products.
The check digit verifies the validity of the product. It tells
whether the barcode has been scanned properly of not.
Fig.3 A standard UPC-A barcode [10]
The barcode begins & ends with a „101‟ or “black-white-
black” pattern, these are also termed as guard bars. Between
these guard bars, we have two blocks of black and white
strips, separated by a central bar which is a „01010‟ or “white-
black-white-black-white” pattern. The two blocks on either
side of the central bar contain the decimal code, which is
different for each product. Each decimal digit is encoded by
using 7 bits. Even and Odd alphabets are used for the
encoding. First digit is called the meta-number or induced
digit [1].
Fig. 4 A typical UPC barcode. Guard bars are highlighted green [14]
To ensure that the scanline does not go outside the boundary
of the image, we set our starting position in the middle of the
image, to the value where luminance is 0 or we start with a bar
(black). Then we scan left and right from this point by using
pre-determined steps or blocks of pixels. The choice of the
steps helps us in finding the guard bars, which are used for the
first step of the error detection.
The error detection is as follows:
If
The first 3 bits of the binarized image are equal to 101.
The bit 46 is 0, 47 is 1, 48 is 0, 49 is 1 and 50 is 0.
The last three bits i.e., 93, 94 and 95 are equal to 101.
Then
The binarized image is a valid UPC code. If any one of the
above mentioned conditions is not satisfied then the code is
not a valid UPC code.
The Matlab® implementation is given in Appendix A
6. CONVERSION
For the conversion of the binarized image to the decimal we
again use our knowledge of the UPC construction. There is a
lookup table [14] with which we compare our bits.
We ignore first and last 3 bits as they are the guard bits. Also
we do not consider the central bits. As these bits are same for
all the barcodes. Starting from the 4th
bit (first three bits are
guard bits) and selecting seven bits at a time. These seven bits
are compared with the lookup table of Figure 2 and by
comparison we allocate decimal values to the block of seven
bits. We can see from the table that if we are looking at bits to
the left of the central bits then we use the “Left Bit Pattern”
column to compare, while if we are looking at bits on the right
of the central bits we use the “Right Bit Pattern”.
Digit Left Bit Pattern Right Bit Pattern
0 0001101 1110010
1 0011001 1100110
2 0010011 1101100
3 0111101 1000010
4 0100011 1011100
5 0110001 1001110
6 0101111 1010000
7 0111011 1000100
8 0110111 1001000
9 0001011 1110100
4
Once the 12 digits have been calculated the check sum bit is
calculated, it is calculated by the following method [14]
1. The digits that are in the odd numbered positions are
added and multiplied by 3.
2. The digits in the even numbered positions are added.
3. The sum of even numbered is added to the sum of
odd numbered.
4. The result is modulo 10.
5. If the result is zero then check bit is zero. Otherwise
subtract it from 10 and the answer is the result.
7. EXPERIMENTS
We used a database of images [15]. To test our project using
Matlab®. The Experiments were very assuring and we reached
a success rate of 97%. We also used images which were
affected by minor noise.
Fig. 5 (a) (b)
(d) (e)
Images (a) - (e) Successfully Deciphered
(f) Decoding Unsuccessful
The Matlab® implementation is given in Appendix A
8. CONCLUSION
Hence we are able to achieve all of our preset objectives for
this semester project, i.e., we have successfully deciphered
UPC barcode using image processing techniques in Matlab®.
We were also able to account for minor noise distortions as in
Figure 5 (d). For future our next step will be to remove as
many types of noises as we can from the image and add
support for other barcode standards such as EAN and Codabar
as well.
9. ACKNOWLEDGMENTS
We would like to thank Mr. Saad Qaisar and Ms. Jaweria
Amjad for their support throughout the semester.
1) Dr. Saad Qaisar
2) Jaweria Amjad
10. REFERENCES
[1]. Robust Recognition of 1-D Barcodes Using Camera
Phones by Steffen Wachenfeld, Sebastian Terlunen,
Xiaoyi Jiang, Computer Vision and Pattern Recognition
Group, Department of Computer Science, University of
M¨unster, Germany, 2006.
[2]. Mastering Matlab 7 by Duane Hanselman, Bruce
Littlefield
[3]. K. Wang, Y. Zou, H. Wang: 1D Bar Code Reading on
Camera Phones. Int. Journal of Image and Graphics,
7(3):529–550, 2007.
[4]. S. Wachenfeld, S. Terlunen, X. Jiang:
http://cvpr.uni-muenster.de/research/barcode
[5]. R. Muniz, L. Junco, A. Otero: A Robust Software Barcode
Reader Using the Hough Transform. In Proc. of the Int.
Conf. on Information Intelligence and Systems, 313–319,
1999.
[6]. E. Ohbuchi, H. Hanaizumi, L. A. Hock: Barcode Readers
Using the Camera Device in Mobile Phones. In Proc. of
the Int. Conf. on Cyberworlds, 260–265, 2004.
[7]. A Bayesian Algorithm for Reading 1D Barcodes; Ender
Tekin, James Coughlan, The Smith-Kettlewell Eye
Research Institute
5
[8]. Reading Challenging Barcodes with Cameras, Orazio
Gallo and Roberto Manduchi, University of California,
Santa Cruz
[9]. R. Adelmann, M. Langheinrich, C. Fl¨orkemeier:
Toolkit for Bar Code Recognition and Resolving
on Camera Phones – Jump Starting the Internet of
Things. Workshop on Mobile and Embedded Interactive
Systems (MEIS’06) at Informatik, GI LNI,
2006.
[10]. D. Chai, F. Hock: Locating and Decoding EAN-13
Barcodes from Images Captured by Digital Cameras.
5th Int. Conf. on Information, Communications
and Signal Processing, 1595–1599, 2005.
[11]. E. Joseph, T. Pavlidis: Bar Code Waveform Recognition
Using Peak Locations. IEEE Trans. on
PAMI, 16(6):630–640, 1998.
[12]. http://www.morovia.com/education/symbology/upc-a.asp
[13]. http://www.morovia.com/education/utility/upc-ean.asp
[14]. en.wikipedia.org
[15]. http://www.google.com/imghp