Foreen
Foreen

Reputation: 399

Pyzbar does not recognize CODE-128 barcode

I am trying to read text encoded in barcode - I am using pyzbar like this:

from pyzbar import pyzbar
import cv2

img = cv2.imread("example/path")
barcodes = pyzbar.decode(img, symbols=[pyzbar.ZBarSymbol.CODE128])

print(barcodes)

It normally works, but in the last batch of barcodes that I have received, pyzbar cannot read them - output of pyzbar.decode is []. There is one example:

enter image description here

I have tried to put it into online decoder and it decodes it just fine (it also says the barcode type is CODE-128). Anybody knows, how can I read it in Python, please?

Upvotes: 2

Views: 1641

Answers (1)

user1196549
user1196549

Reputation:

This picture shows a lot of ringing (contours reinforced in black). That could be the reason for the failure. Try blurring the image before a read. Binarization also works seamlessly.

enter image description here

enter image description here

Upvotes: 2

Related Questions