code_scanner

备注

This module is only applicable to the CoreS3 Controller

code_scanner module for qrcode scanning recognition

Micropython Example

qrcode detect

 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

qrcode_detect_example.png

qrcode_detect_example.m5f2

Methods

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

QR code recognition

  • img Image to be recognized

Returns image.qrcode instance

UIFlow2.0

find_qrcodes.png

class image.QRCode

QRCode The QRCode object is returned by code_scanner.find_qrcodes(img: image.Image).

code_scanner.payload() str

Return the payload string of the QR code

UIFlow2.0

payload.png

code_scanner.type_name() str

Return the type of the QR code

UIFlow2.0

type_name.png