Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I Detect an EAN-13 +5 Supplement Barcode Using Python or NodeJS

I'm trying to find a way to get the UPC plus the 5 number supplement barcode using Python or NodeJS.

So far I've tried using pyzbar in Python via this code.

 img = Image.open(requests.get(url, stream=True).raw)
 img = ImageOps.grayscale(img)
 results = decode(img)

That only returns the main UPC code. Not the supplemental code.

This is an example of an image I'm trying to read this from.

enter image description here

like image 952
James Parker Avatar asked Oct 30 '25 04:10

James Parker


1 Answers

Install the dependencies (on mac + python):

$ brew install zbar
$ pip install pyzbar
$ pip install opencv-python

You can define the symbols to ZBar. Please try this python code:

import cv2
import pyzbar.pyzbar as pyzbar
from pyzbar.wrapper import ZBarSymbol

img = cv2.imread('barcode.png')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

barcodes = pyzbar.decode(gray, [ZBarSymbol.EAN13, ZBarSymbol.EAN5])

for barcode in barcodes:
    print('{}: {}'.format(barcode.type, barcode.data))

I've tested it with this image:

enter image description here

The result is:

EAN5: b'07900'
EAN13: b'9791234567896'

(BTW, for your image this code scans just the EAN13 part. Maybe you have to use a bigger image, or increase the contrast)

like image 70
Peter Avatar answered Nov 01 '25 19:11

Peter



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!