How can I improve detection on this image? Contains a Code128.

Skip to first unread message


Apr 8, 2019, 8:23:16 AM4/8/19
to zxing
Hi there,

Having a hard time finding enough information so thought I'd reach out to the group.

The barcode inside the attached image can't be detected by my current usage of zxing - I've configured it to use a BufferedImageLuminanceSource, HybridBinarizer and GenericMultipleBarcodeReader with the TRY_HARDER hint enabled.

A few things I notice about the issue:
* A lot of background noise / speckling
* Barcode lines are somewhat speckled as well

But otherwise feels like something zxing should be able to decode

I've tried applying a gaussian blur before processing to no avail.

Does anybody notice something in particular about the image that might make it difficult to detect, tips on what to try next, or suggestions for how best to approach debugging this?

Screen Shot 2019-04-08 at 8.57.42 pm.png


Apr 8, 2019, 8:42:45 AM4/8/19
to zxing

Had some success scaling the image 4x w/ PDFBox which is interesting, I suppose it's very unlikely that 4x is a magic number all cases where this might fail, but if I'll see what happens if I fail to detect a barcode, scale and try again.


Apr 8, 2019, 11:19:50 PM4/8/19
to zxing
The image is very noisy (why ? Maybe clean the scanner ?) I found I could scan it ok when scaled up to fill display on a tablet and using an older version of zxing running on a pixel2 phone, but only if I moved the red scan line up and down to find a least noisy line through the bar code. Pixel phones have a pretty good camera image, try different devices might help but the image noise is the main issue.

Sean Owen

Apr 9, 2019, 8:10:00 PM4/9/19
to zxing
This image has already been (poorly) binarized and has a lot of noise. Try processing an original grayscale image or improve the binarization so that light regions don't have black speckles.


Apr 9, 2019, 10:46:57 PM4/9/19
to zxing
Thanks for the advice folks, much appreciated! - the image was uploaded by a user who reported difficulty scanning for barcodes, not sure what they had done to it beforehand. Have got a feeling that the image was scanned as b&w and the speckled area was a region of blue background.

I've advised that they should clean their scanned, avoid pre-processing the images and upload in colour if possible to avoid any binarisation.

Will also add an extra step into our decode logic to try scaling the image if no barcodes are found!

On Monday, April 8, 2019 at 10:23:16 PM UTC+10, PTeen wrote:

Lachezar Dobrev

Apr 10, 2019, 5:55:25 AM4/10/19
to PTeen, zxing
I've had lots of problems with such. Mostly such images are coming
from multi-purpose scanner+fax+printer combines. Typically they use
these B&W images and even encode them as fax-friendly CCITT or TIFF,
that makes it hard to read into a Buffered Image.
And if the scanned document is a form of some sorts that is not a
white sheet with black ink, you're in trouble. Shaded/Tinted paper
(yellowish, blueish, greenish) or patterned paper (diagonally-striped
for instance) are common, and are extremely hard to process later.

What we did was to instruct the users to scan documents using
grey-scale or colour when scanning the documents. This generally
increases the quality of the image, and allows for variability in
binarisers. If the image is B&W all binarisers end up with the same

Also in the back-end images that fail to scan we carry through a
series of distortions: scaling, blurring, and combinations. These
allow for multiple attempts at the same document, and do increase the
success rate. Blurring and then sharpening may sound stupid, but it
ends up clearing the dithering and patterns most of the time.
> --
> You received this message because you are subscribed to the Google Groups "zxing" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> For more options, visit
Reply all
Reply to author
0 new messages