当前位置:网站首页>V831——二维码识别
V831——二维码识别
2022-07-16 11:43:00 【我与nano】
V831
前言
一个合格的摄像头,一定要可以实现识别二维码。
一、二维码识别字符
#!/usr/bin/python3
from maix import display, camera
while True:
t = camera.capture()
mks = t.find_qrcodes()
for mk in mks:
#外框数据
X = mk['x']
Y = mk['y']
W = mk['w']
H = mk['h']
#二维码信息
string = mk['payload']
#内框数据
x1,y1 = mk['corners'][0] #访问字典的列表
x2,y2 = mk['corners'][1]
x3,y3 = mk['corners'][2]
x4,y4 = mk['corners'][3]
#画外框
t.draw_rectangle(X, Y, X + W, Y + H, color=(0, 0, 255), thickness = 2)
#打印信息
t.draw_string(int(X) , int(Y - 35) , str(string), scale = 2.0, color = (255, 0, 0), thickness = 2) #内框ID
#画内框
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)
display.show(t)
直接看代码,find_qrcodes()、 string = mk[‘payload’]这些831都已经给我们封装好了,可以直接使用
但是后面测试的时候,发现中文不能识别,会报乱码
那么改怎么解决呢
二、二维码识别汉字
1.加载中文字库
image.load_freetype(path="/home/res/sans.ttf")
831里面内置了中文字库,我们只需要将它加载出来,然后image就可以进行显示了
2.完整代码
#!/usr/bin/python3
from maix import display, camera,image
image.load_freetype(path="/home/res/sans.ttf")
while True:
t = camera.capture()
mks = t.find_qrcodes()
for mk in mks:
#外框数据
X = mk['x']
Y = mk['y']
W = mk['w']
H = mk['h']
#二维码信息
string = mk['payload']
#内框数据
x1,y1 = mk['corners'][0] #访问字典的列表
x2,y2 = mk['corners'][1]
x3,y3 = mk['corners'][2]
x4,y4 = mk['corners'][3]
#画外框
t.draw_rectangle(X, Y, X + W, Y + H, color=(0, 0, 255), thickness = 2)
#打印信息
t.draw_string(int(X) , int(Y - 35) , str(string), scale = 2.0, color = (255, 0, 0), thickness = 2) #内框ID
#画内框
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)
display.show(t)

总结
介绍简单几个键值的含义。‘x’ , ‘y’ , ‘w’ , ‘h’ 键值返回的值分别是外框左上角 x 坐标和 y 坐标以及外框的长和宽。而键值 ‘payload’ 返回的值是二维码的信息。
边栏推荐
- JS Base64 to picture
- Chinese translation of zagayevsky's "try to praise this incomplete world"
- 图片验证,滑块验证解决
- [CVA valuation training camp] how to quickly read the annual reports of listed companies (Lecture 1)
- PostgreSQL source code (5) buffer management
- [Huawei online battle] download and run Huawei's official unity example code, prompting authentication failure and returning error code 100114
- 为何加上@Configuration注解的类会生成cglib代理?
- Pycharm crawler tutorial (only for technical exchange)
- [golang learning notes] interface
- Use of [golang] function (first-class citizen)
猜你喜欢

支付宝沙箱测试手机网站支付,提示商户合作协议已到期,无法继续使用

How to choose MySQL database storage engine? Let's take a look at the performance test

How to build a code server cloud ide platform on kubernetes

【华为联机对战】下载运行华为官方Unity示例代码,提示鉴权失败并返回错误码100114

Data Lake (11): Iceberg table data organization and query

Introduction to leetcode special dynamic planning

如何在Kubernetes上搭建code-server 云IDE平台

How to build cloud ide Theia on kubernetes platform

Architecture layering of standard web system of Architecture Series

View for recording a temperature curve
随机推荐
Scala Foundation (II): variables and data types
Shengxin weekly issue 36
Qt | 控件之QCheckBox
如何在Kubernetes平台上搭建云IDE Theia
Etcd database source code analysis -- etcdserver bootstrap to remove v2store
[HMS core] [wallet kit] [solution] why can't Huawei wallet's client sample code run
美国压力激增 TikTok更换全球安全主管
【快应用】快应用用户协议、隐私政策内容中可以多次跳转,点击返回未能返回上一级页面,该如何处理?
面试官:Redis主从集群切换数据丢失问题如何应对?
Competition of "four clouds"
[harmony OS] [FAQ] Hongmeng application development problem sharing (font / constructor)
Etcd database source code analysis -- etcdserver bootstrap initialization cluster and raft
AB introduction to web performance testing tools
因果学习将开启下一代AI浪潮?九章云极DataCanvas正式发布YLearn因果学习开源项目
TypeScript 类的使用
【快应用】px和vp单位换算
【华为联机对战】下载运行华为官方Unity示例代码,提示鉴权失败并返回错误码100114
[quick application] quick application user agreement and privacy policy content can jump many times. Click back and fail to return to the previous page. How to deal with it?
Sewage discharge monitoring, environmental protection data acquisition instrument to help urban black and odorous water treatment
mixin\插件\scoped样式