Technical FAQs for "Barcode Xpress"
Overview
Goal:
Create a command line sample program for reading different types of barcodes using Java, including damaged barcodes and low quality images.
Requirements:
- Barcode Xpress Java SDK (download free trial here)
- Oracle Java SE 5.0 and up
- Oracle Java JDK 1.8 or above
- Development IDE (in this example, Eclipse Java Oxygen is used)
Programming Skill:
Java Intermediate Level
Need to recognize barcodes from an image file in your Java application? In this project, we’ll walk through how to do this with a powerful barcode library for Java, Barcode Xpress.
Setting Up
If you’re already an experienced Java developer and know how to setup your development environment, feel free to skip this section.
Start by downloading a trial version of the Accusoft Barcode Xpress Java SDK. Within your Accusoft Barcode Xpress Java SDK will be the file barsdk5.jar. Expand that either with your favorite unzip program or if your java environment is already set up, just run:
Along with some code samples, there will also be the file tasbar5.jar. This contains the libraries that are needed to run this sample.
Depending on your development environment, you’ll want to add this jar file to your Java Build Path. Since Eclipse is being used for this sample, right click on your Java project and select Properties, then “Java Build Path”, and the “Libraries” tab.
It’s useful to add in the jar files into a common library, so in this case we’ll add a folder called “lib” into the development directory and place the tasbar5.jar file there so it can be included with whatever code repository system is being used. Then to reference this file, click “Add External JARs”, navigate to the lib directory, and select tasbar5.jar. Now the various Java objects we’ll need for our code can be accessed.
Here is the source code for the application we’re demoing in this article:
Scanning the First Barcode
For our code to work, let’s go over how to import an image file into Java, how to set the options for what kind of barcodes to scan for, and then how to scan the file itself.
Here’s a sample bar code to be read.
As we can see – it’s not perfect. Looks like the paper was a little off on one side, there’s some pixelation in the scanning. Maybe the scanner was nudged during the process. sam
Our SimpleBarCodeScanner program works via the command line. The first argument will be the type of barcode we’re scanning – we’ll pick Code39 as our default barcode to scan for. So a typical execution of this program will look like this (assuming that your tasbar5.jar is in the /lib directory, and you execute the program from your compiled /bin directory):
Let’s run it, see what the results are, and then step through our program code to explain what’s going on.
Looking At the Process
We’ll skip over the items in the Main function – all we’re really doing there is accepting the arguments, and as long as they’re valid, we pass it onto the ScanBarCodeFile function via the following command:
This function takes an integer as the barcodeType. Barcode Xpress can handle several different types of barcodes (for a list of supported barcodes, please review the documentation at http://help.accusoft.com/BarcodeXpress/v12.0/dotnet/webframe.html#Supported_Barcode_Types.html ), but for this example we’re just going to focus on one dimensional barcodes of the Code39, Code128, and CodeEAN13 standard.
A complete copy of the source code is available above – we’ll just highlight some items to go through what it’s going.
When we start, our function is going to read in the image file we’ve specified. The Java object BufferedImage can input JPEG, PNG, GIF, and BMP formats, so we’ll stick with png files in our example.
Once the BufferedImage object has been loaded, let’s load it into the Barcode Xpress object BarReader:
There are plenty of options to set in our BarReader object, and to do that, we’ll load them up into a Readoptions object, then set it to read the barcodes from left to right:
Since we just want to scan in specific types of barcodes as we run the function, we can specify that by setting that in our options object:
In this case, we select 1 as our barcode type, so it defaulted to the Code39 standard. To actually scan the image based on the options we’ve set up, just set our Barcode Xpress object to read them from the BufferedImage object, and store the results in an array of Barcode objects. This way if there’s more than one barcode in a document, we’ll find them all:
And here’s our value displayed:
More Options
Only Scanning A Specific Type Of Barcode
That works just fine for a simple demonstration – one barcode inside of one file. Let’s increase the complexity a bit. What if we have an image with different kinds of barcodes within it, but we only care about one of them?
Not a problem – Barcode Xpress detects the barcode we’re interested, and ignores the other.
Scanning Multiple & Misaligned Barcodes
Because of the way our code is situated, we can scan multiple barcodes in one shot, like in this image:
Barcode Xpress is capable of scanning 1,000 documents a minute – so one image file with a few barcodes in it isn’t a problem.
Also notice that the orientation of the image isn’t an issue – some of them are at an angle, so we don’t have to worry about whether the image is perfectly vertical or that everything is lined up. Just scan, get the data, and move on.
Switching Types Of Barcodes
We can also shift between different kinds of barcodes on the fly. In an image that has both EAN-13 and Code39 standards, we can flip between scanning for one and the other by changing the command line switch:
We’ll start with Code39 by setting the first command line argument to “1”, then flip right back into EAN-13 by setting the command line argument to “3”
Rather than worrying that you’ll get more information than you need – you can pick and choose for your needs.
Integrating Into Your Program
If you’re looking to implement this code in your project, the following function will provide the data you require. GetScanBarCodeFile works the same as our ScanBarCodeFile above – only instead of displaying the barcode values on the console, it returns an array of BarCode objects so you can extract the data yourself. The function can be called by:
Here’s a copy of the GetScanBarCodeFile function:
Ready to try it out? Check out Accusoft Barcode Xpress for more details or to download an evaluation copy.
Inventory warehouses and distribution centers can contain hundreds of thousands of square feet of space filled with row after row of shelved items. The online retail giant Amazon opened a fulfillment center in Ruskin, Florida that measures 1.1 million square feet in 2016! A “Mom and Pop” grocery store may have a tiny storage space in comparison, but each of these businesses will experience tracking issues. With any size inventory there are several challenges to consider. How do you track what is coming in and out? How do you know which of these items are performing well and which are not selling? If any of your items are perishable, how do you keep track of which need to be pulled from inventory first? You thought you had more of this product in stock, where did it go? Using barcodes in inventory management can help.
The Challenges of Inventory Management
The reality of inventory management is that it can be a difficult and time-consuming undertaking. Without proper inventory tracking and control, your business could miss out on sales, lose inventory to shrinkage and undetected theft, or experience product spoilage. Any of these issues can cost a business both time and money! Manually handling inventory also increases operating expenses, taking up vast amounts of time and creating a large margin for human error. All of these are issues that can be addressed by implementing a barcode system.
The Benefits of Inventory Control Systems
Monitoring the flow of your products is vital to understanding what needs to be restocked more often, keeping your business from missing out on potential sales. At the same time, you need to keep an eye out for products that are underperforming, thus taking up valuable space and racking up carrying costs. A well implemented inventory control system allows users to keep visibility on levels of inventory and notifies them when it is time to reorder or return items. Using barcodes as a part of an inventory management system is a low-cost way of ensuring product levels are constantly available. Assigned barcodes can also help track when items are nearing their shelf life.
How Barcode Systems Can be Integrated with Inventory Control
With a barcode system, the location of items becomes constantly available as well. You can use barcodes to track a product from receiving through shipping, shelving, and sale. This is useful in ensuring the number of products ordered or shipped is the same as the number of products received, especially in the case of large shipments containing hundreds or even thousands of units. Should shrinkage be an issue, this information can help determine where in the process products are going missing and for what reason.
Implementing a Barcode System
Manually managing inventory can be time-consuming and costly. The chance of human error in counting, remembering to reorder, or tracking products is high. A software program that utilizes barcode generation and reading is a low-cost, highly efficient way of eliminating error. Simply generate a barcode for a specific product, print it on a sticker, and scan for instantaneous data. Once you decide to implement a barcode system, try Barcode Xpress. Barcode Xpress quickly and accurately reads and writes over 30 different barcode types including 1D, 2D, postal codes, and patch codes. It also reads broken, damaged, and poorly printed barcodes automatically. Be sure packages are accounted for at every step in the process, in any condition.
If you’re planning to (or already do) use barcodes to efficiently process and store document images, you’re thinking about the ways you can make barcode recognition as easy, fast, and accurate as possible. Regardless of whether you’re using 1D or 2D barcodes, or whether you’re using barcodes to auto-index documents, process forms, or track inventory, there are plenty of ways to optimize your barcode scanning and decoding.
Here are seven ways to get the most out of your barcodes:
-
Pixels per element
To produce the most readable 1D barcodes, create barcodes with at least three pixels as the minimum bar width. For 2D barcodes, aim for modules to be 4 or 5 pixels.
-
Variable-length data
Don’t allow barcodes to be automatically generated with unlimited length data. You won’t be able to guarantee the overall barcode size required for accurate recognition if more and more elements get squeezed into a fixed area. If you require variable-length data, be sure to set a limit on the maximum size of each field.
-
Avoid skewed input
In most cases, higher skew angles reduce barcode recognition accuracy. Whenever possible, take steps to reduce skew. This may involve routine maintenance of input devices, using better sheet-fed scanners, deskewing barcodes as separate regions of interest on a form, or simply placing a box on your forms to help operators align manual barcode stickers. But, if you are stuck with a skewed image, remember that electronic deskew will sometimes decrease accuracy, not improve it.
-
Specify cleanup
Experiment to determine the optimal cleanup features for the types of damage your document images usually experience. This could be SmoothZoom, dilation, deskewing the barcode’s region of interest, or an algorithm that tries each and compares decode confidence.
-
Optimize performance
If you’re processing a lot of barcodes, there are plenty of options which could significantly increase performance. Try limiting scanning to either horizontal or vertical (if you only expect one orientation), limiting the number of expected barcodes per document, utilizing the multi-threading capabilities of Barcode Xpress, and searching only the pages or areas on the page where barcodes are found.
-
Know thy image
The more you can predict about the images containing barcodes, the better you can optimize their recognition. If you know the number, type, resolution, rotation, and placement of barcodes, you can use some of the tools mentioned above to speed recognition. This may also suggest locking down your business process to reduce variation. Using cues about the image can allow you to optimize cleanup and improve recognition speed and accuracy.
-
Test, test, test
Try to simulate the expected business process that document images will experience on the way to your system. If the documents will be faxed twice, fax some samples three or four times, then validate. If they’ll be printed, copied, and scanned, at least repeat all of the expected steps on the worst acceptable hardware in your system.
Accusoft’s Barcode Xpress can distinguish over 30 1D and 2D barcode types and is capable of multi-threading as an optimization strategy.
Have more helpful tips to ensure barcodes are processed as quickly, efficiently, and accurately as possible? Have questions about these best practices? Share below in the comments!
Corey Morehead, Accusoft Software Engineer
With more than 30 different types of barcodes out there, it begs the question, “what kind of barcode type is best for my needs?” Below I provide some information that might help you answer just that. There are many different reasons why a company would use barcodes—security tracking, scalable inventory databases, or reduced employee training time—to name a few. For example, many online companies such as Amazon will only sell your product if it has its own unique barcode. With the different variations of barcodes it can be difficult to choose the correct one for your needs. Here we’ll explore some pros and cons of the most commonly used barcodes, so you can select the appropriate one to begin to reduce your overhead and improve efficiency.
1D Barcodes
EAN-13 (European Article Number-13 digits, aka International Article Number) is used all over the world for (but not limited to) branded products sold for retail, coupons, inventory, and refund receipts. Benefits for these barcodes include that the EAN-13 and EAN-8 are the accepted standard consumer barcode. As of January 2005, all retail scanning systems in the United States must be able to accept the EAN-13 symbol as well as the standard UPC-A symbol.Any software that is capable of reading an EAN-13 symbol will automatically be able to read an UPC-A symbol. The major differences between the EAN-13 and UPC-A is that the first two digits of an EAN-13 barcode represent the country code, where UPC-A only has one digit for location coding. The country codes represent the country in which the manufacturer is registered.
2D Barcodes
Summary
Above I mentioned benefits and limitations of some of the more commonly used barcodes. I spoke about the benefits of the EAN-13 and UPC-A for retail, Code 39 for an alphanumeric option, and the two-dimensional barcodes, QR and Data Matrix for your marketing needs. To learn more about how you can incorporate barcodes into your applications, check out Barcode Xpress for more information.
Corey Morehead is a Software Engineer at Accusoft. He joined the company in 2014 as a Software Engineer in Support. Corey now plays a key role on the recognition team working on Barcode Xpress, ScanFix and FormSuite. Corey has his BS in Game Development.