forked from its-sushant/Qrscanner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadbc.py
More file actions
56 lines (38 loc) · 1.17 KB
/
readbc.py
File metadata and controls
56 lines (38 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# import the necessary packages
import os
import sys
import cv2
from pyzbar.pyzbar import decode
# Function to load image from the folder
def load_images_from_folder(folder):
images = []
for filename in os.listdir(folder):
img = os.path.join(folder, filename)
if img is not None:
images.append(img)
return images
# Function to detect barcode from the file
def BarcodeReader(image):
img = cv2.imread(image)
detectedBarcodes = decode(img)
if not detectedBarcodes:
return None
else:
for barcode in detectedBarcodes:
if barcode.data != "":
return barcode.data, barcode.type
def write_text_file(path, file, barcode, type):
newline = path + ',' + '' + str(type) + ':' + str(barcode) + '\n'
file.write(newline)
def main():
folder = sys.argv[1]
eancode = sys.argv[2]
images = load_images_from_folder(folder)
file = open(eancode, 'w')
for image in images:
path = os.path.basename(os.path.normpath(image))
barcode, type = BarcodeReader(image)
write_text_file(path, file, barcode, type)
file.close()
if __name__ == "__main__":
main()