Пример #1
0
 def scan(self):
     box = self.detect(frame)  # 调用detect()函数来查找二维码返回二维码的位置
     # print(box)
     # 这下面的3步得到扫描区域,扫描区域要比检测出来的位置要大
     if check == True:
         min = np.min(box, axis=0)
         max = np.max(box, axis=0)
         roi = frame[min[1] - 10:max[1] + 10, min[0] - 10:max[0] + 10]
         # 把区域里的二维码传换成RGB,并把它转换成pil里面的图像,因为zbar得调用pil里面的图像,而不能用opencv的图像
         # roi = cv2.cvtColor(roi, cv2.COLOR_BGR2RGB)
         # cv2.imshow("roi",roi)
         # print(roi.shape)
         if roi.any() != 0:
             barcodes = pyzbar.decode(roi)
             for barcode in barcodes:
                 # 提取条形码的边界框的位置
                 # 画出图像中条形码的边界框
                 # (x, y, w, h) = barcode.rect
                 # cv2.rectangle(roi, (x, y), (x + w, y + h), (0, 0, 255), 2)
                 # 条形码数据为字节对象,所以如果我们想在输出图像上
                 # 画出来,就需要先将它转换成字符串
                 barcodeData = barcode.data.decode("utf-8")
                 barcodeType = barcode.type
                 # 向终端打印条形码数据和条形码类型
                 print("[INFO] Found {} barcode: {}".format(
                     barcodeType, barcodeData))
                 return roi
def qrcode_decode(path):
    """二维码识别

    :param path: 二维码图片路径
    :return: 返回识别结果
    """
    results = pyzbar.decode(Image.open(path),
                            symbols=[pyzbar.ZBarSymbol.QRCODE])
    return results[0].data.decode("utf-8")
Пример #3
0
def read_barcodes(frame):
    global barcode_text
    barcodes = pyzbar.decode(frame)
    for barcode in barcodes:
        x, y, w, h = barcode.rect
        barcode_text = barcode.data.decode('utf-8')
        print(type(barcode_text))
        cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
    return frame, barcode_text
Пример #4
0
def decode_qr_bar_code(path):
    """ return Decoded class """

    # validation
    if type(path) != str:
        path = str(path)
    if not is_file(path):
        raise NotAFileError
    # /validation

    img = cv2.imread(path)
    decoded = pyzbar.decode(img)
    return decoded
Пример #5
0
    def scanCode(self):

        pwd = self.returnPassword()
        self.con = sql.connect('localhost', 'root', pwd, 'bill')
        self.cur = self.con.cursor()
        self.cur1 = self.con.cursor()

        vs = VideoStream(src=0).start()
        time.sleep(2.0)

        while True:

            frame = vs.read()
            frame = imutils.resize(frame, width=400)
            QRcodes = pyzbar.decode(frame)

            for QRcode in QRcodes:

                (x, y, w, h) = QRcode.rect
                cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2)
                QRcodeData = QRcode.data.decode("utf-8")

                text = "{}".format(QRcodeData)
                cv2.putText(frame, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX,
                            0.5, (0, 0, 200), 2)

                text = text.split(',')
                pName = text[0]
                pPrice = text[1]

            cv2.imshow("Press 'Q' to exit", frame)
            key = cv2.waitKey(1) & 0xFF

            if key == ord("q"):
                break

        cv2.destroyAllWindows()
        vs.stop()

        try:
            self.cur.execute(
                '''insert into purchase (pName, pPrice) values (%s,%s)''',
                (pName, pPrice))
            self.con.commit()
            self.cur1.execute('''select sum(pPrice) from purchase''')
            total = self.cur1.fetchone()
            self.label_21.setText('Total amount: ' + str(total[0]))
            self.statusBar().showMessage('Item added to cart')
            self.showBill()
        except:
            self.statusBar().showMessage('Unable to add item to bill')
def process(img):
    """ Detect QR code and barcode in the image.

    @param img (numpy.ndarray): the image to be processed.
    @return (list): a list containing all the features detected.
    """
    # Find barcodes and QR codes
    objects = pyzbar.decode(img)

    for obj in objects:
        print("=" * 24)
        print(obj.rect)
        print("Type:", obj.type)
        print("Data:", obj.data, "\n")

    return objects
Пример #7
0
 def decodeDisplay(image):
     barcodes = pyzbar.decode(image)
     for barcode in barcodes:
         # 提取二维码的边界框的位置
             #  画出图像中条形码的边界框
         (x, y, w, h) = barcode.rect
         cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 2)
        # 提取二维码数据为字节对象,所以如果我们想在输出图像上
         #画出来,就需要先将它转换成字符串
         barcodeData = barcode.data.decode("utf-8")
         barcodeType = barcode.type         #
        # 绘出图像上条形码的数据和条形码类型
         text = "{} ({})".format(barcodeData, barcodeType)
         cv2.putText(image, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX,
                     .5, (0, 0, 125), 2)         # 向终端打印条形码数据和条形码类型
         print("[INFO] Found {} barcode: {}".format(barcodeType, barcodeData))
