當前位置: 首頁>>代碼示例>>Python>>正文


Python zbar.ImageScanner方法代碼示例

本文整理匯總了Python中zbar.ImageScanner方法的典型用法代碼示例。如果您正苦於以下問題:Python zbar.ImageScanner方法的具體用法?Python zbar.ImageScanner怎麽用?Python zbar.ImageScanner使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在zbar的用法示例。


在下文中一共展示了zbar.ImageScanner方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_qrcode_data

# 需要導入模塊: import zbar [as 別名]
# 或者: from zbar import ImageScanner [as 別名]
def get_qrcode_data(image_name):
    '''??qrcode,????zbar'''
    import zbar
    from PIL import Image
    scanner = zbar.ImageScanner()
    scanner.parse_config('enable')
    pil = Image.open(image_name).convert('L')
    width, height = pil.size
    raw = pil.tobytes()
    image = zbar.Image(width, height, 'Y800', raw)
    scanner.scan(image)
    data = ''
    for symbol in image:
        data += symbol.data
    del(image)
    return data 
開發者ID:JingRanCor,項目名稱:python-django-wechat,代碼行數:18,代碼來源:utils.py

示例2: decode_zbar

# 需要導入模塊: import zbar [as 別名]
# 或者: from zbar import ImageScanner [as 別名]
def decode_zbar(qr_img):
    width, height = qr_img.size

    scanner = zbar.ImageScanner()
    scanner.parse_config('enable')
    qrCode = zbar.Image(width, height, 'Y800', qr_img.tobytes())
    scanner.scan(qrCode)
    qr = ""
    for symbol in qrCode:
        qr = symbol.data
    del(qrCode)
    data_qr = base64.b64decode(qr[5:])
    return data_qr 
開發者ID:luxux,項目名稱:spider,代碼行數:15,代碼來源:AutoSs.py

示例3: decode

# 需要導入模塊: import zbar [as 別名]
# 或者: from zbar import ImageScanner [as 別名]
def decode(self, filename=None):
        self.filename = filename or self.filename
        if self.filename:
            scanner = zbar.ImageScanner()
            # configure the reader
            scanner.parse_config('enable')
            # obtain image data
            pil = Image.open(self.filename).convert('L')
            width, height = pil.size
            try:
                raw = pil.tobytes()
            except AttributeError:
                raw = pil.tostring()
            # wrap image data
            image = zbar.Image(width, height, 'Y800', raw)
            # scan the image for barcodes
            result = scanner.scan(image)
            # extract results
            if result == 0:
                return False
            else:
                for symbol in image:
                    pass
                # clean up
                del(image)
                # Assuming data is encoded in utf8
                self.data = symbol.data.decode(u'utf-8')
                self.data_type = self.data_recognise()
                return True
        else:
            return False 
開發者ID:primetang,項目名稱:qrtools,代碼行數:33,代碼來源:qrtools.py

示例4: read_qr_codes

# 需要導入模塊: import zbar [as 別名]
# 或者: from zbar import ImageScanner [as 別名]
def read_qr_codes(image):
        image = image.convert('L')
        width, height = image.size

        raw = img_to_bytes(image)
        zimg = zbar.Image(width, height, 'Y800', raw)

        scanner = zbar.ImageScanner()
        scanner.scan(zimg)

        return [ sym.data for sym in zimg if str(sym.type) == 'QRCODE' ] 
開發者ID:ztp-at,項目名稱:RKSV,代碼行數:13,代碼來源:img_decode.py

示例5: get_QR

# 需要導入模塊: import zbar [as 別名]
# 或者: from zbar import ImageScanner [as 別名]
def get_QR():
    scanner = zbar.ImageScanner()
    scanner.parse_config("enable")
    pil = Image.open(pic_url).convert('L')
    width, height = pil.size
    raw = pil.tostring()
    image = zbar.Image(width, height, 'Y800', raw)
    scanner.scan(image)
    data = ''
    for symbol in image:
        data+=symbol.data
    del(image)
    return data 
