Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read barcode from an image in JAVA

Tags:

java

image

I have a java application which requires to read bar-code from an image to java program. I was very impressed with zxing library which is able to retrieve bar-codes, But not for all the images(I mean if the image quality is slightly poor.).

My question is, What is the most preferable image format to read bar-codes? JPEG or PNG? I'm currently trying JPEG images.

And another question, What is the most reliable java API/SDK to retrieve bar-codes from images. I already tried, Accusoft, DataSymbol, AtalaSoft, j4l which are paid versions. And have gone through few open sources like Ron Cemer JavaBar. But still I'm looking for a JAVA API/SDK which gives accurate results in bar-code reading.

Your information regarding Barcode Reader JAVA APIs/SDKs would be really helpful for me.

like image 711
chaitanya89 Avatar asked Nov 09 '13 09:11

chaitanya89


1 Answers

@Tom Setzer's solution is great if you don't mind paying a little extra for your project. However, if you don't have the budget to get such software, I'd still recommend to listen to Tom's answer.

One option for improving results is some image processing prior to sending into the engine. Try to scale the image up prior to going from Gray/Color to Black and White. A 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 works great only if you do some image processing before you attempt to read the barcode.

I'm using OpenCV for image processing. A great native library that works both for Linux and Windows and probably some other platforms as well (haven't looked into that).

This is the way I do it.

  1. Convert to the image to grayscale.
  2. Resize barcode up to 4 times in height and 8 times in width.
  3. Apply gaussian blur with the size of 17x17 pixels.
  4. Apply binary threshold with the threshold value of 225 and maximum value of 255.

After following these steps, you'd be getting better results.


Resources:

  • http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_morphological_ops/py_morphological_ops.html
  • http://docs.opencv.org/trunk/d7/d4d/tutorial_py_thresholding.html
  • http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_canny/py_canny.html
  • http://www.bogotobogo.com/python/OpenCV_Python/python_opencv3_Image_Global_Thresholding_Adaptive_Thresholding_Otsus_Binarization_Segmentations.php
  • http://www.pyimagesearch.com/2014/11/24/detecting-barcodes-images-python-opencv
like image 109
kevto Avatar answered Oct 12 '22 12:10

kevto