我正致力于为Ubuntu和Windows构建可执行的python(2.7)脚本,其中脚本读取和解码QR码。我使用Opencv和pyzbar模块来运行它。我在使用PyInstaller时遇到问题,因为它无法识别opencv,因此可执行文件无法运行。
import cv2
import os
import numpy as np
import pyzbar.pyzbar as pyzbar
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--img", type = str, required=True)
parser.add_argument("--type", type = str, default = "Aadhaar")
args = parser.parse_args()
#image = cv2.imread(args.img)
#cv2.imshow("Image", image)
#cv2.waitKey(0)
#cv2.destroyAllWindows
def decode(im) :
# Find barcodes and QR codes
decodedObjects = pyzbar.decode(im)
# Print results
if decodedObjects:
return decodedObjects
else:
return None
def Aadhaar(file_path):
image = cv2.imread(file_path)
kernel = np.zeros( (9,9), np.float32)
kernel[4,4] = 2.0 #Identity, times two!
#Create a box filter:
boxFilter = np.ones( (9,9), np.float32) / 81.0
#Subtract the two:
kernel = kernel - boxFilter
image = cv2.filter2D(image, -1, kernel)
decodedObjects = decode(image)
if decodedObjects:
k = 0
for obj in decodedObjects:
k += 1
#data = ET.fromstring(obj.data)
print("Aadhaar: ", obj.data)
if k > 0:
break
else:
print("No QR cde found")
if args.type == "Aadhaar":
Aadhaar(args.img)