開發者ID:jetty-guo,項目名稱:python_learn,代碼行數:15,代碼來源:test9.py

示例6: analyze_barcode_zbar

# 需要導入模塊: import zbar [as 別名]
# 或者: from zbar import ImageScanner [as 別名]
def analyze_barcode_zbar(self):
        """
        Use ``zbar`` to find barcodes and qr codes from the image.

        :return: dict with the keys:

             - zbar:Barcodes - An array containing information about barcodes.
                Each barcode is encoded to a dictionary with the keys:
                - format - The format of the barcode. Example: QRCODE,
                    I25, etc.
                - data - The text data that is encdoded in the barcode.
                - bounding box - A dictionary with left, width, top, height.
                - confidence - The quality of the barcode. The higher it is
                    the more accurate the detection is.
        """
        image_array = self.fetch('ndarray_grey')
        if image_array.ndim == 3:
            logging.warn('Barcodes cannot be detected in animated images '
                         'using zbar.')
            return {}
        height, width = image_array.shape
        zbar_img = zbar.Image(width, height, 'Y800', image_array.tobytes())
        scanner = zbar.ImageScanner()
        scanner.parse_config('enable')
        if scanner.scan(zbar_img) == 0:
            return {}

        barcodes = []
        for barcode in zbar_img:
            p = numpy.array(barcode.location)
            bbox = {"left": min(p[:, 0]), "top": min(p[:, 1]),
                    "width": max(p[:, 0]) - min(p[:, 0]),
                    "height": max(p[:, 1]) - min(p[:, 1])}
            barcodes.append({'data': barcode.data,
                             'bounding box': bbox,
                             'confidence': barcode.quality,
                             'format': str(barcode.type)})
        return {'zbar:Barcodes': barcodes} 
開發者ID:pywikibot-catfiles,項目名稱:file-metadata,代碼行數:40,代碼來源:image_file.py

示例7: post

# 需要導入模塊: import zbar [as 別名]
# 或者: from zbar import ImageScanner [as 別名]
def post(self):
        name = self.request.arguments.get('name')[0]
        post_type = self.request.arguments.get('type')[0]
        if int(post_type) == LINK_TYPE:
            data = self.request.arguments.get('info')[0]
            url = add_http(data.decode("utf-8"))
        else:
            b64img = self.request.arguments.get('image')[0]
            img = BytesIO(base64.b64decode(b64img))
            scanner = zbar.ImageScanner()
            scanner.parse_config('enable')
            pil = Image.open(img).convert('L')
            width, height = pil.size
            raw = pil.tobytes()
            image = zbar.Image(width, height, 'Y800', raw)
            scanner.scan(image)
            for symbol in image:
                url = add_http(symbol.data)

        cur_user = self.get_current_user()
        if cur_user:
            users = self.db[USER_COLLECTION]
            users.update({'phone': cur_user['phone']}, {'$addToSet': {'qrcode': url}})
        stat_col = self.db[STATISTIC_COLLECTION]
        if not stat_col.find_one({'url': url}):
            stat_col.insert({
                'name': name,
                'url': url,
                'visit': []
            })
        else:
            stat_col.update({'url': url}, {"$set": {'name': name}})
        img = qrcode.make(gen_new_url(url))
        o = BytesIO()
        img.save(o, "JPEG")
        s = base64.b64encode(o.getvalue())

        img = qrcode.make(gen_statistic_url(url))
        o = BytesIO()
        img.save(o, "JPEG")
        s2 = base64.b64encode(o.getvalue())

        self.write({
            "qrcode": s.decode('utf-8'),
            "statistic": s2.decode('utf-8')
        }) 
開發者ID:flingjie,項目名稱:qrcode_track,代碼行數:48,代碼來源:handlers.py


注:本文中的zbar.ImageScanner方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。