Skip to content

Barcode Scanner #864

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions barcode_scanner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Barcode Scanner

## About:
A simple Barcode Scanner using cv2 with python

## requirements:
* <code>pip install -r requirements.txt</code>

## usage:
python barcode_scanner.py

* Enter the path the barcode to be scanned with extension:
32 changes: 32 additions & 0 deletions barcode_scanner/barcode_scanner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/python
from pyzbar.pyzbar import decode
from glob import glob
import cv2


def barcode(decoded, image):
imge = cv2.rectangle(image, (decoded.rect.left, decoded.rect.top),
(decoded.rect.left + decoded.rect.width,
decoded.rect.top + decoded.rect.height),
color=(0, 255, 0), thickness=5)
return imge


def scan(image):
dcode = decode(image)
for obj in dcode:
print('Given barcode:', obj)
image = barcode(obj, image)
print('Barcode Type:', obj.type)
print('Scanned Data:', obj.data)
print()
return image


dat = input('Enter the path of the barcode')
data = glob(dat)
for code in data:
img = cv2.imread(code)
img = scan(img)
cv2.imshow('img', img)
cv2.waitKey(0)
2 changes: 2 additions & 0 deletions barcode_scanner/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
opencv-python==4.6.0.66
pyzbar==0.1.9