Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pyzbar not detecting Code93 barcodes

Tags:

python

linux

zbar

I'm trying to use the library to decode Code93 barcodes but the library is not being able to detect it. I looked at the source code and apparently it's able to scan this type of barcode. Is there something wrong with my environment or the way I'm using the library?

I am using the version 0.1.8 of pyzbar along with python 3.7.3 and load using:

from pyzbar import pyzbar
from pyzbar.pyzbar import ZBarSymbol

barcodes = pyzbar.decode(cv2.imread(pic_path), symbols=[ZBarSymbol.CODE93])

The image I am using:

enter image description here

I know this is detectable because this website can read normally.

enter image description here

like image 283
denisb411 Avatar asked Apr 28 '26 12:04

denisb411


1 Answers

You're using the library OK, but your image needs some pre-processing to make the bar-code readable. You need to increase the contrast between the black and white bars, which can be done using a threshold filter to binarize the image before passing it to pyzbar. This example, using the OpenCV library, worked for me with your sample image:

import cv2
from pyzbar.pyzbar import decode
from pyzbar.pyzbar import ZBarSymbol

pic_path = "UNENg.png"
# preprocessing using opencv
im = cv2.imread(pic_path, cv2.IMREAD_GRAYSCALE)
ret, bw_im = cv2.threshold(im, 127, 255, cv2.THRESH_BINARY)
# zbar
barcodes = decode(bw_im, symbols=[ZBarSymbol.CODE93])

There are some alternative pre-processing methods in the answer to Preprocessing images for QR detection in python which might also be helpful.

like image 69
JRI Avatar answered May 01 '26 02:05

JRI



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!