Skip to content

Commit 7528209

Browse files
authored
Create barcode_scanner.py
1 parent b9b11c4 commit 7528209

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

barcode_scanner/barcode_scanner.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from pyzbar.pyzbar import decode
2+
from glob import glob
3+
import cv2
4+
5+
6+
def barcode(decoded, image):
7+
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)
8+
return imge
9+
10+
def scan(image):
11+
dcode = decode(image)
12+
for obj in dcode:
13+
print("Given barcode:", obj)
14+
image = barcode(obj, image)
15+
print("Barcode Type:", obj.type)
16+
print("Scanned Data:", obj.data)
17+
print()
18+
return image
19+
20+
dat = input("Enter the path of the barcode")
21+
data = glob(dat)
22+
for code in data:
23+
img = cv2.imread(code)
24+
img = scan(img)
25+
cv2.imshow("img", img)
26+
cv2.waitKey(0)

0 commit comments

Comments
 (0)