Read barcode from image in JAVA

I have a java application that requires reading a barcode from an image into a java program. I really liked the zxing library, which is able to extract barcodes, but not for all images (I mean, if the image quality is a little poor.).

My question is: what is the most preferred image format for reading barcodes? JPEG or PNG? I am currently trying to use JPEG images.

And one more question: what is the most reliable java API / SDK for extracting barcodes from images. I already tried Accusoft , DataSymbol , AtalaSoft , j4l , which are paid versions. And went through several open sources, such as the Ron Cemer JavaBar . But still I'm looking for a JAVA API / SDK that gives accurate results when reading a barcode.

Your information on the Barcode Reader JAVA API / SDK would be really helpful to me.

+6
source share
4 answers

@Tom Setzer is a great solution if you don't mind paying a little more for your project. However, if you do not have a budget for such software, I still recommend listening to Tom's answer.

One way to improve the results is some image processing before sending it to the engine. Try scaling the image before moving from gray / color to black and white. Better binarization (gray to b & w) than what is provided in the engine can also help.

He's right, but I'm still using ZXing. It only works fine if you do some image processing before trying to read the barcode.

I use OpenCV for image processing. An excellent native library that works for both Linux and Windows, and possibly for some other platforms (have not studied this).

So I do it.

  • Convert an image to grayscale.
  • Resize the barcode up to 4 times in height and 8 times in width.
  • Apply a Gaussian blur of 17x17 pixels.
  • Apply a binary threshold with a threshold value of 225 and a maximum value of 255.

After completing these steps, you will get better results.


Resources

+1
source

JavaBar is another thing you can consider open source and has good reviews.

0
source

I have recently found this zbar software that has yielded promising results when reading barcodes. It has the ability to decode a barcode from the command line. Since this is not an SDK or API. So, I did a trick to read barcodes from an image using a java program.

import java.io.*; public class BarCodeReader { public static void main(String args[]) { try { Process p=Runtime.getRuntime().exec("C:/Program Files/ZBar/bin/zbarimg D:/jpeg/006.jpg"); p.waitFor(); BufferedReader reader=new BufferedReader( new InputStreamReader(p.getInputStream()) ); String line=reader.readLine(); while(line!=null) { System.out.println(line); line=reader.readLine(); } } catch(IOException e1) {} catch(InterruptedException e2) {} System.out.println("Done"); } } 

Hope this can be useful for anyone trying to read the barcode from an image in JAVA.

Note: it also works for Linux. I tested it. For linux environment you only need to execute this command.

sudo apt-get install zbar-tools

and in a Java program, change your code as follows:

 Process p=Runtime.getRuntime().exec("zbarimg /opt/images/006.jpg");// your file path. 

And it works very well.

If you guys come across any other barcode reading SDK or API or software that can run on the command line, please leave a response.

0
source

JPEG - lossy compression and, depending on the compression level, image resolution and image quality (lighting, contrast, etc.), artifacts represented by JPEG compression can interfere with reading the barcode.

Lossless PNG. This will lead to a larger file, but will not add additional problems (artifacts) for reading the barcode.

For the accuracy of barcode engines, this varies greatly. Some engines work better on certain types of barcodes (for example, code 128 against a QR code) and on image quality problems (low resolution and poor contrast). If you have a lot of problems with image quality because you cannot control the source of the images, you will most likely have to go with a commercial engine to achieve the best results.
One way to improve the results is some image processing before sending it to the engine. Try scaling the image before moving from gray / color to black and white. Better binarization (gray to b & w) than what is provided in the engine can also help.

Full disclosure, I work for Accusoft, a barcode SDK provider.

0
source

Source: https://habr.com/ru/post/957727/


All Articles