我们先来看看,识别的效果如何
本程序可以识别网络图片和本地图片
演示1:文字图片
演示2:游戏大区文字识别 ,一字不差
教程开始
一、先注册一个账号
打开下面 链接 - 点击立即使用 - 点击右侧 - 公有云服务 - 点击应用列表 - 点击创建应用
文字识别_通用场景文字识别-https://cloud.baidu.com/product/ocr_general
1、应用名称:随便填写
2、如下图填写
3、获取APPID、API5_KEY、SECRET_KEY:
?
4、APPID、API_KEY、SECRET_KEY 填入程序即可。
二、程序开始之前,要做的事。
1、先安装3个模块:
#安装optparse模块
pip install optparse -i https://pypi.tuna.tsinghua.edu.cn/simple
安装aip模块
pip install baidu-aip -i https://pypi.tuna.tsinghua.edu.cn/simple
#安装chardet
pip install chardet -i https://pypi.tuna.tsinghua.edu.cn/simple
三、代码编写:
from optparse import Values
from aip import AipOcr
import chardet
""" 你的 APPID AK SK """
APP_ID = '271296523' #这里用到的是百度API
API_KEY = 'vN7XVZUZlBBLqDZssssafso1Zw'
SECRET_KEY = 'qX3L5KTu50aiasdas465d6G39aPN6pYOfc'
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
#获取网络图片,并用ocr识别
def getUrlText(imagesUrl):
# 调用通用文字识别
res_url = client.basicGeneralUrl(imagesUrl)
wordList = res_url['words_result']
for i in wordList:
for k,v in i.items():
print(v)
return v
#获取本地图片,并用ocr识别
def getPathText(imagespath):
""" 读取文件 """
def get_file_content(filePath):
with open(filePath, "rb") as fp:
return fp.read()
image = get_file_content(imagespath)
res_url = client.basicGeneral(image)
wordList = res_url['words_result']
for i in wordList:
for k,v in i.items():
print(v)
return v
这样代码就编写好了,你学会了吗?
?
本文暂时没有评论,来添加一个吧(●'◡'●)