本文整理汇总了Python中pyzbar.pyzbar.decode方法的典型用法代码示例。如果您正苦于以下问题:Python pyzbar.decode方法的具体用法?Python pyzbar.decode怎么用?Python pyzbar.decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyzbar.pyzbar
的用法示例。
在下文中一共展示了pyzbar.decode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read
# 需要导入模块: from pyzbar import pyzbar [as 别名]
# 或者: from pyzbar.pyzbar import decode [as 别名]
def read(self):
try:
from PIL import Image
from pyzbar.pyzbar import decode
decoded_data = decode(Image.open(self.filename))
if path.isfile(self.filename):
remove(self.filename)
try:
url = urlparse(decoded_data[0].data.decode())
query_params = parse_qsl(url.query)
self._codes = dict(query_params)
return self._codes.get("secret")
except (KeyError, IndexError):
Logger.error("Invalid QR image")
return None
except ImportError:
from ..application import Application
Application.USE_QRSCANNER = False
QRReader.ZBAR_FOUND = False
示例2: read_qr
# 需要导入模块: from pyzbar import pyzbar [as 别名]
# 或者: from pyzbar.pyzbar import decode [as 别名]
def read_qr(wallet):
amount = -1
if wallet.current_balance <= 0:
print("You need some money first")
return None
print("Input filename of QR code: ")
fn = input(prompt)
decoded = decode(Image.open(fn))
puzzlehash = puzzlehash_from_string(decoded[0].data)
while amount > wallet.temp_balance or amount <= 0:
amount = input("Amount: ")
if amount == "q":
return
if not amount.isdigit():
amount = -1
amount = int(amount)
return wallet.generate_signed_transaction(amount, puzzlehash)
示例3: main
# 需要导入模块: from pyzbar import pyzbar [as 别名]
# 或者: from pyzbar.pyzbar import decode [as 别名]
def main(args=None):
if args is None:
args = sys.argv[1:]
parser = argparse.ArgumentParser(
description='Reads barcodes in images, using the zbar library'
)
parser.add_argument('image', nargs='+')
parser.add_argument(
'-v', '--version', action='version',
version='%(prog)s ' + pyzbar.__version__
)
args = parser.parse_args(args)
from PIL import Image
for image in args.image:
for barcode in decode(Image.open(image)):
print(barcode.data)
示例4: run_python_module
# 需要导入模块: from pyzbar import pyzbar [as 别名]
# 或者: from pyzbar.pyzbar import decode [as 别名]
def run_python_module(module, arguments=None):
"""Runs a python module, as though from the command line, and returns the output."""
if re.search(r'\.py$', module):
module = this_thread.current_package + '.' + re.sub(r'\.py$', '', module)
elif re.search(r'^\.', module):
module = this_thread.current_package + module
commands = [re.sub(r'/lib/python.*', '/bin/python3', docassemble.base.ocr.__file__), '-m', module]
if arguments:
if not isinstance(arguments, list):
raise DAError("run_python_module: the arguments parameter must be in the form of a list")
commands.extend(arguments)
output = ''
try:
output = subprocess.check_output(commands, stderr=subprocess.STDOUT).decode()
return_code = 0
except subprocess.CalledProcessError as err:
output = err.output.decode()
return_code = err.returncode
return output, return_code
示例5: print_my_details
# 需要导入模块: from pyzbar import pyzbar [as 别名]
# 或者: from pyzbar.pyzbar import decode [as 别名]
def print_my_details(wallet):
print(f"{informative} Name: {wallet.name}")
print(f"{informative} Pubkey: {hexlify(wallet.get_next_public_key().serialize()).decode('ascii')}")
print(f"{informative} Puzzlehash: {wallet.get_new_puzzlehash()}")
示例6: main
# 需要导入模块: from pyzbar import pyzbar [as 别名]
# 或者: from pyzbar.pyzbar import decode [as 别名]
def main():
fp = 'macbookPro.jpg'
# image = Image.open(fp)
# image.show()
image = cv2.imread(fp)
barcodes = decode(image)
decoded = barcodes[0]
print(decoded)
#
url: bytes = decoded.data
url = url.decode()
print(url)
# rect
rect = decoded.rect
print(rect) # Rect(left=19, top=19, width=292, height=292)
# loop over the detected barcodes
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(image, (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(image, 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))
# show the output image
cv2.imshow("Image", image)
# cv2.imwrite('macbook_qr_rect.jpg', image)
cv2.waitKey(0) # 按任意键退出
示例7: parse_rect_from_png_bytes
# 需要导入模块: from pyzbar import pyzbar [as 别名]
# 或者: from pyzbar.pyzbar import decode [as 别名]
def parse_rect_from_png_bytes(*a):
pixbytes, w, h = screenshot_rect(s)
deco = decode((pixbytes, w, h))
for i in deco:
print(i)
示例8: process_image
# 需要导入模块: from pyzbar import pyzbar [as 别名]
# 或者: from pyzbar.pyzbar import decode [as 别名]
def process_image(self, frame):
decoded_objs = self.decode(frame)
# 認識したQRコードの位置を描画する
# frame = self.draw_positions(frame, decoded_objs)
detected = False
if len(decoded_objs) > 0:
detected = True
cv2.putText(frame, 'Detected: {}'.format(detected), (15, 30), cv2.FONT_HERSHEY_DUPLEX, 0.8, (0, 255, 0), 1)
return frame
示例9: decode
# 需要导入模块: from pyzbar import pyzbar [as 别名]
# 或者: from pyzbar.pyzbar import decode [as 别名]
def decode(self, frame):
decoded_objs = pyzbar.decode(frame, scan_locations=True)
for obj in decoded_objs:
print(datetime.now().strftime('%H:%M:%S.%f'))
print('Type: ', obj.type)
print('Data: ', obj.data)
return decoded_objs
示例10: draw_positions
# 需要导入模块: from pyzbar import pyzbar [as 别名]
# 或者: from pyzbar.pyzbar import decode [as 别名]
def draw_positions(self, frame, decoded_objs):
for obj in decoded_objs:
left, top, width, height = obj.rect
frame = cv2.rectangle(frame,
(left, top),
(left + width, height + top),
(0, 255, 0), 2)
data = obj.data.decode('utf-8')
return frame
示例11: generate
# 需要导入模块: from pyzbar import pyzbar [as 别名]
# 或者: from pyzbar.pyzbar import decode [as 别名]
def generate(self, content: str, output_file: Optional[str] = None, show: bool = False,
format: str = 'png', camera_plugin: Optional[str] = None) -> QrcodeGeneratedResponse:
"""
Generate a QR code.
If you configured the :class:`platypush.backend.http.HttpBackend` then you can also generate
codes directly from the browser through ``http://<host>:<port>/qrcode?content=...``.
:param content: Text, URL or content of the QR code.
:param output_file: If set then the QR code will be exported in the specified image file.
Otherwise, a base64-encoded representation of its binary content will be returned in
the response as ``data``.
:param show: If True, and if the device where the application runs has an active display,
then the generated QR code will be shown on display.
:param format: Output image format (default: ``png``).
:param camera_plugin: If set then this plugin (e.g. ``camera`` or ``camera.pi``) will be used to capture
live images from the camera and search for bar codes or QR-codes.
:return: :class:`platypush.message.response.qrcode.QrcodeGeneratedResponse`.
"""
import qrcode
qr = qrcode.make(content)
img = qr.get_image()
ret = {
'content': content,
'format': format,
}
if show:
img.show()
if output_file:
output_file = os.path.abspath(os.path.expanduser(output_file))
img.save(output_file, format=format)
ret['image_file'] = output_file
else:
f = io.BytesIO()
img.save(f, format=format)
ret['data'] = base64.encodebytes(f.getvalue()).decode()
return QrcodeGeneratedResponse(**ret)
示例12: decode
# 需要导入模块: from pyzbar import pyzbar [as 别名]
# 或者: from pyzbar.pyzbar import decode [as 别名]
def decode(self, image_file: str) -> QrcodeDecodedResponse:
"""
Decode a QR code from an image file.
:param image_file: Path of the image file.
"""
from pyzbar import pyzbar
from PIL import Image
image_file = os.path.abspath(os.path.expanduser(image_file))
img = Image.open(image_file)
results = pyzbar.decode(img)
return QrcodeDecodedResponse(results)
示例13: _qr_dec
# 需要导入模块: from pyzbar import pyzbar [as 别名]
# 或者: from pyzbar.pyzbar import decode [as 别名]
def _qr_dec(self, qr_b64):
# decode png from temp inmem file
b = base64.b64decode(qr_b64)
f = io.BytesIO(b)
image = Image.open(f)
# decode qr code - results in a otpauth://... url in 'data' bytes
dec = decode(image)[0]
qs = parse.urlsplit(dec.data).query
secret_b32 = parse.parse_qs(qs)[b"secret"][0]
return secret_b32
示例14: read_qr
# 需要导入模块: from pyzbar import pyzbar [as 别名]
# 或者: from pyzbar.pyzbar import decode [as 别名]
def read_qr(self, verbose, path):
"""Reads the QR code to get the attributes
Args:
verbose (Boolean): Set to True to verbose mode
path (str): Path to store the image
"""
try:
read = decode(Image.open(path))
except:
print_error("Error, file not found or not readable")
return
display_qr(read, verbose)
示例15: capture_qr
# 需要导入模块: from pyzbar import pyzbar [as 别名]
# 或者: from pyzbar.pyzbar import decode [as 别名]
def capture_qr(self, verbose, path, save_capture):
"""Get the webcam and wait for a qr image
Args:
verbose (Boolean): Verbose mode
path (str): Path to store the image
save_capture (Boolean): Set to true to save the image
"""
cap = cv2.VideoCapture(0)
cap.set(3,640)
cap.set(4,480)
time.sleep(1)
while(cap.isOpened()):
ret, frame = cap.read()
im = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
read = decode(im)
cv2.imshow('frame',frame)
if(read):
display_qr(read, verbose)
if(save_capture):
cv2.imwrite(path, frame)
cap.release()
cv2.destroyAllWindows()
break
key = cv2.waitKey(1)
if key & 0xFF == ord('q'):
break