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