REAL-TIME BARCODE READER USING PERSONAL DIGITAL ASSISTANCE (PDA) OSAMA SALEM ELSHERAIRI A project report submitted in partial fulfillment of the requirements for the award of the degree of Master Engineering (Electrical-Electronics & Telecommunication) Faculty of Electrical Engineering Universiti Teknologi Malaysia MAY 2007 iii In the name of Allah, Most Gracious, Most Merciful All praise and thanks are due to Allah Almighty and peace and blessings be upon His Messenger The results of this effort are truly dedicated to my mother and father whose example as devoted professionals, as well as, parents taught me to be perseverant, responsible and loyal to my belief. To my brothers, and sisters, and my best friend my uncle for all their support, encouragement, sacrifice, and especially for their love. Thank you all and this work is for YOU. iv ACKNOWLEDGEMENTS First and foremost, I thank Allah for giving me the strength to complete my project. I would like to thank especially supervisor ASSOC. PROF. DR. SYED ABD RAHMAN AL-ATTAS for his constant support and guidance during my graduate studies at Universiti Teknologi Malaysia. I would also like to convey my deepest gratitude to Mr. Usman Ullah Sheikh for his guidance to complete this research. Thanks to all my colleagues and friends with whom I had the opportunity to learn, and share a good time during my stay here. Finally, special and infinite thanks goes to the most important people in my life; my parents, for their love, prayers, sacrifice and support. v ABSTRACT This project concerns the design and implementation of a system for real time barcode reader using personal digital assistant (PDA) with built-in camera. A system that reads and decodes (1D) linear barcodes based on images containing barcodes – independent of the barcodes' orientation or rotation. Problems associated with images taken by the PDA are limited depth of field, limited resolution, poor lighting sensitively and camera shake. To accomplish this project with the above constraints the following stages are undertaken; First the image from the camera is enhanced, the camera will send continuous frame of images from the environment. These images are converted to grayscale and some preprocesses are performed, image is filtered (such as sharpening and noise reduction) and converted to binary. The image is then scanned horizontally, vertically and diagonally for barcodes, thus enabling it to detect rotated barcodes to suit the subsequent processing. Then the barcode is located in the image using a method based on the evaluation of the correlation. To extract relevant information from the located image the barcode is then isolated from the image, after that it is used to gain a waveform that represents the information of the barcode. Finally, the waveform will be wavered into a string of digits representing the widths of each bars of the barcode. At this stage the processing has completely decoded the barcode symbology. This project only considers European Article Number 13, (EAN-13) barcodes. The system has been implemented in Windows Mobile (windows CE) based software in Embedded Visual Studio 2005 C++ on PDA, with a graphical user interface. Error correction and predictive decoding is implemented to improve the capability accuracy and performance of the system. vi ABSTRAK Projek ini berkenaan dengan reka-bentuk dan implementasi sistem kod-bar maya nyata menggunakan pembantu peribadi digit (PDA) yang dilengkapi dengan kamera terbina-dalam. Sistem ini mampu membaca dan menyahkod kod-bar satu dimensi tanpa mengambil kira orientasi dan pusingan kod-bar. Kedalaman medan yang terbatas, resolusi yang terhad, pencahayaan yang lemah dan goncangan kamera adalah beberapa masalah yang berkaitan dengan imej-imej yang dihasilkan oleh kamera PDA. Untuk melaksanakan projek yang mempunyai masalah diatas dengan jayanya, proses-proses berikut perlu dilakukan. Pertama, kualiti imej ditingkatkan. Imej-imej ini kemudiannya ditukar kepada imej aras kelabu dan beberapa peringkat pra-pemprosesan dilakukan seperti penajaman dan pengurangan hingar, dan imej ditukar ke nombor binary. Untuk mendapatkan kodbar, imej kemudiannya diimbas secara menegak, melintang, dan pepenjuru untuk menentukan proses yang selanjutnya. Dengan menggunakan kaedah penilaian korelasi, kodbar diletakkan didalam imej. Untuk mengekstrak maklumat darapida imej. Kodbar kemudiannya diasingkan daripada imej, dan digunakan untuk mendapat bentuk gelombang yang mewakili kodbar. Akhir sekali, bentuk gelombang diliang-liuk menjadi rangkaian digit yang mewakili lebar setiap buku kodbar. Pada peringkat ini, kodbar telah dinnyahkod sama-sekali. Projek ini hanya mengambil kira kodbar jenis nombor artikel Eropah (EAN-13). Sistem ini diatas diimplementasi di dalam persekitaran Windows Mobile (Windows CE) dengan menggunakan Embedded Visual Studio 2005 C++ untuk PDA dengan antara muka grafik. Pembetulan kesalahan dann penyahkid penjangkaan dilaksankan untuk meningkatkan ketepatan dan pencapaian sistem. vii LIST OF CONTENTS CHAPTERS CHAPTER 1 TITAL PAGE DECLARATION ii DEDICATION iii ACKNOWLEDGEMENTS iv ABSTRACT v ABSTRAK vi TABLE OF CONTENTS vii LIST OF TABLES xi LIST OF FIGURES xii LIST OF ABBREVIATIONS xv LIST OF APPENDICES xvii INTRODUCTION 1 1.1 Overview 1 1.2 Personal Digital Assistant (PDA) 2 1.2.1 Pocket PC 3 1.3 Plam 4 1.4 Smartphones 4 1.5 Camera used with PDA 5 1.6 Windows Mobile 5 1.7 PDA using a camera 6 1.8 Limitation of conventional barcode readers 7 viii CHAPTER 2 1.9 Objective of Project 8 1.10 Scope of Project 8 1.11 Project outline 8 LITERATURE REVIEW 10 2.1 Introduction 10 2.2 A bit of history 11 2.3 Types of Barcodes 11 2.3.1 One Dimensional barcodes 12 2.3.2 Two - Dimensional barcodes 13 2.4 2.5 2.6 CHAPTER 3 The Physical Reader 13 2.4.1 Input Device 14 2.4.2 Decoder 18 2.4.3 Barcode Reading 19 The Barcode Recognition System 21 2.5.1 EAN-13 Barcode Image Recognition 21 2.5.2 Barcode symbologies 21 2.5.3 Barcode Size and Color 22 Encoding Rule of Structure of an EAN barcode 23 2.6.1 The X-dimension 24 2.6.2 Quiet zone 24 2.6.3 Guard bars 25 2.6.4 Right & left hand side digits 26 2.6.5 How to calculate the checksum 27 2.6.6 Encoding 28 2.6.7 Decoding 31 METHODOLOGY 32 3.1 Introduction 32 3.2 Barcode Image Devices 33 ix 3.3 Image Capturing 33 3.4 Barcode processing in PDA 34 3.4.1 35 Searching for barcode image automatically 3.4.2 Identification of the Bars and Spaces 36 3.4.3 Estimating How Correctly the Elements 36 Have Been Identified 3.4.4 3.5 Decoding the Barcode 37 Pre-Processing 38 3.5.1 39 The RGB color model 3.5.2 Gray scaling 40 3.5.3 41 Image Enhancement 3.6 Scanning Direction 42 3.7 Barcode Identification & Extraction 44 3.8 Program Architecture 45 3.8.1 45 Overview of Programming Languages Used For PDA 3.8.2 3.9 CHAPTER 4 Program Build on PDA 46 Program screenshot 46 3.9.1 Program interface 47 3.9.2 Using the HP Photosmart Mobile Camera 48 RESULT 50 4.1 Introduction 50 4.2 Uneven Resolution, Shadow, Shake and 50 Illumination 4.3 Tests of Barcode Orientation 51 4.3.1 52 Computing the orientation of the barcode 4.4 Show scan diagonal read rotated barcode (offline) 53 4.5 Show scan horizontal read rotated (offline) 54 4.6 Show scan vertical read rotated barcode (offline) 54 x 4.7 Show scan horizontal read rotated barcode 55 (online) 4.8 Time Consumption 56 4.9 Performance Comparison 56 CHAPTER 5 CONCLUSION 58 5.1 Conclusion 58 5.2 Recommendations for Future Work 58 REFERENCE 59 APPENDIX 63 xi LIST OF TABLES TABLE TITAL PAGE 2.1 Specification for EAN-13 barcode 22 2.2 Total number of bars and modules for EAN-13 barcode 28 2.3 The list of oriented-modules on logic of 0-9 for A, B, C, 29 types 2.4 Result for example 30 3.1 Normal barcode (left to right) 37 3.2 Flipped or mirrored barcode 38 3.3 These are classes used in program 46 xii LIST OF FIGURES Figure TITAL PAGE 1.1 Symbol barcode 2 1.2 HP iPAQ hx4700 Pocket PC 3 1.3 Palm 4 1.4 Smartphone 4 1.5 Digital camera card (HP Photosmart mobile camera) 5 1.6 Different devices used windows CE 6 1.7 Interfaces for windows CE 6 1.8 PDA build-in camera 7 2.1 A scheme of a bar code reading system 10 2.2 Numeric barcode, 1D 12 2.3 Alphanumeric barcode, 1D 13 2.4 Some types of barcode, 2D 13 2.5 Reader (a), Laser scanner, (b) CCD scanner, (c) CCD 15 sensor by a lens. 2.6 Pen-Type readers 15 2.7 Some cameras can used to read barcode 16 2.8 These are some digital camera card (Photosmart mobile 16 camera) 2.9 The barcode reader with PDA in the shopping 17 2.10 Barcode EAN-13 21 2.11 (a) equivalent EAN-13 barcode, with the first character 22 set to zero, and (b) an EAN-13 with an additional digit used, with the first character set to not zero xiii 2.12 X-dimension barcode 23 2.13 Barcode Structure 24 2.14 Actual size of EAN-13 25 2.15 EAN-13, left and right hand 29 2.16 Barcode EAN-13 Parity Encoding 30 3.1 Architectural Overview: Our EAN-13 barcode and 33 resolution system consists of a PDA using camera and load from file application for decodes barcode 3.2 There are some progress used to read barcode 33 3.3 Image processing in PDA 34 3.4 Some symbols barcode image 35 3.5 Schematic of the RGB color cube 39 3.6 Illustrating difference between a general RGB color 40 image and a general gray scale image. 3.7 Original gray-scale image 40 3.8 A 3x3 window, for use in a windowing function, where 42 the z-values corresponds to the gray-scale values of the original image 3.9 Spatial filters (a) Gaussian Blur, (b) Laplacian (c) 42 Sharpen (d) Unsharpen Mask 3.10 Scan 4 directions implemented 43 3.11 These are some direction of a barcode at different angles, 43 (a) Horizontal (b). Vertical (c) Diagonal (d) invest horizontal 3.12 Illustrating how the barcode's angle µ is derived using the 44 vector displacement, k, the distance d between two vectors, and basic trigonometry. 3.13 Steps to identify and extract the EAN-13 barcodes 44 3.14 program interface 47 3.15 Getting Acquainted 48 xiv 4.1 These are some samples for barcodes image are not clear, 51 all of them (uneven resolution and shake) 4.2 Some types of barcode all of them very clear 51 4.3 Some types of barcode all of them not clear 51 4.4 Shows the output from the localization algorithm. Angle 52 α is the angle of the bar code. The angle is also given by 90 - β 4.5 Rotation 53 4.6 Diagonal (+45, - 45), (a) scan consume operation 53 93ms,(b) scan consume 1482ms, (c) scan consume operation 617ms 4.7 Horizontal, (a) scan consume operation 531ms,(b) scan 54 consume 492ms, (c) scan consume operation 462ms 4.8 Vertical, (a) scan consume operation 435ms,(b) scan 55 consume 336ms, (c) scan consume operation 515ms 4.9 some tests from camera (online), (a) scan consume 55 operation 203ms,(b) scan consume 270ms, (c) scan consume operation 272ms 4.10 compare consume operation 57 xv LIST OF ABREVIATIONS PDA - Personal Digital Assistants GPS - Global Positioning System PC - Personal computer MS - Microsoft RAM - Random access memory CPU - Central processing unit GSM - Gold Standard Multimedia GPRS - General Packet Radio Service CDMA - Code division multiple access WCDMA - Wideband Code Division Multiple Access 3G - 3-Generation SD - Secure Digital MP - Micro Pixel D - One- or Two- Dimensional BMP - Windows Bitmap EAN - European Article Number UPC - Universal Product Code CCD - Charge-Coupled Devices PSA - Personal Shopping Assistant PIM - personal information manager JPEG - Joint Photographic Experts Group RGB - Red, Green and Blue SD - Secure Digital SDIO - Secure Digital Input/Output SDK - Software Development Kit xvi PCB - Printed Circuit Boards CD - Compact Disc; conjugate directions GSM - Groups :Special Mobile or Global System for Mobile SMS - Simplex Minimization Search xvii LIST OF APPENDICES APPENDIX TITAL PAGE A Camera SDIO SDK Specification 63 B Visual Studio 2005 C++ CLASS DECLARATION 70 C Some Types of digital camera card 75 D SOME BARCODE IMAGE ARE VERY CLEAR 79 E SCREENSHOTS OF COMMERCIAL TEST 80 PROGRAMS F Number System (number of countries) 82 CHAPTER 1 INTRODUCTION 1.1 Overview Today barcodes are present all around us not only for use on groceries in the super-market, but also in industries for example in a car assembly plant most the car parts are marked with barcodes for identification purposes. Similarly, and for the same reasons, most electronic circuits and microchips have barcodes on them. Why is that? Why are barcodes used? The main reason is the convenience and effectiveness barcodes provide since they are designed for automated reading and interpretation. Leading to a rationalization when a machine does the job instead of a human operator. Further, a product can be given a fix barcode, only linking the barcode’s number to a database containing attributes such as price, manufacturing date, adjacent bars and spaces etcetera. Hence, attributes can easily be changed in the database, without actually relabeling the product. Barcodes are standardized, as shown in figure 1.1, which leads to that they are consistently shaped and used, and that they have a well defined structure wherever they are found. They provide unambiguous, and secure, identification. Some barcode symbologies also offer a feature for tracing for example the origin of a product. As 2 barcodes are wide-spread over the world there has naturally evolved many different ways to read them – using for example laser scanners, so called wands, CCDscanners, or digital cameras. If it could be possible to use personal digital assistant (PDA) build in camera to read barcodes image much could be gained. Naturally, the first advantage compared to, for example, a laser scanner is that the object with the barcode is visible in the image, and thus that the operator can see whether the object is for example intact or damaged, which means that the system easily could be expanded with additional cameras. This is due to the fact that the PDA using a camera downloads the images with ease could be connected to the network via the internet such as the World Wide Web. Figure 1.1: symbol barcode 1.2 Personal Digital Assistants (PDA) A personal digital assistant (PDA) is a handheld device technology that can implements various new kinds of applications such as telephone/fax, internet, GPS, movie and network features. A typical PDA can function as a cellular phone, fax sender, Web browser and personal organizer. Unlike portable computers, most PDA’s began as pen-based, using a stylus rather than a keyboard for input. This means that they are also integrated with handwriting recognition features. Some PDA’s can also react to voice input by using voice recognition technologies. PDA’s of today are available in either a stylus or keyboard version. 3 1.2.1 Pocket PC This project will use Pocket PC (HP iPAQ hx4700 series as shown in Figure 1.3). The main reason for choosing Pocket PC rather than Palm is that Pocket PC is a handheld computer with a subset of the capabilities of a PC and provides the basic functionality those users need when they are traveling. Pocket PC also has a longer battery life than a notebook PC, therefore, offers 320 x 240 color display or more, moreover it can use touch screen for data entry. The pocket PC uses a cable serial & USB sync port to connect with PC or other devices. It is an available compact flash and/or Secure Digital (SD) Card for secondary storage. The pocket PC is better than palm because the palm is just an organizer but the Pocket PC is a small computer that uses a windows interface which is already user-friendly. The Pocket PCs are more popular and used by many people because it can use Microsoft Word, Excel, and Outlook. The Pocket PC uses high resolution color screens. Pocket PCs come with mobile versions of office applications in addition to Microsoft Outlook Mobile. Though there are different Pocket PCs, all of them can compose e-mail messages and send them by synchronizing with desktop computer or wirelessly. Figure 1.2: HP iPAQ hx4700 Pocket PC 4 1.3 Palm The palm has some applications with an easy to use interface, as shown in figure 1.3 Figure 1.3: Palm 1.4 Smartphones Mobile phones use Windows Mobile or Symbian as operating system developed by the Palm Company. The smartphone is different with PDA’s, as shown in figure 1.4. Figure 1.4: Smartphone 5 Therefore, the smartphone has something like a PDA (storage on flash, multimedia features, pocket outlook, pocket internet explorer, GSM/GPRS, CDMA, WCDMA, 3G Radio, SD Card. 1.5 Camera used with PDA There are many kinds of camera for PDA. They include; built–in camera, wireless camera and digital card camera. The recent models of smartphone’s and PDA’s have built-in camera, as shown in figure 1.5, which is digital camera card that can be used in a PDA’s and other dives. Figure 1.5: Digital camera card (HP Photosmart mobile camera) 1.6 Windows Mobile Microsoft recently announced Windows Mobile operating system, which is a handheld device powered by the Windows Mobile platform. It allows the user to make phone calls, retrieve e-mails, browse the Internet, send and receive text messages, read and compose Microsoft Word Mobile files, make Microsoft Excel Mobile charts, and view Microsoft PowerPoint presentations. Windows Mobile powered devices come in three types and includes: Pocket PC, Pocket PC Phone Edition, and Smartphone, as Shown Figure 1.6 6 Figure 1.6: Different devices that use windows CE Windows CE (WCE) is a Windows like operating system for various handheld devices, including Personal Digital Assistants (PDA’s) and Mobile Phones. While at the API level, many of the function calls and interfaces are the same as the standard version of Windows as shown in figure 1.7, much of the internals have been altered to accommodate many different types of CPUs and architectures. Figure 1.7: Interfaces for windows CE 1.7 PDA using a camera The system architecture of PDA using a camera is a recent generation of PDA devices, as shown in figure 1.8 7 Figure 1.8: PDA build-in camera This project can perform either in real-time (online) or load from a file (offline). The application revolution has been made possible by the added extra processor called an application processor into the newer PDA's. The software used is Embedded Visual Studio 2005 C++ and the hardware system processing will be done in real-time by PDA using camera. See figure 1.8, PDA with camera. 1.8 Limitations of Conventional Barcode Readers In real time (online) phase, the capturing of barcodes image depends on the following: a) Resolution of the camera, for build-in camera in real time, the resolution of the camera must be more than 3.0 MP. b) Light intensity is very important to camera. c) Camera stationary using a camera that is shaking will could the barcode image to be blurred (that mean the bars are not clear.). 8 1.9 Objective of Project The main objective of this project is to develop a system comprising of a PDA using camera and software for the purpose of capturing 1-D barcodes and decoding them in real-time (online) as well as offline (reading from a file). Suitable image processing techniques must be implemented in the software to accommodate inaccuracies or environmental changes during the acquiring process. 1.10 Scope of Project The project is mainly to develop a Windows Mobile (windows CE) based software in Embedded Visual Studio 2005 C++, which is to be run on HP Ipaq hx 4700 series PDA. a. The program obtains images barcode from offline windows bitmap (BMP) files or in real-time from a camera that is either attached or built in the PDA. b. The image barcode is obtained from a camera that is either attached or built in the PDA. c. Barcode symbologies that will be considered in the project will be mainly the EAN -13 (Very common in consumer products). 1.11 Project Outline This project is organized into five chapters. The outline is as follows; Chapter 1-Introduction This chapter discusses the objectives and scope of the project and gives a general introduction to barcode technology. 9 Chapter 2-Review of Literature Studies This chapter reviews the relevant literature and previous work regarding PDA using camera barcode readers. In addition to that, explain of EAN-13 symbologies are given. Chapter 3- Methodology This chapter elaborates on the principles behind good quality image acquisition and the factors that must be taken into consideration to obtain readable barcodes. This includes camera selection, determination of field of view, resolution, light intensity and shake. The algorithms to initiate barcode detection and decoding are also described and justified in this chapter. Chapter 4-Result The final results of this project are shown in this chapter. Chapter 5-Conclusion This chapter consists of the conclusion and future improvement. CHAPTER 2 LITRATURE REVIEW 2.1 Introduction There is quite a number of research works carried out on barcode reading and localization using camera. Findings of these works are described in this chapter. This chapter will also present an explanation of the barcode EAN-13 symbologies. Barcodes are information carrying graphical patterns designed for easy and reliable automatic retrieval. The most common barcodes are known as onedimensional barcodes. These graphical patterns in a single dimension (e.g. horizontal), and are constant in the other (vertical) dimension and diagonal dimension. In order to convey more information on the same surface area, the constancy in the vertical dimension has to be abandoned for more intricate patterns, known as two-dimensional barcodes. Barcode reader is to extract the optical information in a symbol from bars and spaces into computer-compatible data. The data can either be transmitted directly. A general scheme for a bar code reading system is shown in figure 2.1. Online or Offline Processor Decoder Figure 2.1: A scheme of a barcode reading system Code Barcode 11 2.2 A bit of history for Barcode Beginning with 1932, when an ambitious project was conducted by a small group of students headed by Wallace Flint at the Harvard University Graduate School of Business Administration. The project proposed that customers select desired merchandise from a catalog by removing corresponding punched cards from the catalog. Barcode was first used commercially in 1966, however, it was soon realized that there would have to be some sort of industry standard set. [3] By 1970, the Universal Grocery Products Identification Code or UGPIC was written by a company called Logion Inc. The first company to produce barcode equipment for retail trade use (using UGPIC) was the American company Monarch Marking in 1970, and for industrial use, the British company Plessey Telecommunications was also first in 1970. UGPIC evolved into the U.P.C. symbol set or Universal Product Code, which is still used in the United States. George J. Laurer is considered the inventor of U.P.C. or Uniform Product Code, which was invented in 1973. In June of 1974, the first U.P.C. scanner was installed at a Marsh's supermarket in Troy, Ohio. The first product to have a barcode included was a packet of Wrigley's. 2.3 Types of Barcodes To understand the contents of barcodes or be able to produce own barcodes one has to understand the barcode symbology. The symbology is very much a like a language defining how different combinations of various wide bars and spaces shall be interpreted. There are many different barcode symbologies, one- dimensional or two-dimensional, fixed-width or multi-width, each with various properties such as data density or type of data stored, all designed to fulfill a specific purpose [1, 2]. The symbology also defines properties such as: • Quiet Zone, a quiet area around the barcode to avoid interference with surrounding textures. 12 • Start and Stop Patterns, speeds up the localization of the barcode. • Aspect Ratio, defines the relations between width and height of the whole symbol and the different widths of bars and spaces. • Parity and Redundancy, ensures a low error rate and enables damaged barcodes to be read. Bar code systems can use several symbologies. A symbology is equivalent to a language. Each symbology has strengths and weaknesses. Many symbologies are around for historical or political reasons, while others have definite technical advantages. 2.3.1 One Dimensional barcodes It is employed in low information content applications like product index registry (e.g. automatic price tagging and inventory management), or serial number registry (e.g. test-tube tagging in automated medical tests). Two-dimensional barcodes are used in applications that require more information contents like mail addresses (for automated mail reading and distribution systems), or compressed content of a printed page (to avoid the need for optical character recognition), as shown in figure 2.2 and figure 2.3. a. Numeric-only barcodes EAN-13 EAN-8 UPC-A Figure 2.2: Numeric barcode UPC-E 13 b. Alphanumeric barcodes Code-39 code-93 code-128 Figure 2.3: Alphanumeric barcode 2.3.2 Two - Dimensional barcodes It is graphical patterns composed usually of dots. They are rendered using two-toned dots (e.g. black dots on a white background), and occupy, usually a rectangular area. Two-dimensional barcodes incorporate various registration and fiducially marks, enabling automated identification, and accurate registration of the barcode, which might be read-in in arbitrary orientations. In addition, two dimensional barcode systems employ various error correcting codes for reliable automated retrieval, as shown in figure 2.4. PDF 417 DataMatrix Maxicode QR code Figure 2.4: Some types of barcode, 2D 2.4 The Physical Reader A physical barcode reader is considered to contain two separate elements: the input device and the decoder [3]. These two elements can either be separated into two different physical units or they can both be in one single unit. The input device 14 includes the electro-optical system and the camera system, while the decoder equals the processor. 2.4.1 Input Device There are different ways to read a barcode: by a scanner, using a wand or a vision-based `device [2]. All these devices share a common structure in how the reading process is performed. The user either holds the reader over the barcode or holds the barcode image in front of the reader. All approaches scan a line across the barcode and measure the intensity along the scan line. High intensity corresponds to a bar and low intensity corresponds to a space. If the scan line does not cross the entire bar code, the code will not be read. Then, another line must be scanned such that the barcode is converted. The user has to ensure that the scan line is in the right direction and that it covers the entire bar code [1]. a. Scanner A scanner is usually a handheld device and is often used in the retail industry. In some cases, the scanner is stationary and the user places the barcode in front of the beam, like in the supermarket [1, 2], as shown in figure 2.5. The scanner either moves the beam over the code by itself or the user has to move the beam over the barcode. In the second case, the user has to be able to move his hand with some skill. The handheld device must stay at the same distance from the barcode while the beam is moved over the code. A scanner does not have contact with the barcode. A handheld, moving beam scanner has a large advantage over a fixed beam scanner. It can scan with a much higher frequency, up to 40 scans per second, and almost no operator skill is required. There is another type of handheld scanner that uses a raster laser scan pattern to read 2D symbols. 15 (a) (b) (c) Figure 2.5: Reader (a). Laser scanner, (b) CCD scanner, (c) CCD sensor by a lens. b. Wand A wand is a handheld device with a fixed beam that physically touches the barcode is shown figure 2.6. The reading device of the wand is in the tip and the wand looks like a pen that is moved over the barcode. The user has to provide the moving motion of the beam, and therefore, some operator skill is required to use a wand. The hardest thing is to move the wand at the right speed and to not make too high accelerations [1, 3]. Figure 2.6: Pen-Type readers, c. Vision-Based Scanning Vision-based scanners use a camera to read the barcode, as shown figure 2.7. An image is taken over the barcode area and is then analyzed so that the code can be decoded. This technique has an advantage over the others when reading 2Dsymbols. It is not as fast but more accurate and thus better to use in some applications, than the other two techniques. The performance and symbols available for decoding have been evaluated [3]. 16 Figure 2.7: Some cameras can used to read barcode However, there are many kinds of a camera using with other devices. There are built–in cameras, wireless camera and digital card camera, as shown Figure 2.8 The most of modern smartphone’s and PDA’s have built-in camera. This the camera usually used with PDA to take a picture, video, etc. Figure 2.8: These are some digital camera card (Photosmart mobile camera) Wesley Chan [9], Project Voyager builds applications that link virtual services to people, places, and things see figure 2.9. This is describes the design and implementation of two such systems. The MIT Campus Guide application provides services for specific points of interests. Campus visitors used the system to interact with different sites, for example, a restaurant, a lecture hall, or a sculpture. The Voyager Personal Shopping Assistant (PSA) connects shoppers in a supermarket to 17 virtual services, linked to specific products. Customers used handheld computers to scan products. The system retrieved relevant information from the Internet about each item, including recipes, nutritional information, and related product recommendations. Project Voyager successfully deployed both systems and conducted informal user trials. Figure 2.9: The barcode reader with PDA in the shopping Peter Sundström [3]. Barcode Reader for Surface Mounting Systems This is describes a method for reading barcodes with a camera that has a field of view that is smaller than the size of the barcode. The method analyzes partial barcode images. From these images the barcode area is located and decoded. Using partial images when reading barcodes is quite unique. The method reads the barcode EAN13 in two steps. In the first step the partial barcode images are analyzed and a region of interest is detected. The partial barcode images are then merged to one large image with one region of interest. The barcode area is located by finding regions that have a high concentration of mono-oriented gradients. In the second step, an average of lines is scanned across the region of interest of the bar code. A waveform is produced that has ridges and valleys. Ridges correspond to bars and valleys correspond to spaces in the barcode. The width of the bars and spaces are classified and decoded so that the bar code data can be extracted. Both code 128 and code 39 can be decoded. The developed method has been tested on a set of bar code images. From a test set of 13 undamaged bar codes all were decoded correctly but from a test set of 11 damaged 18 bar codes 50 % were decoded correctly. The bar code area is correctly located in 90 % of all the partial bar code images. 2.4.2 Decoder As mentioned before, the decoder analyzes the signal from the input device and deciphers the information encoded in the barcode. The data is either transmitted to an attached PDA, stored locally for later transfer, or forwarded to an application program in the decoder itself. All decoders have a system that decodes the encoded symbols information to understandable data. This system is usually implemented in software on a microprocessor, but it might also be implemented in hardware. There are some basic steps included in all decoders [2]: 1. Measure the width of each element or the edge-to-similar-edge distance, depending on the symbol. Only for CCD input devices the actual distance is measured. Instead, the decoder measures the time the signal spends in an element. 2. Quantize the element widths to fit the symbol description. This is hard if the input device does not have a moving beam. 3. Decode the quantized element characters to readable data. This is done via a look-up table. 4. If necessary, reverse the order of the decoded data characters to accommodate symbols that have been scanned in the wrong direction. 5. Perform additional checks to confirm the validity of the scan. Such as: quiet zone size,check character... 6. Transmit the decoded data. 19 2.4.3 Barcode Reading Usman Ullah Sheikh [1], real-time barcode reader using Active vision. This is to decode the UPC-A and EAN-13 barcodes using an active vision system, consisting of a camera and user-written software. The camera will feed the software with continuous frames of images from the environment. These images are converted to grayscale and some preprocessing is performed. Image is filtered (such as sharpening and noise reduction) and converted to binary. An adaptive thresholding algorithm is used to reduce the effects of uneven illumination. Image is then scanned horizontally, vertically and diagonally for barcodes, thus enabling it to decode rotated barcodes.Error correction and predictive decoding is implemented to improve the speed and accuracy of the system. Overall system performance is benchmarked with existing commercially available software. Johan Bylund, Fredrik Jirhede [2],Visual Barcode Reading, the design and implementation of a system for visual barcode reading, using a network camera A system that reads and decodes linear barcodes based on images containing barcodes – independently of the barcodes' orientation or rotation. To accomplish this method based on various image and signal processing was developed, consisting of the following main stages. First the image from the camera was enhanced, using Sobel filters, to suit the succeeding processing. Then the barcode was located in the image using a method based on the evaluation of the correlation between small parts of the image. To extract relevant information from the located image the barcode was then isolated in the image. After that the Hough transform was used to gain a waveform representing the information of the barcode. The waveform was then subjected to various processing resulting in a string of digits representing the width's of the elements of the barcode. To this stage the processing has been completely barcode symbology independent, which implicates that many symbologies could be included parallelly in the succeeding stage. However, of practical reasons only EAN-13 barcodes were considered in the final decoding stage; where symbology specific information was used to normalize the informa- tion, decode the information, and validate the result using a checksum. The system was implemented in C on a PC running Linux, with a graphical user interface written C++. The all over performance was good, and all predefined objectives were met to full satisfaction. Key-words: 20 Barcode decoding, barcode symbologies, network camera, image processing, image enhancement, Sobel operator, barcode localization, pattern recognition, feature extraction, Hough transform. Douglas Chai and Florian Hock [13], Locating and Decoding EAN-13 Barcodes from Images Captured. Digital Cameras by a vision-based technique to locate and decode EAN-13 barcodes from images captured by digital cameras. The ultimate aim of our approach is to enable electronic devices with cameras such as mobile phones and Personal Digital Assistants (PDAs) to act as a barcode reader. Yasser Ebrahim, Wegdan Abdelsalam, Maher Ahmed, Siu-Cheung Chau, Proposed a Hybrid Tag-Camera-Based Identification and Navigation Aid for the Visually Impaired, a barcode-based system to help the visually impaired to identify objects in the environment and navigate through unknown territories is introduced. The system is based on the idea of tagging the different objects with 2D barcodes, with the aid of a portable camera and a computing device. The system can recognize and relay the barcode content to the user. The advantages of the proposed system compared to those of existing technologies. This paper addresses the self-localization problem from a pragmatically point of view since it argues for using passive artificial landmarks in order to support mobile robot localization in indoor environments. The idea is to further improve already existing localization capabilities by providing relevant environmental spots with semantic information. In order to facilitate the detection of these landmarks the employment of bar codes is proposed. Experimental results concerning the detection and identification of barcode labels by means of vision have been presented [24]. The BCReader is a new product for smartphones that gives possibility to decode barcodes from snapshots made by onboard camera. Simply make photo of barcode on selected thing and save received data in phone’s database for further processing. For each barcode BCReader can save title name, price and description. The BCReader allows searching necessary goods and comparing their prices in different stores to make best choice [27]. 21 2.5 THE BARCODE RECOGNITION SYSTEM 2.5.1 EAN-13 Barcode Image Recognition The European Article Numbering system (EAN) is by far the most popular barcode used in the retail industry. It’s available on almost all consumer products. While the EAN code format was adopted 3 years later. There are several versions EAN-13 barcodes, such as EAN-13 (13 digits).While EAN-13 is the equivalent for the European market. Thus, the structure and size are the same. The EAN-13 encodes 12 digits of numeric message and one check digit to form a 13 digit barcode. The check digit is not a part of the data, but merely for error checking [3]. Figure 2.10: Barcode EAN-13 2.5.2 Barcode symbologies Barcodes are like a printed version of the most code. Different bar and space patterns are used to represent different characters. Sets of these patterns are grouped together to form a "symbology". There are many types of barcode symbologies each having their own special characteristics and features. Most symbologies were designed to meet the needs of a specific application or industry. However, for the EAN-13 symbology, the data is encoded differently, where the first two digits represents the country of origin. The last digit is still the check digit, while the remaining digits are composed of manufacturer’s number and product’s number. There are differences between these two symbologies. The EAN-13 barcode when the first character is set to 0. Visually looking at the bars of Figure 2.11.a and Figure 2.11 b, both barcodes are identical. In other words, a digit EAN-13, if the first 22 digit is set to 0. EAN-13 “0-XXXXXX-XXXXXX”. Both barcodes are made of left and right-hand character sets. The EAN-13 encodes a 13th digit into the parity pattern of the left six digits symbol (EAN-13 = Data Structure + Symbology) [1]. (‘0’+11+1 Characters) (12+1 Characters) Symbology L R L R Data Structure (a) (b) Figure 2.11: (a) equivalent EAN-13 barcode, with the first character set to zero, and (b) an EAN-13 with an additional digit used, with the first character set to not zero 2.5.3 Barcode Size and Color The size in an EAN-13 barcode is at three different magnifications. Barcodes can be a scaled to a minimum of 80% of the standard dimension, and up to 200% [1]. The complete specification is given in table 2.1. Table 2.1: Specification for EAN-13 barcode 29.83 mm x 20.73 mm Minimum size 74.58 mm x 51.82 mm Maximum size 37.29 mm x 25.91 mm Nominal dimensions 0.330 mm X-dimension at normal size 80% to 200% from normal dimension Magnification factor Left 3.63 mm (11x), Right 2.31 mm Quiet Zone (7x) Top &Bottom 0.33 (1x) 22.85 mm at nominal size Bar height Rear lower right quadrant Target location 23 2.6 Encoding Rule of Structure of an EAN barcode The EAN-13 standard, consist of a number of printed bars with intervening spaces. The characters within the symbology are encoded in a pattern with various sizes of narrow and wide, bars and spaces. There are two different types of a barcode depending on where it is marked. The first type is recognized as "source marking". The barcode of this type is marked on the product during manufacturing process. The second type is a recognized as "in-store marking". Products of this kind are only sold in some particular stores. It is extensively used by most of the commercial products. There are total of 13 digits in an EAN-13 code. The center pattern and the guard pattern consist of auxiliary characters, see figure below. Figure 2.12: Barcode Structure In this standard, each digit is composed of 7 modules. The center pattern and the guard pattern contain 5 modules and 3 modules, respectively. The first three digits of an EAN-13 code are country prefix, see figure 2.12. They are used to identify the nationality of the organization issuing the barcodes. Their four successive digits represent the manufacturer number. Then, the five successive digits represent the specific product item number. The last digit of an EAN-13 code is a check digit. In this standard, a code consists of 7 modules. Different combinations of 011 will represent different numbers under this format. There are total of three 24 encoding rules for the so-called A, B, C types. Based on these encoding rules, we can decode a bar code into its corresponding digits easily. In the EAN-13 standard, the selection of encoding rule totally depends on the first digit of the country prefix. The whole barcode is made of predefined standard elements [3]. 2.6.1 The X-dimension The X-dimension or module is the width of the narrowest bars or spaces in the barcode [27-28]. The width of the other bars or spaces is two, three or four times the size of X-dimension, see figure below. The X-dimension is 264μm, 330μm and 660μm for a barcode scaled at 80%, 100% and 200% respectively. The X-dimension and the width of the thickest bar cannot be more than four times the width of Xdimension. Any barcode will be divided to a spatial, then, each spatial has two bars (black is present (zero)) and two spaces (white is present (one)), after that, it will be divided to 7-dimension, then, it will get a digital numbers from it [1]. Figure2.13 : X-dimension barcode 2.6.2 Quiet zone Quiet zones are the areas to each side of the code that must be kept clear. The blank areas are before/after the barcode [1, 3, 28]. It is measured in terms of “n” times the narrowest bar size (X-dimension). The quiet zones for an EAN-13 barcode 25 are 11 modules on the left hand side (Figure 2.14(1)), 7 modules on the right hand side (Figure 2.14(2)), and 1 module thickness each at the top and bottom of the barcode (Figure 2.14(3), Figure 2.14(4)). The end of the barcode on the right hand side is usually marked with an indicator ‘>’, indicating the end of quiet zone (Figure 2.14(11)). 2.6.3 Guard bars A guard pattern is placed on the right, at the center and on the left of the barcode. This pattern is required so that the reader can identify the starting point of a particular barcode (Figure 2.14(5), Figure 2.14(7), Figure 2.14 shows) the starting and ending guard bars in the order of Black-White-Black (3 bars, each 1 module thick). A centre guard is placed in the middle of the barcode. The centre guard has the same convention as the side guards. Figure 2.14(7), the center guard bars in the order of White-Black- White-Black-White (5 bars, each 1 module thick). Figure 2.14: Actual size of EAN-13 26 2.6.4 Right & left hand side digits It consists of four areas; normally the number system digit is printed to the left of the barcode, and the check digit to the right. The manufacturer and product codes are printed just below the barcode, separated by the guard bar. a. Number System The number system consists of two digits (sometimes three digits) which identify the country/region numbering authority which assigned the manufacturer code. Any number system which starts with the digit 0 is a UPC-A barcode. The number system list is maintained by EAN organization. Also, the number systems for every country/region are listed (in last chapters). b. The Manufacturer Code The manufacturer code is a unique code assigned to each manufacturer by the numbering authority indicated by the number system code. All products produced by a given company will use the same manufacturer code. EAN uses what is called "variable-length manufacturer codes." Assigning fixed-length 5-digit manufacturer codes, means that each manufacturer can have up to 99,999 product codes--and many manufacturers don't have that many products, which means hundreds or even thousands of potential product codes are being wasted on manufacturers that only have a few products. Thus if a potential manufacturer knows that it is only going to produce a few products, EAN may issue it a longer manufacturer code, leaving less - space for the product code. This results in more efficient use of the available manufacturer and product codes. c. The Product Code The product code is assigned by the manufacturer. The product code immediately follows manufacturer code. The total length of manufacturer code plus product code must be exact 10 digits. 27 d. The Check Digit The check digit is used to verify that the barcode is generated or scanned correctly. The check digit is calculated based on the rest of the barcode digits. Since a scan can produce incorrect data due to inconsistent scanning speed, print imperfections, or a host of other problems, it is useful to verify that the rest of the data in the barcode has been correctly interpreted. 2.6.5 How to calculate the checksum The check digit is a character included with the symbol to check on the validity of a barcode’s data when decoding. In the previous section, the check digit was assumed available. However, in the actual encoding process, the check digit is calculated based on the data to be encoded. The process of calculating the check digit is given below: 1. Multiply all odd digits with 3 (the first digit is even). 2. Add all the even digits with the multiplied odd digits. 3. Add a number X to the sum, so that it is evenly divisible by 10. 4. The number X is the check digit. Example: Assume the data to be encoded is; data = 7-501031-31130C (12 digits + 1 check digit) C is the check digit to be determined. 1. Multiply all odd digits with 3, Barcode 7 5 0 1 0 3 1 3 1 1 3 0 Position E O E O E O E O E O E O 3 Multiplier Result 7 15 3 0 3 3 0 9 3 1 9 3 1 2. Add all the even digits with the multiplied odd digits. Total sum = 7+15+0+3+0+9+1+9+1+3+3+0 = 51 3 3 3 0 28 3. 51+9 = 60, evenly divisible by 10. 4. So check digit is 9. 5. Final barcode value is 7-501031-311309 2.6.6 Encoding The process of encoding an EAN-13 barcode is relatively straight forward. An EAN-13 requires 12-digits of data to be present for encoding while the 13th digit (the check digit) will be calculated from the data. a. Total number of bars and modules An EAN-13 symbol can be divided into two halves, each consisting of six digits separated by a center guard bar pattern. The whole symbol is surrounded by two guard bar patterns. The same digit has different encoding depends whether it is in the left halve or in the right halve. The encoding pattern for digits in the left halve always starts with a space while the one for digits in the right halve always start with a bar and ends with a space. An EAN-13 symbol has the following structure: 1. Start guard bars, always with a pattern (bar + space + bar (101)). 2. Left halve, six digits encoded using the encoding from main table A or B. 3. Center guard bars, with a pattern (space + bar + space + bar + space (01010)). 4. Right halve, six digits encoded using the encoding from main table C. 5. Stop guard bars, always with a pattern (bar + space + bar (101)). Table 2.2: Total number of bars and modules for EAN-13 barcode Left guards (start) = 3 bars = 3 modules Left hand = 24 bars 6 x 7 = 42 modules Center guards = 5 bars = 5 modules Right hand = 24 bars 6 x 7 = 42 modules Right guards (stop) = 3 bars = 3 modules Total = 59 bars = 97 modules 29 a) Main table of barcode EAN-13 for encoding This main table indicates how to encode each digit of the barcodes, see table2.3 depending on which half (left or right) of the barcode the digit is found. Left-Hand Sets A & B Right-Hand Set C Figure 2.15: EAN-13, left and right hand Table 2.3: The list of oriented-modules on logic of 0-9 for A, B, C, types Digit Left-Hand Encoding Right-Hand Encoding Odd Parity Even Parity Set C (Set A) (Set B) 0 0001101 0100111 1110010 1 0011001 0110011 1100110 2 0010011 0011011 1101100 3 0111101 0100001 1000010 4 0100011 0011101 1011100 5 0110001 0111001 1001110 6 0101111 0000101 1010000 7 0111011 0010001 1000100 8 0110111 0001001 1001000 9 0001011 0010111 1110100 Each character has its own code and it is represented using 7 modules. The corresponding modules are determined from Table 2.3 and Table 2.4. The first digit will determines the parity encoding of the left hand side characters. Steps for encoding are given below. Example of encoding an EAN-13 barcode (assume the check digit is already calculated); Example: EAN-13 Parity encoding from, see table 2.4, see figure below for barcode EAN 13 30 Data = 7-612345-67890 (12 digits + 1 check digit), Number System 76, (number of country), Manufacturer Code 12345, Product Code 67890, Check Digit is 0, see example barcode divided below. 6 (Value) = 7 X-dimension bars = 0101111 = 2 black & 2 white bars Figure 2.16: Encoding number Table 2.4: Result for example Digit name Numeric Value Encoded with Binary - - 101 2nd Number System 6 Odd 0101111 1st Manufacturer 1 Even 0110011 2nd Manufacturer 2 Odd 0011001 3rd Manufacturer 3 Even 0100001 4th Manufacturer 4 Odd 0100011 5th Manufacturer 5 Even 0111001 Central Guard - - 01010 1st Product Code 6 Set C 1010000 2nd Product Code 7 Set C 1000100 3rd Product Code 8 Set C 1001000 4th Product Code 9 Set C 1110100 5th Product Code 0 Set C 1110010 Check Digit 0 Set C 1110010 Right Guard - - 101 Left Guard (always the same) (always the same) (always the same) 31 1. parity digit is ‘7’, thus from Table 2.4, the parity encoding for the six right hand characters are in the order of Odd-Even-Odd-Even-Odd-Even. 2. The first of the left hand digits (the second digit of the 13 digit barcode) is 6, because the parity is odd (obtained from step 1), by referring to Table 2.3, the digit 6-odd will be encoded as 0101111, and is shown in Figure 2.63. 3. The second digit is 1, and the parity is even. From Table 2.3, the code for 1 even is 0110011. 4. The remaining left hand digits are encoded in the same manner. 5. The right hand digits are encoded directly from Table 2.3. 6. (Start guard) 101-> (Black, white, black). 7. (Six left digits) 0101111-> (white, black white, black, black, black, black), 0110011 –> (White, black, black, white, white, black, black) etc, 0011001, 0100001, 0100011, 0111001. 8. (center guard) -01010 -> (White, black, white, black, white). 9. (six right digits) 1000010 ->(Black, white, white, white, white, black, white) etc, 1100110, 1100110, 1000010, 1110010, 1110100 10. (end guard) -101-> (Black, white, black). 2.6.7 Decoding Decoding is just the reverse of the encoding process. By comparing the bars with Table 2.3, the corresponding digit value and its parity can be determined. The parity of the six left hand characters will decide the first character of the barcode. When all the digits are obtained, the check digit can be calculated and then compared with the check digit obtained from scanning. If the check digits do match, the barcode is verified and assumed to be correct. CHAPTER 3 METHODOLOGY 3.1 Introduction This chapter describes the overall steps needed to decode an image barcode with a camera built in the PDA system. Detailed information on how each step is implemented is given, several methods are presented on each step. 3.2 Barcode Image Devices The imaging barcode system should produce barcodes with high quality so that the desired objects can be extracted successfully for processing. The task of the system is to read EAN-13 barcode using a PDA with a buildin camera or reading from a file. In this case, a barcode image is captured using a PDA and then decode it, see Figure 3.1, once captured the PDA will search for the barcode area. 33 Figure 3.1: Architectural Overview: EAN-13 barcode and resolution system consists of a PDA using camera and load from file application for decodes barcode. 3.3 Image Capturing In this Project a SD camera is used (HP photosmart mobile camera). The system can also read image from a file, see figure 2.3. Press to test to load from file barcode Figure 3.2: There are some progresses used to read barcode 34 3.4 Barcode processing in PDA There are some aspects that need to be mentioned when designing a barcode reader. This design has two parts to a read barcode image. First-part, the capture barcode image by camera built-in PDA (online). Second-part, load from file (offline). This barcode image can contain whole a barcode or a partial barcode depending on the field of view. See figure below. Figure 3.3: Image processing in PDA 35 3.4.1 Searching for barcode image automatically When the system wants to read a barcode it gives the coordinate of the barcode to the barcode reader, see figure 3.4, some symbols barcode image. Then, searching for the image barcode automatically (locate the area of interest), see figure 3.4. The barcode localization algorithm will then be applied to the barcode image. Figure 3.4: Some symbols barcode image To be able to identify the elements of a barcode with good result, the location of interest of the barcode must be known. This area will be referred to as “the region of interest” see figure above. There are scenarios after a barcode image has been searched automatically. Thereby, it gets an accurate result when identifying the elements. The localization algorithm will give information about the extent of the barcode outside the image. The system will be instructed to grab new a barcode images at the new positions. Therefore, the localization algorithm must be able to locate the barcode image area for any orientation of the barcode. Thus, to be able to identify where the barcode is in an image one must be able to specify what is special about a barcode area, either in the spatial domain. Linear barcodes have thin and narrow parallel lines 36 and these lines have high contrast. Two-dimensional symbols also have high contrast, but they do not contain parallel lines. In most barcode applications, the barcode occupies a small part of the barcode image. In this application, the code will most likely occupy a large part of the image, because the image size is small compared to the barcode. The direction of the barcode is not known in most cases. The algorithm must therefore be able to locate a barcode area in any orientation. 3.4.2 Identification of the Bars and Spaces To be able to decode the barcode, the width of the elements must be identified with high precision. One way to get a waveform for analysis is to use the intensity in the barcode image in a similar way as the voltage from a laser scanner. To accomplish this accurately the orientation of the barcode must be known. Two adjacent edges in the waveform constitute the start and stop of an element. So, the task is to detect the edges of the waveform. If the image barcode is damaged it might have to be filtered to improve reading performance. 3.4.3 Estimating How Correctly the Elements Have Been Identified All barcode symbols have a well defined set of valid element widths. For EAN-13 (X-XXXXXX-XXXXXX), the set is {X, 2X, 3X, 4X, 5X, 6X}, X is the smallest element size. If the output from the identification of the bars and spaces is not within these sets or matches the elements in these sets poorly, an alternative method should be used for identifying the bars and spaces. 37 3.4.4 Decoding the Barcode The proposed decoding is as follows: • First, it obtains a sample row across the barcode image. • The signal is then converted into the binary form by simple thresholding based on the mean value of the signal. The signal in a binary form, which is essentially a binary sequence of 1’s and 0’s. • The run-length encoding is performed on the binary sequence so, that the individual width of the alternating black and white bars can be determined. • The next step is to determine where the barcode begins by searching for the left hand guard pattern. • Once the left hand guard pattern is found, the decoder will read the next 6 sets of 4 bars to determine the values of the 2nd, 3rd, 4th, 5th, 6th and 7th barcode digits. The center guard pattern should be detected before reading the next 6 sets of 4 bars, which specify the values of the 8th, 9th, 10th, 11th, 12th and 13th digits. The lock-up tables for the EAN-13 symbologies are given in table 3.1 and table 3.2. Table 3.1 is the lock-up table for a regular barcode and table 3.2 is for a flipped or mirrored barcode. The decoding algorithms were used, namely the Predictive decoding algorithm [1]. Digit 0 1 2 3 4 5 6 7 8 9 Table 3.1: Normal barcode (left to right) Left Right Odd Even Odd 0001101 3211 0100111 1123 1110010 0011001 2221 0110011 1222 1100110 0010011 2122 0011011 2212 1101100 0111101 1411 0100001 1411 1000010 0100011 1132 0011101 2311 1011100 0110001 1231 0111001 1321 1001110 0101111 1114 0000101 4111 1010000 0111011 1312 0010001 2131 1000100 0110111 1213 0001001 3121 1001000 0001011 3112 0010111 2113 1110100 3211 2221 2122 1411 1132 1231 1114 1312 1213 3112 38 Table 3.2 Flipped or mirrored barcode Digit Left (inverted) Right (inverted) Even Even Odd 0 1011000 1123 1110010 1123 0100111 1 1001100 1222 1100110 1222 0110011 2 1100100 2212 1101100 2212 0011011 3 1011110 1411 1000010 1411 0100001 4 1100010 2311 1001110 2311 0011101 5 1000110 1321 1001110 1321 0111001 6 1111010 4111 1010000 4111 0000101 7 1101110 2131 1000100 2131 0010001 8 1110110 3121 1001000 3121 0001001 9 1101000 2113 1110100 2113 0010111 3211 2221 2122 1411 1132 1231 1114 1312 1213 3112 a. Predictive Decoding One of the major advantages of predictive decoding is that it handles noise and inaccuracies very well. The predictive method basically predicts the outcome without comparing all the bars. The basis of this method is that, certain combinations of bars are unique and thus allowing some optimization to be performed. In a worst case scenario, the predictive decoding method only requires 3 out of 4 bars to be present for successful decoding. 3.5 Pre-Processing As in all applications involving image acquisition followed by processing of the images, the qualities of the images are of great importance. Many things do influence the output of the camera built-in PDA, and as regarding all photography, the lighting is the foremost important variable which affects it. Motion of the object, and the distance between the camera and the object are other important issues. Most of which depends on the actual location of the object and its light conditions, or the chosen camera built-in PDA and its features and performance. However, in many applications the sought image is not only an image that is appealing to the human eye. Other features might be important to amplify or reduce to enhance the relevant information of the image. 39 3.5.1 The RGB color model In the RGB model, each color appears in its primary spectral components of red, green and blue. This model is based on a Cartesian coordinate system. The color subspace of interest is the cube shown in figure 3.5. In which RGB values are at three corners, cyan, magnets and yellow are three other corners, black is at the origin, and white is at the corner father from the origin. In this model, the gray scale (point of equal RGB values) extends from black to white along the line joining these two points. The different colors in this model are points on or inside the cube, and are defined by vectors extending from the origin. For convenience, the assumption is that all color values have been normalized so, that the cube shown in figure 3.5 is the unit cube. That is, all values of R, G, and B are assumed to be in the range (0, 1). Image represented in the RGB color model consist of three component images, one for each primary color. When fed into an RGB monition, these three images combine on the phosphor screen to produce a composite color image. The number of bits used to represent each pixel in RGB space is called the pixel depth. Consider an RGB image in which each of the red, green, and blue images is an 8-bit image. Under these conditions each RGB color pixel (that is, a triplet number of bits per plane). The full color image is used often to denote a 24-bit RGB color image. B Blue 0, 0, 1 Cyan Magenta White Gray scale 0, 1, 0 Green Black 1, 0, 0 R Red Yellow Figure 3.5: Schematic of the RGB color cube G 40 3.5.2 Gray scaling Gray scaling is done to remove the color values of the image. It is a very common preprocessing step in most image processing applications where additional color information is unnecessary. A color image is a composition of 3 separate layers of Red, Green and Blue. Processing on a color image is 3 times slower as the processing has to be performed on three different layers. Besides that, a color image also requires three times the memory space compared to a gray level image (for an uncompressed image). These drawbacks are definitely undesirable for real-time application especially when the color information in not required. Grayscaling converts a color image (a 24-bit RGB, 8-bit per channel in this case) to an 8-bit gray level image, thus representing the light intensity of the image, see Figures below. Thereby, the data is ready for further processing. R G B Figure 3.6: Illustrating difference between a general RGB color image and a general gray scale image. Figure 3.7: Original gray-scale image 41 3.5.3 Image Enhancement To prepare the image for the next stage in the system, the Feature Extraction stage, it has to be suitably enhanced. This process is a prelude to the Barcode Localization phase, which is the first thing done in the Feature Extraction stage. In this case barcodes are the region of interest, thus making the process of high- lighting the patterns that are characteristic for barcodes the aim of this section. This means that areas of high contrast containing many parallel lines are considered highly interesting, and should thus be amplified. While oppositely, areas of uniform grayscale levels are considered as of low interest regarding barcodes. The basic idea is to sharpen the image, thereby making details and edges appear clearer, and at the same time to suppress areas of low interest, such as fields of uniform gray-scale etcetera. Intuitively averaging of pixels in a region – which is analogous to integrating over that region - does blur detail. Leading to the expectation that differentiation yields the opposite effect, thus sharpening the image; which is just the sought-for effect. As a collective name these kinds of operators are called derivative filters, and the most common method to achieve it is by using the gradient. The analytical expression for the gradient, of the function f(x; y), this step is carried out to enhance certain details in the image such as edges or to attenuate others such as noise. Brightness and contrast of the image can also be adjusted here. Three filters can be applied consecutively in a cascading manner to the image in addition to brightness and contrast adjustment. Specifically, there are four spatial filters available for use, mainly for sharpening and blurring. The filters are applied automatically. The filters that are available and their respective kernels are shown in Figure 3.9 A convenient way of doing this kind of processing on images is by letting a windowing function operate on the image. The windowing function exemplifed with a window of 3 x 3 pixels works as follows: Consider Figure 3.7, where the z-values represent the gray-level values of the original image. The values of all the nine pixels, z1 through z9, are each multiplied with pre-defined factors. Then the sums of all components are set as the new centre of the window, in this case position z5. [2] 42 The window is then moved on to the next pixel, and the same procedure is repeated, see figure 3.8. By sliding the window in an overlapping fashion the whole image, except the pixels in the margin of the image. Figure 3.8: A 3x3 window, for use in a windowing function, where the z-values corresponds to the gray-scale values of the original image. Figure 3.9: Spatial filters (a) Gaussian Blur, (b)Laplacian (c) Sharpen (d) Unsharpen Mask 3.6 Scanning Direction The first step is to scan for a barcode or multiple barcodes in the scene or image (a frame in the case of real-time acquiring). The method employed is similar to that of a laser scanner. Image is scanned in 4 directions, horizontally (left to right), vertically (top to bottom), 45 degrees diagonally (top left to bottom right) and -45 degrees (bottom left to top right), shown in Figure 3.10 Each of the direction is known as a scan direction. The number of scan line depends on the scanning resolution set by the user. Depending on the accuracy required, the number of scan lines can be increased or decreased [1]. 43 Figure 3.10: Scan 4 directions implemented Each direction detects flipped and mirrored barcodes without a second pass. This is because; flipped and mirrored barcodes are handled by the decoding mechanism rather than the scanning mechanism. The scanning mechanism is merely for obtaining a provisional location of a barcode. (a) (b) (c) (d) Figure 3.11: These are some direction of a barcode at different angles, (a) Horizontal (b). Vertical (c) Diagonal (d) invest horizontal Four scan directions are implemented to allow detection of rotated barcodes (rotation of barcodes also referred as skewing) which is a usual occurrence in reality. By scanning horizontally (0), vertically (180) and diagonally (-45 and 45), the barcode reader is capable of detecting barcodes throughout the 360o range. See figure 3.11 44 Angular information of the barcode is acquired through knowledge of the vector displacement, k, and the distance, d, between the correlated vectors, when the correlation between two vectors is calculated. The barcode's angle is derived as (µ = arctan( d k )), see Figure 3.12 Angles in the images are defined as increasing counterclockwise from the x-axis, with 90 degrees on the y-axis, and 180 degrees on the negative x-axis Figure 3.12: Illustrating how the barcode's angle µ is derived using the vector displacement, k, the distance d between two vectors, and basic trigonometry. 3.7 Barcode Identification & Extraction One-dimensional barcodes are made of bars and spaces. This distinct feature is what the scanning process is looking for. The identification and extraction of the EAN-13 barcode consist of 4 main steps. Referring to Figure 3.12, the steps are; Figure 3.13: Steps to identify and extract the EAN-13 barcodes 45 3.8 Program Architecture 3.8.1 Overview of Programming Languages Used For PDA Platform There are many languages that can be used to program PDA's with Windows CE, OS or Windows Mobile 2003 or 2005, but the most common and popular are: a. Microsoft Visual Studio 2005 Professional Edition Embedded version of Visual C++, C#, J# and Visual Basic are included in Visual Studio 2005 Professional Edition C++. It also contains several SDK tools like Remote Registry Editor, Remote Spy++, etc. More than 95% of Pocket PC developers use this package. b. Visual CE Visual CE used for building database applications for Windows CE. It uses drag and drop controls to create an electronic form. ODBC-enabled software has been used to upload, download, or update the data of windows CE device. c. NS Basic/CE NS Basic is a complete development environment enabling the development of applications with a Pocket PC look. NS Basic includes features such as databases, serial and IR communications, signature capture. Development takes place on the desktop or on the device itself. d. Pocket PC Pocket PC does not generate machine code like Visual C++. Instead, it written intermediate code interpreted by a freely distributable runtime. Windows CE machines are particularly well suited to the use of VMs because they tend to run client applications that don't need incredibly fast loop or integer performance. In addition, Windows CE powered devices can have many different set of CPUs and platforms. Instead of producing a separate executable for each platform and each CPU, Pocket PC allows to distribute one binary for all Windows CE devices. 46 e. Waba Waba is a free open source programming platform that lets developers written a program which can run both on Windows Powered and Palm devices. A version for Compaq iPAQ Pocket PC is an available. f. CASL CASL is an easy to use Windows integrated development environment, and a full featured scripting language, variables, objects, and functions provided by the CASL language and create powerful and flexible applications. 3.8.2 Program Build on PDA This project does some server processes is written by visual Studio 2005 c++ (see Appendix A and Appendix B), is made of some main classes, see table below. Table 3.3: These are classes used in program This class encapsulates image processing routines to be Image performed on a 32-bit RGBA image in memory (device context). Data Decode EAN Barcode Module Handles global program variables Contains scanning and decoding functions for EAN-13 A class to hold all barcode parameters such as height, width, digit, coordinate, etc Holds module parameters such as height, width, normalized width, color, etc. (referred by Barcode) SDIOCam Camera SDIO SDK Specification 47 3.9 Program screenshot The program utilizes one user thread and one image processing thread. Threading allows maximum flexibility and efficiency. Threading allows certain portions of program code to be executed separately but in parallel to other executing codes. Thus, the application is also known as a multi-threaded application. This program used a multi-threaded applications provide better performance on multi processor systems onto some button. Threading also opens up the possibility of parallel execution of codes that do not depend on each other, thus avoiding any waiting that typically occurs in sequential programs. Execution of dependent code can also be implemented using threads, with certain locking and unlocking mechanisms in place. 3.9.1 Program interface This is program interface, can be from here use offline to a read barcode see figure below. 11 1 3 2 4 6 5 8 7 9 Figure 3.14: program interface 10 48 The user interface consists of several important elements which are; 1- Display screen. 2- Refresh, use to resume camera. 3- Snapshot, input image capture size 320 x 240 up pixels from camera then, converts from JPEG to BMP, after that, saves in PDA BMP then, display on screen and analysis it. 4– Auto, this button used on catch image and analyses (online) without save in PDA. 5- Test, Load image barcode from file into the test program (offline). 6- Exit. 7- Predictive, Decoding algorithm selection, Predictive 8- Beep; Enable Beep, (when barcode is detected) and/or Multiple Barcode Detection. 9- Decoded barcode value display. 10 - Consume scan operation by milliseconds. 11- Border is drawn around the barcode expanse 3.9.2 Using the HP Photosmart Mobile Camera This a camera will use in a program in real-time (online) with PDA Figure 3.15: Getting Acquainted 49 Table 3.4: specification for interface camera Component Function X. Lens Shows what will be seen in the photo. Y. Rotating Allows to turn the lens to aim at the subject when Lens Body composing a shot. Z. SDIO Interface between iPAQ pocket PC and Photosmart interface Mobile Camera. ` CHAPTER 4 RESULT 4.1 Introduction This chapter shows the results of the system when tested with actual barcodes in real-time (online) and load from file (offline). The experiments are to test the system’s capability, accuracy and performance are described based when subjected to various objects with different properties and in different conditions. Tests were also carried out with rotated barcodes and barcodes residing on various surfaces. Finally, this chapter shows the performance comparison with existing vision based barcode readers. 4.2 Uneven Resolution, Shadow, Shake and Illumination One of the major concerns is the level of resolution. Poor lighting and shaking or incorrect camera position may cause shadowing and uneven illumination to be present, see figures 4.1. Although in industrial applications (such as on a PCB manufacturing line) the presence of uneven illumination in unlikely (due to strict lighting and a controlled production environment), this cannot be said in situations where the device is handled by human or when there is human involvement. 51 (a) (b) (c) (d) Figure 4.1: These are some samples for barcodes image are not clear, all of them (uneven resolution and shake). 4.3 Tests of Barcode Orientation 1. Firstly, the capture barcode image must be very clear, that means the bars and space are very clear, see figure below. (a) (b) Figure 4.2: Some types of barcode all of them very clear 2. Secondly, if the captured barcode images are bad, can not analyze because bars and spaces are not clear, that mean of barcode has some blur or resolution is bad or shake in barcode image see figure Figure 4.3: Some types of barcode all of them not clear 52 4.3.1 Computing the orientation of the barcode Computing the orientation of the barcode is important for accurate classification of the bars and spaces. The orientation can either be determined from the bars themselves or from the area of interest, i.e. the output from the localization algorithm. a. Computing the orientation of the Bars The orientation of a bar code can be computed from the direction of the bars. To get an accurate result, some smoothing of the input image is required. This method can be applied to the entire bar code region. b. Analyzing the Output from the Bar Code Localization Algorithm By analyzing the output from the algorithm for detecting the region of interest, a good result on the barcode angle can be achieved. All barcode are symbols rectangular shape. The region of interest for a barcode can be estimated by the shape of a rectangle (Angle = α = 90 − β), see figure 4.4 (a) (b) Figure 4.4: Shows the output from the localization algorithm. Angle α is the angle of the bar code. The angle is also given by 90 - β There is one problem with this approach. If the area of the barcode region is too small, the estimated angle may be highly sensitive to inaccurate estimations of the barcode region. If small regions of interests are merged to one large region the angle can be estimated more accurately. X = x. cos(θ ) − y.sin (θ ) − m. cos(theta ) + n.sin (θ ) + m Y = y. cos(θ ) + x.sin (θ ) − m.sin(theta ) − n.sin (θ ) + n 53 Figure 4.5: Rotation 4.4 Show scan diagonal read rotated barcodes (offline) The ability of the developed program to read barcodes on irregular surface is shown in figure 4.6 The detection barcode value is printed at the bottom of the screen and a border is drawn around the barcode region. Its successful detection on the remaining surface is mentioned earlier. (a) (b) (c) Figure 4.6: Diagonal (+45, - 45), (a) scan consume operation 393ms,(b) scan consume 1482ms, (c) scan consume operation 617ms. 54 4.5 Show scan horizontal read rotated barcodes (offline) The capability of the developed program to read barcodes on flat surface is shown in figure 4.7 The detection barcode value is printed at the bottom of the screen and a border is drawn around the barcode region. Its successful detection on the remaining surface is mentioned earlier. (a) (b) (c) Figure 4.7: Horizontal, (a) scan consume operation 531ms,(b) scan consume 492ms, (c) scan consume operation 462ms. 4.6 Show scan vertical read rotated barcodes (offline) The capability of the developed program to read barcodes is along the axis of cylinders and irregular surface shown in figure 4.8. The detection barcode value is printed at the bottom of the screen and a border is drawn around the barcode region. Its successful detection on the remaining surface is mentioned earlier. 55 (a) (b) (c) Figure 4.8: Vertical, (a) scan consume operation 435ms,(b) scan consume 336ms, (c) scan consume operation 515ms. 4.7 Show scan horizontal read rotated barcodes (online) This section shows the scanning process using mobile camera (online) of the developed program to read barcodes on flat surface as shown in figure 4.9 The detection barcode value is printed at the bottom of the screen and a border is drawn around the barcode region. Its successful detection on the remaining surface is mentioned earlier. (a) (b) (c) Figure 4.9: Some tests from camera (online), (a) scan consume operation 203ms,(b) scan consume 270ms, (c) scan consume operation 272ms. 56 4.8 Time Consumption This is an important property indicating the performance of the system is time consumption. For measures concerning time to be relevant the hardware and software configuration of the system. In this application all testing and processing were executed on a PDA: Hardware - Intel 624MHz, PXA 270 processor - 135 MB user available memory. Software - Windows CE 3.0 - Visual Studio 2005, C++. The time consumption measured without the graphical interface illustrates the actual time consumption of the algorithm - with the above defined hardware and software. When images of different levels of resolution were tested from file or from camera onto the differences in time consumption, therefore, the result became consumptions different. 4.9 Performance Comparison Real-time (online) and load from file (offline) processing leads to strict time constraints. The faster the processing the better it is. The processing time largely depends on the size of barcode image (height x Width), resolution of barcode image from camera, shake of camera and the computing power (PDA hardware). The smaller image usually fast in the computing. Moreover, using a faster Pocket PC will definitely produce closer results and will bring the system to be as real-time as possible. The program will repeat the same code over and over again thus it is important that the algorithms be as efficient as possible. In the program developed, the processing time is determined by the following factors: 1. The size of the frame (smaller means faster). 57 2. The implementation algorithm of image enchantment (grayscale, filters add to computation time ) 3. Number of scan barcode image and scan resolution (that means higher resolution). 4. Predictive decoding (the latter is slower). The average decoding time is calculated based on the time taken to successfully detect and decode all of images shown in Appendix B. In the case of incorrect detection or failure of detection, the sample is omitted. The total time is obtained by summing up the time taken for all successful detections and it is normalized with the number of pixels processed, see figure below. COMPARE Shake Resolution Load from file (offline) Camera (online) 0 20 40 60 Figure 4.10: compare consume operation 80 100 CHAPTER 5 CONCLUSION 5.1 Conclusion The program can capture images from offline windows bitmap (BMP) files or in real-time from a camera that is attached or either built in the PDA. This image obtains barcode which is used for further decoding. Thereby, software is already designed based on PDA platform by which different barcodes can be read & decoded. 5.2 Recommendations for Future Work The program can be improved by sending data to server using wireless technology. To read image barcode, this program can be used in smart phones. And, with additional software, this technique can be used in hospitals supermarkets, etc, after updating the database or connecting it with the server. More symbologies can further be added, however, program developed can be migrated to run on other devices to open up the possibilities for the users to obtain product information just by snapping a picture of the image barcode. 59 REFERENCE 1. Usman Ullah Sheikh, Real–time barcode reader using active vision ,It is to decode the UPC-A and EAN-13 barcodes using an active vision system the system was implemented in C++ ,UTM,2004. 2. Johan Bylund, Fredrik Jirhede, Visual Barcode Reading, the implementation of a system for visual barcode EAN-13 reading, using a network camera, the system was implemented in C++, Royal Institute of Technology (KTH) in Stockholm, Sweden., 2003 3. Peter Sundström, Barcode EAN-13 Reader for Surface Mounting Systems, reading bar codes with a camera that has a field of view that is smaller than the size of the bar code: 760326-0451 2001. 4. N. Normand, C. Viard-Gaudin . A Two-Dimensional BarCode Reader. Laboratoire Analvse et Traitement des Images (LATVSEI) IRESTE - Route de Gacheti CP 3003 - 44087 NANTES CEDEX 03; France , 1994. 5. Xi-Ping Luo, Li-Xin Zhen, Gang Peng, Jun Li, Bai-Hua Xiao Motorola China Research Center, Shanghai, P.R.China, and Camera based mixedlingual card reader for mobile device: IEEE, 2005. 6. Eisaku Ohbuchi, Hiroshi Hanaizumi† , Lim Ah Hock‡, Barcode Readers using the Camera Device in Mobile Phones: IEEE, 2004. 7. Hisayuki Tatsumi1), Yasuyuki Murai2), Masahiro Miyakawa1) and Shinji Tokumasu2), Providing Environmental Information by Data Carrier + Networks : Tsukuba College of Technology. 60 8. H. Kato, K. T. Tan, 2D Barcode for mobile phones. The difference between traditional 1D barcodes and 2D barcodes for camera-enabled cell phone application: Edith Cowan University, Western Australia, 2005. 9. Wesley Chan, Project Voyager: Building an Internet Presence for People, Places, and Things, The Voyager Personal Shopping Assistant (PSA) connects shoppers in a supermarket to virtual services, linked to specific products: MASSACHUSETTS INSTITUTE OF TECHNOLOGY, 2001. 10. Robert Adelmann, Marc Langheinrich, Christian Flörkemeier, Toolkit for Bar Code Recognition and Resolving on Camera Phones – Jump Starting the Internet of Things: Institute for Pervasive Computing, ETH Zurich. 11. I, Hong-Yuan &om, Liang-Hua ChenB, Hsiao-Rong Tana, and Jun-Wei Hsiehm , A-BASED BAR CODE RECOGNITION SYSTEM USING NEURAL NET: IEEE, 1993. 12. Jeffrey Adair, Locating, Tracking, and Interpreting Ean-13 Bar Code Waveforms in a Two-Dimensional Video Stream : Hiram College, 2001. 13. Douglas Chai and Florian Hock , Locating and Decoding EAN-13 Barcodes from Images Captured by Digital Cameras : Visual Information Processing Research Group School of Engineering and Mathematics Edith Cowan University, IEEE, 2005. 14. Aparna Rajan Ramchandran , A HANDHELD PDA USING RFID TAGS FOR CHILD VISITORS TO THE MICHIGAN 4-H CHILDREN'S GARDEN : Michigan State University , 2004. 15. Elsag S.p.A. Italy, Datalogic S.p.A. Italy, A COMMON IMAGE PROCESSING FRAMEWORK FOR 2D BARCODE READING.: IEE,1999. 61 16. Yasser Ebrahim, Wegdan Abdelsalam , Maher Ahmed, Siu-Cheung Chau, Proposing a Hybrid Tag-Camera-Based Identification and Navigation Aid for the Visually Impaired: IEEE, 2004. 17. Kwang Bok Lee and Roger A. Grice, The Embedded Zooming Applications for Personal Digital Assistants (PDA) : Troy, New York, USA, 0-7803-7949 , IEEE, 2003. 18. Eva Brandt, Erling Bj ِrgvinsson and Per-Anders Hillgren, PDA´s, Barcodes and Video-films for Continuous Learning at an Intensive Care Unit. NordiCHI, October 19-23, 2002. 19. Hee II Hahn Joung Koo Joung, Implementation of algorithm to decode twodimensional barcode PDF-417: 0-7803-7488 IEEE, 2002. 20. Yonghoon Choi¹, Jong Un Won¹, and Jong Heung Park, An Experimental Testbed for Parcel Handling with RFID Technology: 305-358, Republic of Korea, Feb 2006. 21. Klaus-Werner J.RG, Torsten Gattung & Joachim Weber, Supporting Mobile Robot Localization by Visual barcode Recognition : Kaiserslautern University, Santa Barbara, California, USA, October, 1999. 22. Johan Bylund and Fredrik Jirhede, Vision Barcode Reading : Royal Institute of Technology (KTH) in Stockholm, Sweden, Dec 2003. 23. Lynn Ltd., 912 North Main Street, Ann Arbor, MI 48104 313-9961777(v),663-7937(fax) http://www.adams1.com/pub/russadam/stack.html (3di) 24. N. Ohboshi, R. Nadayoshi, Y. Mitomi, T. Kuroda, N. Sakihana, T. Tachibana, Y. Miyachi, H. Yoshihara: "A Study of Electronic Treatment Planning System for Pressure Ulcers using Personal Digital Assistant", Journal of JAMI, Vol.24, No.1, pp.99-109,2004.(Japanese) 62 http://www.kuhp.kyoto-u.ac.jp/~mi/research/wearable/index_en.shtml 25. Barcode reader with smartphone , 2005 http://www.symbianone.com/content/view/3025/31/ 26. Barcode basic, barcode software center http://www.mecsw.com/specs/speclist.html 27. BarCodeWiz Barcode ActiveX Control, http://www.barcodewiz.com/barcodeactivexhelp/uccean128.asp 28. ActiceBarcode, http://www.activebarcode.com/codes/ean13.html, http://www.gs1india.org/ABOUT/his88-92.htm. 29. .EAN-13 BACKGROUND INFORMATION, http://www.barcodeisland.com 30. Richard E Woods, Digital Image Processing (Second Edition), University of Tenness. 63 APPENDIX A Camera SDIO SDK Specification SDK Interface 1. BOOL SDIOCamVersion(HANDLE hCom, TCHAR *DriverVersion) Description: Get driver version information Params hCom : Camera Device Handle DriverVersion : buffer to receive data Return Value Zero if fail,otherwise not zero; 2. BOOL SDIOCamData(HANDLE hCom, UCHAR *ScreenBufShow, DWORD *ll) Description: Get frame data from driver Params hCom : Camera Device Handle ScreenBufShow : Buffer to receive frame data ll : To receive data length Return value Zero if fail,otherwise not zero; 64 3. BOOL SDIOCamInit(HANDLE hCom, HWND Mainhwnd ) Description Device initialization Params hCom : Camera Device Handle Mainhwnd : Handle of Application main window Return value Zero if fail,otherwise not zero; 4. BOOL SDIOCamSnapShot(HANDLE hCom, TSNAPINFO snapshotinfo) Description Request for doing snap shot Params hCom : Camera Device Handle snapshotinfo : Image quality to achieve and file name、 directory information, resolution and more… Return Value Zero if fail,otherwise not zero; 5. BOOL SDIOCamPreviewStart(HANDLE hCom, HWND hwVideo, int prvmode) Description Request for starting preview Params hCom : Camera Device Handle hwVideo : Handle of Video window prvmode : preview mode, values: PREVIEW_160_120_1X : preview with 160*120 and zoom 1x PREVIEW_160_120_2X : preview with 160 *120 and zoom 2x 65 PREVIEW_160_120_4X: preview with 160 *120 and zoom 4x PREVIEW_320_240_1X: preview with 320*240 and zoom 1x PREVIEW_320_240_2X: preview with 320*240 and zoom 2x PREVIEW_320_240_4X: preview with 320*240 and zoom 4x Return value Zero if fail,otherwise not zero; 6. BOOL SDIOCamPreviewStop(HANDLE hCom) Description Request for stopping preview Params hCom : Camera Device Handle Return value Zero if fail,otherwise not zero; 7. BOOL SDIOCamPowerOff(HANDLE hCom) Description Request for shutting down the power of camera Params hCom : Camera Device Handle Return value Zero if fail,otherwise not zero; 8. BOOL SDIOCamSetting(HANDLE hCom,_PARAMETERINFO parainfo) Description request for Setting the mode of video or snapshot picture Params hCom : Camera Device Handle 66 Parainfo : Mode information to be set Return value Zero if fail,otherwise not zero; 9. void SDIOCamPreviewInit( void ) Description Initialize to preview Params NULL Return value No return value; 10. BOOL SDIOCamDeCode( int PreMode, UCHAR *inBuf, UCHAR *outBuf, ULONG dataLenLeft) Description Decode Image data from JPEG formate to BMP format Params PreMode: Preview Mode.( as SDIOCamPreviewStart) InBuf : Buffer of JPEG data source to decode OutBuf : Buffer to receive decoded BMP data. DataLenLeft : Data length of JPEG data source Return value Zero if fail,otherwise not zero; z Structures Definition Needed 1. typedef struct imgcolor_struct { UCHAR avRed; UCHAR avGreen; UCHAR avBlue; UCHAR avY; }Imagecolor; 67 Description This structure defines the color information Members avRed : Value of red avGreen : Value of green avBlue :Value of blue avY : Brightness 2. typedef struct _TSNAPINFO {UCHAR resolution;UCHAR quality; TCHAR filename[100];} int inbufferlen; unsigned char *imgbuff; int *outbufferlen; HINSTANCE hinst; } TSNAPINFO, *PTSNAPINFO; Description This structure defines the information of snapshot picture when requesting for do snapshot Members resolution : resolution of snapshot picture. Values: TAKPIC_1280_1024: 1280 *1024 wiht zoom 1x TAKPIC_1280_960: 1280 *960 wiht zoom 1x TAKPIC_640_480: 640 *480 wiht zoom 1x TAKPIC_320_240: 320*240 with zoom 1x TAKPIC_640_480_2X: 640 *480 wiht zoom 2x TAKPIC_320_240_2X: 320 *240 wiht zoom 2x TAKPIC_320_240_4X: 320*240 with zoom 4x quality : quality of snapshot picture. 0 : good 1: better 2: best filename : file name of picture to save(full name, directory inside). inbufferlen: imgbuff: outbufferlen: hinst: 68 3. typedef struct{ int WhiteBalance; int Color; int Compression; int AeMetering; }_PARAMETERINFO, *_pPARAMETERINFO; Description This structure defines the information of snapshot picture when do setting Members WhiteBalance : Mode of whitebalance. Values: WB_AUTO: auto; WB_SUN: sun; WB_TUNGSTEN: tungsten; WB_FLUORESCENT: fluorescent; Color : Color of picture, (0: full color; 1: black & white; 2: negative; 3: negative; 4: cool ) Compression : Compression of picture ,( 0: good; 1: better; 2: best ) AeMetering : AeMetering of picture,( 0: average; 1: center-weighted; 2:spot) z Preview Mode and Snapshot resolution values For Snapshot: Zoom*1: #define TAKPIC_1280_1024 0 //1280 *1024 wiht 1x #define TAKPIC_1280_960 1 //1280 *960 wiht 1x #define TAKPIC_640_480 2 #define TAKPIC_320_240 4 // 320*240 with 1x #define TAKPIC_640_480_2X 7 //640 *480 wiht 2x #define TAKPIC_320_240_2X 8 //320 *240 wiht 2x //640 *480 wiht 1x Zoom*2: 69 Zoom*4: #define TAKPIC_320_240_4X 17 // 320*240 with 4x For Preview: #define PREVIEW_160_120_1X 6 //preview with 160*120 and PREVIEW_160_120_2X 20 //preview with 160 *120 and PREVIEW_160_120_4X 21 //preview with 160 *120 and #define PREVIEW_320_240_1X 4 // 320*240 with zoom 1x #define PREVIEW_320_240_2X 9 //preview with 320*240 and PREVIEW_320_240_4X 17 // 320*240 with zoom 4x zoom 1x #define zoom 2x #define zoom 4x zoom 2x #define z White balance values #define WB_AUTO 0 //auto #define WB_SUN 1 //sun #define WB_TUNGSTEN 2 //tungsten #define WB_FLUORESCENT 3 //fluorescent All above need SDIOCam.h 、 SDIOCam.lib 、 SDIOCam.dll 70 APPENDIX B Visual Studio 2005 C++ CLASS DECLARATION Image Processing Class Library Reference 1. RTBCRwithPDADlg.cpp All procedures in program will be done it and all of classce, operatore grayscale and lowpass filter on start vidoe and used thread to some button. volatile bool fThread; UINT __cdecl MyThread( LPVOID pParam ) { CRTBCRwithPDADlg *dlg = (CRTBCRwithPDADlg*) pParam; while(fThread) { if (SDIOCamData(hCom,ScreenBufShow,&ll)) if(SDIOCamDeCode(gPreMode,ScreenBufShow,ScreenBuf24,ll)) dlg->Capture(); • To Load a barcode image from file (offline).in PDA CString strFilter = L"Bitmap Files (*.bmp)|*.bmp|All Files (*.*) |*.*||"; • Display a size for screen.on PDA (can use any size). 71 pdc->StretchBlt(2,0,320,240,&hdcMem,0,0,280,180,SRCCOPY); • This is use, convert from jpg to bmp then save in file. CString filename; filename.Format(_T("..\\..\\My Documents\\barcode\\snapshot%d.bmp"), snapshotno++); imgBar = new CDIBSectionLite(); imgBar->SetBitmap(bmp); imgBar->Save(filename); EndWaitCursor(); • Load from file then, display on screen, finally, anaysis it if (imgBar->Load(filename)) { TRACE(L"\n File opened") ImageProcessing is very important becasue will done all process: ImageProcessing(bmp_image,pDC,this,decode,ptrDest ,depth); 2. #include "SDIOCam.h" (SDIOCam.h, find it in header files in solution’RTBCRwithPDA’) All of code for a Camera, in APPENDIX A 3. #include "Core.h" All procedures are carried out according to the settings, this class is hold in list solution RTBCRwithPDA but can find it in RTBCRwithPDADlg.cpp same name above or search on [ImageProcessing(bmp_image,pDC,this,decode,ptrDest ,depth);] then, clik right-on-muse on ImageProcessing, after that, will see list, chosse Go To Definition go onto code core. void ImageProcessing(Image &img, CDC *pDC, LPVOID param, DecodeEAN &decode, byte * imgArray, int bitdepth); void ScreenPlotter(CDC &MemDC, CDC *pDC, const int &monitor); void DrawBox(CDC *pDC, DecodeEAN &decode,const int &box); void DrawLine(CDC *pDC, DecodeEAN &decode,const int &line,const int &i); 72 void ImageProcessing(Image &img, CDC *pDC, LPVOID param, DecodeEAN &decode, byte * imgArray, int bitdepth) CPen pen(PS_SOLID, 2, RGB(255, 0, 0)); bounds to image barcode on screen pDC->SelectObject(pen); inline void ImageProcessing(Image &img, CDC *pDC, LPVOID param, DecodeEAN &decode, byte * imgArray, int bitdepth); inline void ScreenPlotter(CDC &MemDC, CDC *pDC, const int &monitor); inline void DrawBox(CDC *pDC, DecodeEAN &decode,const int &box); inline void DrawLine(CDC *pDC, DecodeEAN &decode,const int &line,const int &i); inline void ImageProcessing(Image &img, CDC *pDC, LPVOID param, DecodeEAN &decode, byte * imgArray, int bitdepth) Bounds to image barcode on screen : CPen pen(PS_SOLID, 2, RGB(255, 0, 0)); pDC->SelectObject(pen); 4. #include "Image.h" (Image.cpp, find it in source files in solution’RTBCRwithPDA’) It will do some progress for image. Adjusts image brightness, Restores FPU register state for FPU operations, Performs color correction on image pointed by MemDC. R, G and B are integer values to be added to the existing image. R, G, B values are applied to all pixels in the image. Alpha channel is ignored, Adjusts image contrast, creates a new image in the memory buffer (x Width of the image, y, Height of the image, depth Bit depth of the image.), Performs memory cleanup, and frees up memory, void FilterGaussianBlur(); void FilterLaplacian(); void FilterSmooth(); void FilterSobel(); void FilterUnsharpen(),Gets the gray level value of a pixel pointed by the coordinate x,y or offset, loads internal object memory buffer with a 32-bit image pointed by MemDC, Converts a color image to a grayscale image, Inverts a grayscale image, Returns a pointer to the grayscale image array, Rotates the grayscale image in memory buffer by specified given degrees, Copies image from object image buffer to target compatible device context. Available as Device-Independent or DeviceDependent Bitmaps functions. 73 void Image::ColorCorrection(const int &R, const int &G, const int &B);Performs color correction on image. R, G and B are integer values to be added to the existing image. R, G, B values are applied to all pixels in the image. 5. #include "Data.h" (Data.cpp, find it in source files in solution’RTBCRwithPDA’) General const, size for show an image barcode and General Variable, size for *.bmp ( W & H) 6. #include "DecodeEAN.h" (DecodeEAN.cpp, find it in source files in solution’RTBCRwithPDA’) Decoding Class Library Reference for EAN-13, clears the result in memory, scans the image for barcode and decodes it, obtains image width and height, #include "DecodeEAN.h" #include "Image.h" #include "Barcode.h" #include <math.h> #define black 0 #define white 255 // The black color is (0). // The white color is (255). DecodeEAN::DecodeEAN() { Clear(); The sympols for code to barcode between "". code=""; Dash "-" between name and number for barcode. dash="-"; Barcode EAN-13. ean=" (EAN-13)"; Barcode Guard between start and end. EnableChkHeight=1; GuardBarTolerance=(float) 0.4; tolerance=10; ModeDecode=1; ModeGuardbar=1; ModeNormalize=1; Mode1stchar=1; 74 ModeGetWidth=1; height2width_ratio=10; Continuous all code ….. 75 APPENDIX C Some Types of digital camera card 1.1 HP Photosmart Mobile 1.3MP Camera The HP Photosmart mobile camera allows consumers to turn their HP iPAQ Pocket PC into a mobile digital imaging center. By putting the power of digital imaging in their pocket, users can produce great 4 x 6 snapshots with 1.3-mega pixel total resolution and 4x digital zoom, or capture video clips with audio to playback on their iPAQ Pocket PC or desktop computer anywhere, at any time, see figures below. Specifications: 1. 1.3 MP total resolution 2. 4x digital zoom 3. 1-bit SDIO interface 4.Video capture with audio 76 1.2 Pretec SD Camera 1.3MP SmartCam The Pretec 1.3Mp CompactCamera is a full-featured digital still and digital video camera card that can be used on any Pocket PC or Pocket PC 2002 PDA with a CompactFlash Type I interface slot. The 1.3Mp CompactCamera is capable of taking photos of up to 1.3 Megapixel resolution. It also features a 2X digital zoom. Several image quality settings allow you to adjust the JPEG compression level to get the perfect balance between the file size of the image file and its quality. The 180-degree swivel head design allows you to view yourself, an automatically adjusted upright view of the scene you are facing if you rotate the head all the way in the opposite direction, or all angles in between. Organize your photos and video clips into colorful albums, even add text and audio annotations for your favorite files. Capture the moment with the 1.3Mp CompactCamera! Your photos and video are all stored directly in your Pocket PC's main memory, from which you may upload to your PC for viewing, editing, and sharing, see figures below. 1.3 Spectec 1.3 Mega Pixel SD Camera for Pocket Pc and Palm Superb SD camera that works in Pocket PC and Palm OS devices - the drivers are already installed on the card so it is quick and simple to use. At A Glance - Spectec SD 1.3 Mega Pixel Camera Camera Design: • Digital Zoom: 1x,2x, and 4x • Swivel lens allows you to point in multiple directions in a 180° range 77 • Secure Digital I/O (SDIO) type, suitable for all Pocket PC and Palm PDA which have SDIO slots hardware • The live preview window size is from 160 x 120 to 320 x 240 (full screen). • Self-view / portrait / landscape display mode. • Full Screen display at 320x240 landscape (240x320 portrait) • Supports to capture still images in JPEG, BMP and GIF formats. • Image size from 320x240 (240x320) to 480 x 640 (640 x 480) at true colours. • Three different imaging controls (auto gain control, auto white balance and auto-exposure), see figures below. 1.4 Veo Cancels 1.3MP Camera Veo Cancels 1.3MP Camera, turn your Pocket PC handheld into a 1.3 megapixel camera! Get close with a 4x digital zoom, record and send video clips, and print high quality 3" X 5" pictures. that already have to create a 1.3 Megapixel camera. Simply install the drivers, plug the 130S into your SD expansion slot and within seconds. "With the release of our Photo Traveler 130S for Pocket PC, see figures below. 78 Figure: Veo Cancels 1.3MP Camera 79 APPENDIX D SOME BARCODE IMAGE ARE VERY CLEAR 80 APPENDIX E SCREENSHOTS OF COMMERCIAL TEST PROGRAMS Interface program visual studio 2005 when created program on a PDA 81 82 APPENDIX F Number System (number of countries) The number system consists of two digits (sometimes three digits) which identify the country (or economic region) numbering authority which assigned the manufacturer code. Any number system which starts with the digit 0 is an EAN-13 barcode. The valid number system codes are presented in the following table: Table of number system 00-13: USA & Canada 20-29: In-Store Functions 30-37: France 40-44: Germany 45: Japan (also 49) 46: Russian Federation 471: Taiwan 474: Estonia 475: Latvia 477: Lithuania 479: Sri Lanka 480: Philippines 482: Ukraine 484: Moldova 485: Armenia 486: Georgia 487: Kazakhstan 489: Hong Kong 49: Japan (JAN-13) 50: United Kingdom 520: Greece 528: Lebanon 529: Cyprus 531: Macedonia 535: Malta 539: Ireland 54: Belgium & Luxembourg 560: Portugal 569: Iceland 57: Denmark 590: Poland 594: Romania 599: Hungary 600 & 601: South Africa 609: Mauritius 611: Morocco 613: Algeria 619: Tunisia 622: Egypt 625: Jordan 626: Iran 64: Finland 690-692: China 70: Norway 729: Israel 73: Sweden 740: Guatemala 741: El Salvador 83 742: Honduras 743: Nicaragua 744: Costa Rica 746: Dominican 750: Mexico 759: Venezuela 76: Switzerland 770: Colombia 773: Uruguay 775: Peru 777: Bolivia 779: Argentina 780: Chile 784: Paraguay 785: Peru 786: Ecuador 789: Brazil 80 - 83: Italy 84: Spain 850: Cuba 858: Slovakia 859: Czech Republic 860: Yugloslavia 869: Turkey 87: Netherlands 880: South Korea 885: Thailand 888: Singapore 890: India 893: Vietnam 899: Indonesia 90 & 91: Austria 93: Australia 94: New Zealand 955: Malaysia 977: International Republic Standard Serial Number for Periodicals (ISSN) 978: International 979: International Standard Standard Book Music Number (ISMN) Numbering (ISBN) 981 & 982: Common Currency Coupons 99: Coupons 980: Refund receipts