【MaixPy学习体会】(用Maixpy和Maix Go硬件识别Barcode和QR code)
前言
关于MaixGo的小摄像头如何应用,Sipeed和CSDN上都有实现的例子和例程。这里要分享的是关于MaixGo上用MaixPy实现一维条码和二维条码阅读
的经验。
条形码 (一维条码、Barcode)
其一:MaixGo的摄像头为30万像素,理论上能支持640x480的分辨率,但是很多时候因为LCD分辨率只有320x240,我们就按较低的分辨率来设置成QVGA来操作了。这样对一维码的识别距离要很近-近到显示区域刚刚能覆盖条码全长才能保证分辨率足够。
其二:当使用Image module的时候,固件版本的选择要慎重。不能是Minimal固件。否则有可能不支持一个关键的模块操作描述:Image.Find_Barcodes()
一维条码识别实现
在Sipeed和MaixPy文档网页也可以能找到QR code识别的代码。稍作变更后,可以识别一维条码如下:
import sensor
import image
import lcd
import time
clock = time.clock()
lcd.init()
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_vflip(0)
sensor.set_hmirror(0)
sensor.run(1)
sensor.skip_frames(30)
while True:
clock.tick()
img = sensor.snapshot()
res = img.find_barcodes()
fps =clock.fps()
if len(res) > 0:
img.draw_string(2, 2, res[0].payload(), color=(0,255,0), scale=2)
print(res[0].payload())
lcd.display(img)