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


Python zbar.Image方法代碼示例

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


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

示例1: get_qrcode_data

# 需要導入模塊: import zbar [as 別名]
# 或者: from zbar import Image [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 Image [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 Image [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 Image [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 Image [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 Image [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: get_ss_shadowsocks8

# 需要導入模塊: import zbar [as 別名]
# 或者: from zbar import Image [as 別名]
def get_ss_shadowsocks8(r):
    shadowsocks8_list = [
        r.url + 'images/server01.png',
        r.url + 'images/server02.png',
        r.url + 'images/server03.png'
    ]
    Ss_users = []
    Ss_passwds = []
    Ss_ports = []
    Ss_Encs = []
    for x in shadowsocks8_list:
        try:
            pass
            # qrstr = decode_qr(x)  # ??????????
            req = requests.get(x)
            fimg = cStringIO.StringIO(req.content)
            img = Image.open(fimg).convert('L')
            qrstr = decode_zbar(img)
            arr = qrstr.split(':')
            Ss_Encs.append(arr[0])
            Ss_passwds.append(arr[1].split('@')[0])
            Ss_users.append(arr[1].split('@')[1])
            Ss_ports.append(arr[2])
        except Exception as e:
            continue
    load_Sslist(Ss_users, Ss_passwds, Ss_ports, Ss_Encs) 
開發者ID:luxux,項目名稱:spider,代碼行數:28,代碼來源:AutoSs.py

示例8: _haarcascade

# 需要導入模塊: import zbar [as 別名]
# 或者: from zbar import Image [as 別名]
def _haarcascade(image, filename, directory=None, **kwargs):
        """
        Use OpenCV's haarcascade classifiers to detect certain features.

        :param image:     Image to use when detecting with the haarcascade.
        :param filename:  The file to create the CascadeClassifier with.
        :param directory: The directory of the haarcascade file.
        :param kwagrs:    Keyword args to pass to cascade's detectMultiScale().
        :return:          List of rectangles of the detected objects. A rect
                          is defined by an array with 4 values i the order:
                          left, top, width, height.
        """
        warn_msg = ('HAAR Cascade analysis requires the optional dependencies '
                    'OpenCV and opencv-data to be installed.')
        try:
            import cv2
        except ImportError:
            logging.warn(warn_msg)
            return []

        haar_paths = [
            os.path.abspath(os.path.join(
                os.path.realpath(cv2.__file__),
                *([os.pardir] * 4 + ['share', 'OpenCV', 'haarcascades']))),
            os.path.abspath(os.path.join(
                os.path.realpath(cv2.__file__),
                *([os.pardir] * 4 + ['share', 'opencv', 'haarcascades'])))]
        for _dir in [directory] + haar_paths:
            if _dir is not None and os.path.exists(_dir):
                directory = _dir
                break
        if directory is None:
            logging.warn(warn_msg)
            return []
        cascade = cv2.CascadeClassifier(os.path.join(directory, filename),)
        features = cascade.detectMultiScale(image, **kwargs)
        return features 
開發者ID:pywikibot-catfiles,項目名稱:file-metadata,代碼行數:39,代碼來源:image_file.py

示例9: post

# 需要導入模塊: import zbar [as 別名]
# 或者: from zbar import Image [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

示例10: fetch

# 需要導入模塊: import zbar [as 別名]
# 或者: from zbar import Image [as 別名]
def fetch(self, key=''):
        if key == 'filename_raster':
            # A raster filename holds the file in a raster graphic format
            return self.fetch('filename')
        elif key == 'filename_zxing':
            return pathlib2.Path(self.fetch('filename_raster')).as_uri()
        elif key == 'ndarray':
            Image.MAX_IMAGE_PIXELS = self.config('max_decompressed_size')
            try:
                image_array = skimage.io.imread(self.fetch('filename_raster'))
                if image_array.shape == (2,):
                    # Assume this is related to
                    # https://github.com/scikit-image/scikit-image/issues/2154
                    return image_array[0]
                return image_array
            except Image.DecompressionBombWarning:
                logging.warn('The file "{0}" contains a lot of pixels and '
                             'can take a lot of memory when decompressed. '
                             'To allow larger images, modify the '
                             '"max_decompressed_size" config.'
                             .format(self.fetch('filename')))
                # Use empty array as the file cannot be read.
                return numpy.ndarray(0)
        elif key == 'ndarray_grey':
            with warnings.catch_warnings():
                warnings.simplefilter("ignore")
                return skimage.img_as_ubyte(
                    skimage.color.rgb2grey(self.fetch('ndarray')))
        elif key == 'ndarray_hsv':
            with warnings.catch_warnings():
                warnings.simplefilter("ignore")
                return skimage.img_as_ubyte(
                    skimage.color.rgb2hsv(self.fetch('ndarray_noalpha')))
        elif key == 'ndarray_noalpha':
            if self.is_type('alpha'):
                return self.alpha_blend(self.fetch('ndarray'))
            return self.fetch('ndarray')
        elif key == 'pillow':
            pillow_img = Image.open(self.fetch('filename_raster'))
            self.closables.append(pillow_img)
            return pillow_img
        return super(ImageFile, self).fetch(key) 
開發者ID:pywikibot-catfiles,項目名稱:file-metadata,代碼行數:44,代碼來源:image_file.py


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