基于python的文字识别技术

1.需要申请百度的APP_ID           http://ai.baidu.com/ 

然后填入代码中的4-6行中

2.在cmd命令窗口中安装baidu-aip,命令为pip install baidu-aip

基于python的文字识别技术_第1张图片

3.需要导入两个模块 ,代码中的前两行

from aip import AipOcr

import re

4.运行如下代码,ok

# -*- coding: utf-8 -*-
"""
Created on Wed Apr 24 10:58:40 2019

@author: lenovn
"""

from aip import AipOcr
import re

APP_ID = '你的APP_ID'
API_KEY = '你的API_KEY'
SECRET_KEY = '你的SECRET_KEY'

client = AipOcr(APP_ID,API_KEY,SECRET_KEY)

i = open(r'E:\picture\shibie2.jpg','rb')
#print(i)

img = i.read()

message = client.basicGeneral(img)

#输出识别图片中文字的列表
print(message.get('words_result'))

#只输出图中的文字:

for i in message.get('words_result'):

    print(i.get('words'))

基于python的文字识别技术_第2张图片 

 

你可能感兴趣的:(人工智能)