Maixll-Dock 条形码识别
- image模块:find_barcodes
- 案例:识别条形码
- 查看 find_barcodes() 返回信息
- 识别条形码
二维码识别就不用我多说了吧
咸鱼出品,能用就行~
选用版本:v831-m2dock-maixpy3-0.5.0-20220601
条形码或称条码(barcode)是将宽度不等的多个黑条和空白,按照一定的编码规则排列,用以表达一组信息的图形标识符。
常见的条形码是由反射率相差很大的黑条(简称条)和白条(简称空)排成的平行线图案。
条形码可以标出物品的生产国、制造厂家、商品名称、生产日期、图书分类号、邮件起止地点、类别、日期等信息,因而在商品流通、图书管理、邮政管理、银行系统等许多领域都得到了广泛的应用。
image模块:find_barcodes
一、导入模块
from maix import image
二、基本使用方法
from maix import image
x=image.find_barcodes()
print(x)
获取条形码坐标:读取 find_barcodes() 函数返回的字典中键值为: corners 的列表中的值作为条形码的坐标(绿色框)。
获取条形码信息:读取 find_barcodes() 函数返回的字典中键值为: payload 的值作为条形码信息。 获取条形码类型:读取
find_barcodes() 函数返回的字典中键值为: type 的值作为条形码的类型
(注意:此处条形码类型选择的是 CODE39故键值为 type 返回的值为 12 ,如果将条形码类型换为 CODE128 ,则键值为 type 返回的值为 15 )。
字典的键值如下所示:‘x’ , ‘y’ , ‘w’ , ‘h’ , ‘payload’ , ‘rotation’ , ‘type’ , ‘quality’ , ‘corners’。
键值 | 说明 |
x | 返回条形码的边界框的x坐标(int)。 |
y | 返回条形码的边界框的y坐标(int)。 |
w | 返回条形码的边界框的w坐标(int)。 |
h | 返回条形码的边界框的h坐标(int)。 |
payload | 返回的值是条形码的内容。 |
rotation | 返回以弧度计的条形码的旋度(浮点数) |
type | 返回的值是条形码的类型 |
quality | 返回条形码在图像中被检测到的次数(int)。 |
corners | 键值返回的是一个列表,列表中的值分别条形码四个顶点的坐标 |
案例:识别条形码
查看 find_barcodes() 返回信息
#!/usr/bin/python3
from maix import display, camera
while True:
t = camera.capture()
mks = t.find_barcodes() # 返回条形码信息
print(mks)
#display.show(t)
所获得的信息如下:是个字典哦
[{‘x’: 71, ‘y’: 60, ‘w’: 136, ‘h’: 48, ‘payload’: ‘6901234567892’, ‘rotation’: 0, ‘type’: 6, ‘quality’: 55, ‘corners’: [[71, 60], [207, 60], [207, 108], [71, 108]]}]
得到了字典,后面你懂得
识别条形码
#!/usr/bin/python3
from maix import display, camera
while True:
t = camera.capture()
mks = t.find_barcodes()
for mk in mks:
#二维码信息
string = mk['payload']
TYPE = mk['type']
#内框数据
x1,y1 = mk['corners'][0] #访问字典的列表
x2,y2 = mk['corners'][1]
x3,y3 = mk['corners'][2]
x4,y4 = mk['corners'][3]
#画内框
t.draw_line(x1, y1, x2, y2, color = (0, 255, 0), thickness = 3)
t.draw_line(x2, y2, x3, y3, color = (0, 255, 0), thickness = 3)
t.draw_line(x3, y3, x4, y4, color = (0, 255, 0), thickness = 3)
t.draw_line(x4, y4, x1, y1, color = (0, 255, 0), thickness = 3)
#打印信息
t.draw_string(int(x1) , int(y1 - 35) , str(string), scale = 2.0, color = (255, 0, 0), thickness = 2)
t.draw_string(int(x1) , int(y1 + 35) , str(TYPE), scale = 2.0, color = (255, 0, 0), thickness = 2)
display.show(t)
效果图:(IBSN码有错误,其他正常)
11111为条形码内容,12表示条形码类型为CODE39