python条码识别,dbr,pyzbar

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()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值