code_scanner

Note

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
15
16def setup():
17    global img, qrcode
18    M5.begin()
19    Widgets.fillScreen(0x222222)
20    camera.init(pixformat=camera.RGB565, framesize=camera.QVGA)
21    camera.set_hmirror(False)
22
23
24def loop():
25    global img, qrcode
26    M5.update()
27    img = camera.snapshot()
28    qrcode = code_scanner.find_qrcodes(img)
29    if qrcode:
30        print(qrcode.payload())
31        print(qrcode.type_name())
32        img.draw_string(10, 10, str(qrcode.payload()), color=0x3333FF, scale=2)
33    M5.Lcd.show(img, 0, 0, 320, 240)
34
35
36if __name__ == "__main__":
37    try:
38        setup()
39        while True:
40            loop()
41    except (Exception, KeyboardInterrupt) as e:
42        try:
43            from utility import print_error_msg
44
45            print_error_msg(e)
46        except ImportError:
47            print("please update to latest firmware")

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