code_scanner

备注

当前模块只适用于 CoreS3 主机

code_scanner 模块用于扫码识别

Micropython 案例

二维码识别

 1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
 2#
 3# SPDX-License-Identifier: MIT
 4import os, sys, io
 5import M5
 6from M5 import *
 7import camera
 8import code_scanner
 9import image
10
11
12img = None
13qrcode = None
14
15def setup():
16    global img, qrcode
17    M5.begin()
18    Widgets.fillScreen(0x222222)
19    camera.init(pixformat=camera.RGB565, framesize=camera.QVGA)
20    camera.set_hmirror(False)
21
22def loop():
23    global img, qrcode
24    M5.update()
25    img = camera.snapshot()
26    qrcode = code_scanner.find_qrcodes(img)
27    if qrcode:
28        print(qrcode.payload())
29        print(qrcode.type_name())
30        img.draw_string(10, 10, str(qrcode.payload()), color=0x3333ff, scale=2)
31    M5.Lcd.show(img, 0, 0, 320, 240)
32
33if __name__ == '__main__':
34    try:
35        setup()
36        while True:
37            loop()
38    except (Exception, KeyboardInterrupt) as e:
39        try:
40            from utility import print_error_msg
41            print_error_msg(e)
42        except ImportError:
43            print("please update to latest firmware")
44

UIFlow2.0 Example

二维码识别

qrcode_detect_example.png

qrcode_detect_example.m5f2

Methods

code_scanner.find_qrcodes(img: image.Image) image.qrcode

二维码识别

  • img 需要识别的图像

返回 image.qrcode 对象

UIFlow2.0

find_qrcodes.png

class image.QRCode

QRCode 对象由 code_scanner.find_qrcodes() 返回

code_scanner.payload() str

返回二维码的有效载荷字符串

UIFlow2.0

payload.png

code_scanner.type_name() str

返回二维码的类型

UIFlow2.0

type_name.png