1.功能描述:python
百度通用文字識別基於業界領先的深度學習技術,提供多場景、多語種、高精度的整圖文字檢測和識別服務,印刷體文字識別準確率高達99%,多項ICDAR指標居世界第一。有如下一些版本:express
通用文字識別json
對圖片中的文字進行檢測和識別,支持中、英、法、俄、西、葡、德、意、日、韓、中英混合等多語種識別,同時支持中、英、日、韓四語種的類型檢測app
高精度版學習
在通用文字識別的基礎上,提供更高精度的識別服務,並將字庫從1w+擴展到2w+,能識別全部經常使用字和大部分生僻字測試
含位置信息版this
在通用文字識別的基礎上,返回文字在圖片中的位置信息,方便用戶進行版式的二次處理編碼
高精度含位置版lua
在通用文字識別(高精度版)的基礎上,返回文字在圖片中的位置信息,方便用戶進行版式的二次處理url
2.平臺接入
具體接入方式比較簡單,能夠參考個人另外一個帖子,這裏就不重複了:
http://ai.baidu.com/forum/topic/show/943327
3.調用攻略(Python3)及評測
3.1首先認證受權:
在開始調用任何API以前須要先進行認證受權,具體的說明請參考:
http://ai.baidu.com/docs#/Auth/top
具體Python3代碼以下:
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import urllib
import base64
import json
#client_id 爲官網獲取的AK, client_secret 爲官網獲取的SK
client_id =【百度雲應用的AK】
client_secret =【百度雲應用的SK】
#獲取token
def get_token():
host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=' + client_id + '&client_secret=' + client_secret
request = urllib.request.Request(host)
request.add_header('Content-Type', 'application/json; charset=UTF-8')
response = urllib.request.urlopen(request)
token_content = response.read()
#print (token_content)
if token_content:
token_info = json.loads(token_content)
token_key = token_info['access_token']
return token_key
3.2百度通用文字識別分析接口調用:
詳細說明請參考: https://ai.baidu.com/docs#/OCR-API-GeneralBasic/db0895e7
說明的比較清晰,這裏就不重複了。
你們須要注意的是:
API訪問URL:https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic
圖像數據,base64編碼後進行urlencode,要求base64編碼和urlencode後大小不超過4M,最短邊至少15px,最長邊最大4096px,支持jpg/jpeg/png/bmp格式
返回示例:
{
"log_id": 2471272194,
"words_result_num": 2,
"words_result":
[
{"words": " TSINGTAO"},
{"words": "青島睥酒"}
]
}
Python3調用代碼以下:
def general_basic(filename):
request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic"
# 二進制方式打開圖片文件
f = open(filename, 'rb')
img = base64.b64encode(f.read())
params = dict()
params['image'] = img
params = urllib.parse.urlencode(params).encode("utf-8")
access_token = get_token()
begin = time.perf_counter()
request_url = request_url + "?access_token=" + access_token
request = urllib.request.Request(url=request_url, data=params)
request.add_header('Content-Type', 'application/x-www-form-urlencoded')
response = urllib.request.urlopen(request)
content = response.read()
end = time.perf_counter()
print('處理時長:'+'%.2f'%(end-begin)+'秒')
if content:
#print(content)
content=content.decode('utf-8')
#print(content)
data = json.loads(content)
print(data)
words_result=data['words_result']
print ("識別結果")
for item in words_result:
print (item['words'])
general_basic('../img/general3.jpg')
4.功能評測:
選用不一樣的數據對效果進行測試,具體效果以下(如下例子均來自網上):
處理時長:0.89秒
利洗手間
Toile
處理時長:0.63秒
POSTCARD
處理時長:13.07秒
識別結果:
ACKNOWLEDGEMENTS
We would like to thank all the designers and
contributors who have been involved in the
production of this book; their contributions
have been indispensable to its creation. We
would also like to express our gratitude to all
the producers for their invaluable opinions
and assistance throughout this project And to
the many others whose names are not credited
but have made specific input in this book, we
thank you for your continuous support
5.測試結論和建議
測試下來,總體識別效果不錯。百度通用文字識別的很準確,速度也很快,用起來很是的方便。能夠應用於
拍照/截圖識別
使用通用文字識別技術,實現拍照文字識別、相冊圖片文字識別和截圖文字識別,可應用於搜索、書摘、筆記、翻譯等移動應用中,方便用戶進行文本的提取或錄入,有效提高產品易用性和用戶使用體驗
內容審覈與監管
使用通用文字識別技術,實現對圖像中文字內容的提取,結合文本審覈技術識別違規內容,提示相應風險,協助進行違規處理,可應用於電商廣告審覈、輿情監管等場景,幫助用戶有效規避業務風險
視頻內容分析
使用通用文字識別技術,實現對視頻中的字幕、標題、彈幕等文字內容的檢測和識別,並根據文字位置判斷文字類型,可應用於視頻分類和標籤提取、視頻內容審覈、營銷分析等場景,有效下降人力成本,控制業務風險
紙質文檔電子化
使用通用文字識別技術,實現對各種醫療單據、金融財稅票據、法律卷宗等紙質文檔的識別,並返回文字在圖片中的位置信息以便於進行比對、結構化等處理,可知足醫療、金融、政務、法務、教育等行業文檔快速錄入、存檔和檢索的需求,有效下降企業人力成本,提升信息錄入效率