dbr 版本为dbr-7.6.1-cp38-cp38-win_amd64.whl 识别比较好的版本 pyzbar 版本为pyzbar-0.1.8-py2.py3-none-win_amd64.whl # ****************************条码解析识别***************************** from dbr import * from pyzbar import pyzbar import cv2 import numpy as np from datetime import datetime testdate = datetime.now().strftime('%Y%m%d') def synctime(testdate): year=int(testdate[:4]) month=int(testdate[4:6]) day=int(testdate[6:8]) os.system('date %d-%d-%d'%(year,month,day)) # dbr解析图片条码 def read_dbr(test_pic): reader = BarcodeReader() # DBR 试用key,试用期30天 # 试用时将电脑时间更改为安装DBR的初始时间,防止过期 reader.init_license( "t0068MgAAACGuAdndQ2rd3So2yZZr57l4NkJaDYw/c/pyy3rX9XGkmtoig+P/CmfsV0CTg7mEVwLHQz1XRtmxl/i4LYhNaIk=") os.system('date 2020-12-25') text_results = reader.decode_file(test_pic) synctime(testdate) if text_results != None: for text_result in text_results: print( "Barcode Format :" + text_result.barcode_format_string + "," + "Barcode Text :" + text_result.barcode_text) return text_result.barcode_text return False # pyzbar解析图片条码 def read_pyzbar(test_pic): image = cv2.imread(test_pic) barcodes = pyzbar.decode(image) # 判断原图能否解析到条码 if barcodes != None: for barcode in barcodes: barcodeData = barcode.data.decode("utf-8") barcodeType = barcode.type print("[INFO] Found {} barcode: {}".format(barcodeType, barcodeData)) return barcodeData # 当原图解析不到条码时对原图进行卷积运算,变换更清晰 kernel = np.array([[0, -1, 0], [-1, 5, -1], [0, -1, 0]], np.float32) dst = cv2.filter2D(image, -1, kernel=kernel) barcodes1 = pyzbar.decode(dst) if barcodes1 != None: for barcode in barcodes1: barcodeData = barcode.data.decode("utf-8") barcodeType = barcode.type print("[INFO] Found {} barcode: {}".format(barcodeType, barcodeData)) return barcodeData return False def dir_filename(): imgpath1 = r'C:\Users\Micheal_Ma\Desktop\tt\23943931Q0481.jpg' imgpath = r'C:\Users\Micheal_Ma\Desktop\tt\23864416Q0159.jpg' # paths = os.listdir(r'E:\LED') # # paths = os.listdir(r'C:\Users\UX5401EA\Desktop\RFID') # for pic in paths: # print(r'C:\Users\UX5401EA\Desktop\RFID'+"\\"+pic) # read_pyzbar(r'E:\LED'+"\\"+pic) read_pyzbar(imgpath) # read_dbr(imgpath1) if __name__ == '__main__': dir_filename()
python条码识别,dbr,pyzbar
最新推荐文章于 2024-09-13 22:26:12 发布