logo

这个程序为什么偶尔会报错,但有时也会运行?

2018-09-29 21:59
7
Lucia
# QRCode Example
#
# This example shows the power of the OpenMV Cam to detect QR Codes
# without needing lens correction.

import sensor, image, time

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.VGA)
sensor.set_windowing((240, 240)) # look at center 240x240 pixels of the VGA resolution.
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # must turn this off to prevent image washout...
clock = time.clock()

while(True):
    clock.tick()
    img = sensor.snapshot()
    for code in img.find_qrcodes():
        m=code.payload()
    break
s=list(m)
print(s)
2018-09-29 22:49
X
Yuan

请提供报错提示截图以及现象

2018-09-30 10:14
K
wlfg
f2f0418c-6810-4987-b398-562d1bc1e08d.png
2018-09-30 10:50
X
Yuan

你的程序逻辑有问题。

没有检测到二维码的时候,m就不会被赋值。

2018-09-30 13:57
7
Lucia

那我想要调用扫面出来的二维码信息应该怎么写?就是跳出while 循环使用数据

I
网红小智智 星瞳科技

程序应该永远都在死循环里。

while(True):
    img = sensor.snapshot()
    for code in img.find_qrcodes():
        m=code.payload()
        print(m)
2018-09-30 14:04
7
Lucia

但是我只想让它扫描出一次数据就可以了,不需要无限循环,该怎么做呢

I
网红小智智 星瞳科技

不会有这种需求的。难道一个设备只能开机运行一次,就要手动重启?

7
Lucia

是这样的,我想用扫描出的二维码信息来执行后面的程序,如果一直在while循环里面就执行不了后面的程序了

I
网红小智智 星瞳科技

你的逻辑是有问题的

while(True):
    img = sensor.snapshot()
    codes = img.find_qrcodes()
    if codes:#如果找到了二维码
        for code in codes:#你的图像里可能有好几个二维码
            m=code.payload()#每一个二维码的数据
            print(m)
        #如果找到了二维码就在这里处理
    else:
        print('not found')
        如果找不到就在这里写