win7 python3.6 调用百度AI进行 图片文字识别 文字识别

 1、安装 baidu_ai包 L在python3环境下,pip install baidu_ai/2、创建 文字识别 应用,获取密码 APP_ID  API_KEY  SECRET_KEY。https://console.bce.baidu.com/ai/?_=1554088705892&fromai=1#/ai/ocr/overview/index

# -*- coding: UTF-8 -*-

from aip import AipOcr
import json
import  pandas as pd

# 定义常量 换为您自己的 应用密码
APP_ID = '您自己的 应用密码'
API_KEY = '您自己的 应用密码'
SECRET_KEY = '您自己的 应用密码'

# 初始化AipFace对象
aipOcr = AipOcr(APP_ID, API_KEY, SECRET_KEY)

# 读取图片
# filePath = "WechatIMG1.jpeg"
filePath = "20190401.jpeg"

def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()

# 定义参数变量
options = {
    'detect_direction': 'true',
    'language_type': 'CHN_ENG',
}

# 调用通用文字识别接口
result = aipOcr.basicGeneral(get_file_content(filePath), options)
data = pd.DataFrame(result).T
print (data.loc['words_result'], '*---通用文字识别----*')

# print(json.dumps(result).decode("unicode-escape"))
# 调用通用文字识别接口 高精度版
result = aipOcr.basicAccurate(get_file_content(filePath), options)
data = pd.DataFrame(result).T
print (data.loc['words_result'], '*---通用文字识别 高精度----*')
# print(json.dumps(result).decode("unicode-escape"))

# 调用通用文字识别接口 含位置信息版
result = aipOcr.general(get_file_content(filePath), options)
data = pd.DataFrame(result).T
# print (data.loc['words_result'], '*---通用文字识别 含位置信息版----*')
print ( result['words_result'], '*---通用文字识别 含位置信息 左右----*')
# print(json.dumps(result).decode("unicode-escape"))

 

就可以了。

4、结果: 不同的 精度的  图片文字识别 得到的结果有一点不同。

https://ai.baidu.com/docs#/OCR-Python-SDK/top

代码打包下:

https://download.csdn.net/upload

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值