logo

脱机运行时,代码怎么改才能在识别二维码时候只拍一次二维码,二维码内容就一直出现在LCD上,而不用一直对准二维码识别

2018-10-22 18:57
O
gtq4
import sensor, image, time, lcd, pyb

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # must turn this off to prevent image washout...
clock = time.clock()
lcd.init() # Initialize the lcd screen.

while(True):
    clock.tick()
    img = sensor.snapshot()


    for i in range(10):
        x = (pyb.rng() % (2*img.width())) - (img.width()//2)
        y = (pyb.rng() % (2*img.height())) - (img.height()//2)
        r = (pyb.rng() % 127) + 128
        g = (pyb.rng() % 127) + 128
        b = (pyb.rng() % 127) + 128


    img.lens_corr(1.8) # strength of 1.8 is good for the 2.8mm lens.
    for code in img.find_qrcodes():
        img.draw_rectangle(code.rect(), color = (255, 0, 0))
        print(code)
        img.draw_string(x, y, code.payload(), color = (255, 0, 0), scale = 5, mono_space = False)

    lcd.display(img)
    print(clock.fps())
2018-10-22 19:25
I
网红小智智 星瞳科技

定义一个变量啊,img一直画这个变量字符串就行了,当检查到二维码就把变量重新赋值。

要显示的字符串 = ''
while True:
    二维码们 = img.find_qrcodes()
    for 二维码 in 二维码们:
        要显示的字符串 = 二维码.payload()
    img.draw(坐标,要显示的字符串)
    lcd.display(img)
2018-10-22 19:40
O
gtq4

请问下第一行要显示的字符串=“”怎么用代码表示

I
网红小智智 星瞳科技
a = ''
O
gtq4

那是不是 a="code.payload"

while True:

for code in img.find_qrcodes()

a=code.payload()

img.draw()

lcd.display(img)