Skip to content

Commit 11f98e6

Browse files
authored
Merge pull request #864 from palanioffcl/main
Barcode Scanner
2 parents 30b4d02 + 9267363 commit 11f98e6

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

barcode_scanner/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Barcode Scanner
2+
3+
## About:
4+
A simple Barcode Scanner using cv2 with python
5+
6+
## requirements:
7+
* <code>pip install -r requirements.txt</code>
8+
9+
## usage:
10+
python barcode_scanner.py
11+
12+
* Enter the path the barcode to be scanned with extension:

barcode_scanner/barcode_scanner.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/python
2+
from pyzbar.pyzbar import decode
3+
from glob import glob
4+
import cv2
5+
6+
7+
def barcode(decoded, image):
8+
imge = cv2.rectangle(image, (decoded.rect.left, decoded.rect.top),
9+
(decoded.rect.left + decoded.rect.width,
10+
decoded.rect.top + decoded.rect.height),
11+
color=(0, 255, 0), thickness=5)
12+
return imge
13+
14+
15+
def scan(image):
16+
dcode = decode(image)
17+
for obj in dcode:
18+
print('Given barcode:', obj)
19+
image = barcode(obj, image)
20+
print('Barcode Type:', obj.type)
21+
print('Scanned Data:', obj.data)
22+
print()
23+
return image
24+
25+
26+
dat = input('Enter the path of the barcode')
27+
data = glob(dat)
28+
for code in data:
29+
img = cv2.imread(code)
30+
img = scan(img)
31+
cv2.imshow('img', img)
32+
cv2.waitKey(0)

barcode_scanner/requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
opencv-python==4.6.0.66
2+
pyzbar==0.1.9

0 commit comments

Comments
 (0)