Пример #8
0
def aadhar(image_cropped):  # if input here only doc name
    blur = cv2.GaussianBlur(image_cropped, (5, 5), 0)
    ret, inverted = cv2.threshold(blur, 127, 255, cv2.THRESH_BINARY)
    img_1 = Image.fromarray(inverted)
    barcodes = ""
    try:
        barcodes = pyzbar.decode(img_1)
    except:
        pass

    if len(barcodes) > 0:
        # get barcode mask here function
        # mask_from_qrcode(img, PDF_file, barcodes)

        lst = barcodes[0].data.decode("utf-8")
        try:
            doc = xml.dom.minidom.parseString(lst)
            kl = doc.firstChild
            # co
            add = kl.getAttribute("co") + " " + kl.getAttribute("house") + " " + kl.getAttribute(
                "street") + " " + kl.getAttribute("lm") + " " + \
                  kl.getAttribute("loc") + " " + kl.getAttribute("vtc") + \
                  " " + kl.getAttribute("po") + " " + kl.getAttribute("dist") + \
                  " " + kl.getAttribute("subdist") + " " + kl.getAttribute("state") + " pincode: " + kl.getAttribute(
                "pc")
            # print(kl.getAttribute("uid"))
            # print(kl.getAttribute("yob"))
            # print(add)
            # print(kl.getAttribute("name"))
            print("Male" if kl.getAttribute("gender") == 'M' else "Female")
            # create_update_adhar(PDF_file, adhaar_no=kl.getAttribute("uid"))
            # create_update_adhar(PDF_file, birth_year=kl.getAttribute("yob"))
            # create_update_adhar(PDF_file, address=add)
            # create_update_adhar(PDF_file, name=kl.getAttribute("name"))
            # create_update_adhar(PDF_file, Sex="Male" if kl.getAttribute("gender") == 'M' else "Female")
            m = model.KYCDocument()
            m.adhaar_num = kl.getAttribute("uid")
            m.is_adhaar_name = kl.getAttribute("name")
            m.is_adhaar_dob = kl.getAttribute("yob")
            m.is_adhaar_address = add
            m.is_adhaar_gender = "Male" if kl.getAttribute("gender") == 'M' else "Female"
            return m
        except:
            pass

    return barcodes
Пример #9
0
    def detect_barcode(self, frame):
        barcodes = pyzbar.decode(frame)

        for barcode in barcodes:
            # extract the bounding box location of the barcode and draw the
            # bounding box surrounding the barcode on the image
            (x, y, w, h) = barcode.rect
            cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2)
            # the barcode data is a bytes object so if we want to draw it on
            # our output image we need to convert it to a string first
            barcodeData = barcode.data.decode("utf-8")
            barcodeType = barcode.type
            # draw the barcode data and barcode type on the image
            text = "{} ({})".format(barcodeData, barcodeType)
            cv2.putText(frame, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX,
                        0.5, (0, 0, 255), 2)
            # print the barcode type and data to the terminal
            print("[INFO] Found {} barcode: {}".format(barcodeType,
                                                       barcodeData))
            self.add_attendence_item(barcodeType, barcodeData)
        return frame
Пример #10
0
    def read_barcodes(self, frame):
        barcodes = pyzbar.decode(frame)
        for barcode in barcodes:
            x, y, w, h = barcode.rect

            barcode_info = barcode.data.decode('utf-8-sig')
            cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)

            font = cv2.FONT_HERSHEY_DUPLEX
            cv2.putText(frame, barcode_info, (x + 6, y - 6), font, 2.0,
                        (255, 255, 255), 1)

            with open("posleden_barkod.dat", mode='w') as file:
                file.write(barcode_info)
            sk_barcode_info = barcode_info.split('*')

            self.data_vyv.text = sk_barcode_info[2]
            self.razhodi_vyv.text = sk_barcode_info[4]
            self.dr1_vyv.text = sk_barcode_info[0]
            self.dr2_vyv.text = sk_barcode_info[1]
        return frame
Пример #11
0
 def decode_qrcode(self, qr_img_path):
     if not os.path.exists(qr_img_path):
         raise FileExistsError(qr_img_path)
     return pyzbar.decode(Image.open(qr_img_path),
                          symbols=[pyzbar.ZBarSymbol.QRCODE])
Пример #12
0
            cv2.line(im, hull[j], hull[(j + 1) % n], (255, 0, 0), 3)

    # Display results
    # cv2.imshow("Results", im);


# Create a qrCodeDetector Object
qrDecoder = cv2.QRCodeDetector()

# Detect and decode the qrcode
t = time.time()
while (1):
    hasFrame, inputImage = cap.read()
    if not hasFrame:
        break
    decodedObjects = pyzbar.decode(inputImage)
    if len(decodedObjects):
        zbarData = decodedObjects[0].data
    else:
        zbarData = ''
    opencvData, bbox, rectifiedImage = qrDecoder.detectAndDecode(inputImage)
    if zbarData:
        cv2.putText(inputImage, "ZBAR : {}".format(zbarData), (10, 50),
                    cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2, cv2.LINE_AA)
    else:
        cv2.putText(inputImage, "ZBAR : QR Code NOT Detected", (10, 50),
                    cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
    if opencvData:
        cv2.putText(inputImage, "OpenCV:{}".format(opencvData), (10, 150),
                    cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2, cv2.LINE_AA)
    else:
Пример #13
0
def current_map(Qmap):
    # algorithm to navigate in the qmap
    speak('What is your destination.')
    listen()
    
locations = {1001: 'Welcome to techienest',
             1002: 'Welcome Home'}
loadmap = {'Welcome to techienest':np.zeros((10,10)),# Qmap of techienest
           'Welcome Home':np.zeros((10,10))} # Qmap of home

cap = cv2.VideoCapture(0)
while(1):
    camera_check, frame = cap.read()
    if camera_check == True:
        # check for any QR codes in image
        decodedobjects = pyzbar.decode(frame)
        for obj in decodedobjects:
            data = (obj.data).decode('utf-8)
            if data in locations.keys():
                speak(locations[data])
                current_map(loadmap[locations[data]])
    else:
        # speak the camera is not available please take some assistant
        speak('Camera is not available. Please contact someone for assistant.')
        cap.release()
        break
    
    # replace it with voice command in future
    k = cv2.waitKey(2)
    if k == ord('q')|k == ord('Q'):
        speak('Bye, have a greate journey.')