100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > 轻松识别手写汉字工具-python

轻松识别手写汉字工具-python

时间:2022-07-20 11:50:41

相关推荐

轻松识别手写汉字工具-python

免费轻松识别手写汉字工具-python

话不多说,先上效果图!开发过程小工具打包为.exe程序了。[下载连接](/download/puremilkll/10707679)

话不多说,先上效果图!

这是需要识别的手写汉字:

这是识别效果:

下面是通用OCR识别:

效果:

识别效果还是非常好的, 单字识别准确率可达到中文98%以上。

我已经将小工具打包为.exe程序了。下载连接,下载后可以直接使用。

喜欢自己捣鼓的小伙伴,可以到腾讯AI开放平台逛逛,现在上面大部分功能都是免费的,赶紧玩玩儿,嘿嘿。

开发过程

首先需要python开发环境,推荐安装Anaconda3,比较方便;下载 简单易用的python接口,可以快速开发使用腾讯AI开放平台的功能。(pip install qqai)

qqai的github地址,里面有使用介绍等

直接上代码;

from tkinter import *import tkinter.filedialogimport qqai"""腾讯AI开放平台 图片识别"""app_id = '你自己的app_id'app_key = '你自己的app_key '"""app_id , app_key 可以自己去腾讯AI开放平台注册,是免费的"""root = tkinter.Tk()var = tkinter.StringVar()def ocrImage(filename):robot = qqai.vision.ocr.GeneralOCR(app_id, app_key) # 通用OCRitem_list = []words = ''# 通用OCRwith open(filename, 'rb') as image_file:result = robot.run(image_file)for key in result:if key == 'data':item_list = result[key]['item_list']for n in item_list:if len(n['itemstring']) > 40:words += n['itemstring']else:words += n['itemstring'] + '\n'print(words)t.insert(1.0, words)def HandwritingOCRImage(filename):robot = qqai.vision.ocr.HandwritingOCR(app_id, app_key) # 手写item_list = []words = ''# 手写OCRwith open(filename, 'rb') as image_file:result = robot.run(image_file)for key in result:if key == 'data':item_list = result[key]['item_list']for n in item_list:if len(n['itemstring']) > 40:words += n['itemstring']else:words += n['itemstring'] + '\n'print(words)t.insert(1.0, words)def xz1():btn.config(state=tkinter.DISABLED) # 按钮失效btn1.config(state=tkinter.DISABLED) # 按钮失效filename = tkinter.filedialog.askopenfilename()if filename != '':l.config(text="您选择的文件是:"+filename)ocrImage(filename)else:l.config(text="您没有选择任何文件")btn.config(state=tkinter.ACTIVE) # 激活按钮btn1.config(state=tkinter.ACTIVE) # 激活按钮def xz2():btn.config(state=tkinter.DISABLED) # 按钮失效btn1.config(state=tkinter.DISABLED) # 按钮失效filename = tkinter.filedialog.askopenfilename()if filename != '':l.config(text="您选择的文件是:"+filename)HandwritingOCRImage(filename)else:l.config(text="您没有选择任何文件")btn.config(state=tkinter.ACTIVE) # 激活按钮btn1.config(state=tkinter.ACTIVE) # 激活按钮# 第2步,给窗口的可视化起名字root.title('图像识别')# 第3步,设定窗口的大小(长 * 宽)root.geometry('500x300') # 这里的乘是小x# 第4步,在图形界面上设定标签l = tkinter.Label(root, text='你好!这是图像识别工具', font=('Arial', 12), width=30, height=2)# 说明: bg为背景,font为字体,width为长,height为高,这里的长和高是字符的长和高,比如height=2,就是标签有2个字符这么高# 第5步,放置标签l.pack() # Label内容content区域放置位置,自动调节尺寸# 放置lable的方法有:1)l.pack(); 2)l.place();btn = tkinter.Button(root, text="通用OCR", command=xz1)btn.pack()btn1 = tkinter.Button(root, text="手写体OCR", command=xz2)btn1.pack()t = tkinter.Text(root, height=16)t.pack()root.mainloop()

效果:

小工具打包为.exe程序了。下载连接

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。