用pyzbar检查纠正性QR码扫描仪

时间:2018-07-31 09:11:44

标签: python-3.x

我想通过确认3次来检查QR码数据是否正确。 我比较了新的QR码数据和保存的QR码数据,但事实并非如此。 这是我的代码:

from __future__ import print_function
import pyzbar.pyzbar as pyzbar
import numpy as np
import cv2
import simplejson as json
import os


def decode(im):
    # Find barcodes and QR codes
    decodedObjects = pyzbar.decode(im)
    return decodedObjects

# Read image
cap = cv2.VideoCapture(0)

c = 0
while (True):
    # Capture frame-by-frame
    ret, im = cap.read()

    #Decode QR
    decodedObjects = decode(im)

    #check QR
    if os.path.isfile("QR.json") and decodedObjects != [] and os.stat("QR.json").st_size != 0 :
        for obj in decodedObjects:
            QRdata = obj.data

        QRc = open("QR.json", "r+")
        QRcdata = json.loads(QRc.read())
        QRc.close()
        print(QRcdata)
        if QRcdata == QRdata:
            c = c + 1
            print("confirm ", QRdata, " : ", c)

        else:
            c = 0
            print("reset , ", c)
            QR = open("QR.json", "w+")
            data = QRdata
            QR.seek(0)
            QR.write(json.dumps(data))
            QR.close()
            print("saved new QR ", QRdata)

    elif decodedObjects != [] :
        for obj in decodedObjects:
            QRdata = obj.data

        QR = open("QR.json", "w+")
        data = QRdata
        QR.seek(0)
        QR.write(json.dumps(data))
        QR.close()
        print("saved new QR ", QRdata)


    # Display the resulting frame
    cv2.imshow("Results", im)

    # press "q" to exit
    if cv2.waitKey(1) & 0xFF == ord('q') or c == 3:
        break

运行时。它的QR数据为“ b'QRCodedata'”,但在文件中为“ QRCodedata”。 我如何在“ QRCodedata”的fornt中删除“ b”。 感谢您的帮助!

0 个答案:

没有答案