python利用百度AI實(shí)現(xiàn)文字識(shí)別功能
本文為大家分享了python實(shí)現(xiàn)文字識(shí)別功能大全,供大家參考,具體內(nèi)容如下
1.通用文字識(shí)別
# -*- coding: UTF-8 -*- from aip import AipOcr # 定義常量 APP_ID = '11352343' API_KEY = 'Nd5Z1NkGoLDvHwBnD2bFLpCE' SECRET_KEY = 'A9FsnnPj1Ys2Gof70SNgYo23hKOIK8Os' # 初始化AipFace對(duì)象 aipOcr = AipOcr(APP_ID, API_KEY, SECRET_KEY) # 讀取圖片 filePath = "test3.png" def get_file_content(filePath): with open(filePath, 'rb') as fp: return fp.read() # 定義參數(shù)變量 options = { 'detect_direction': 'true', 'language_type': 'CHN_ENG', } # 調(diào)用通用文字識(shí)別接口 result = aipOcr.basicGeneral(get_file_content(filePath), options) print(result) words_result=result['words_result'] for i in range(len(words_result)): print(words_result[i]['words'])
2.網(wǎng)絡(luò)圖片文字識(shí)別
識(shí)別一些網(wǎng)絡(luò)上背景復(fù)雜,特殊字體的文字。
# -*- coding: UTF-8 -*- from aip import AipOcr # 定義常量 APP_ID = '11352343' API_KEY = 'Nd5Z1NkGoLDvHwBnD2bFLpCE' SECRET_KEY = 'A9FsnnPj1Ys2Gof70SNgYo23hKOIK8Os' # 初始化AipFace對(duì)象 aipOcr = AipOcr(APP_ID, API_KEY, SECRET_KEY) # 讀取圖片 filePath = "2-5.jpg" def get_file_content(filePath): with open(filePath, 'rb') as fp: return fp.read() options={} options["detect_direction"] = "true" #檢測(cè)朝向 options["detect_language"] = "true" #檢測(cè)語言 result= aipOcr.webImage(get_file_content(filePath),options) print(result) for i in range(len(result['words_result'])): print(result['words_result'][i]['words'])
3.身份證識(shí)別
身份證識(shí)別包括正面和背面。
# -*- coding: UTF-8 -*- from aip import AipOcr # 定義常量 APP_ID = '11352343' API_KEY = 'Nd5Z1NkGoLDvHwBnD2bFLpCE' SECRET_KEY = 'A9FsnnPj1Ys2Gof70SNgYo23hKOIK8Os' # 初始化AipFace對(duì)象 aipOcr = AipOcr(APP_ID, API_KEY, SECRET_KEY) # 讀取圖片 filePath1 = "2-6-2.jpg" #正面 filePath2 = "2-6-1.jpg" #背面 def get_file_content(filePath): with open(filePath, 'rb') as fp: return fp.read() options={} options["detect_direction"] = "true" #檢測(cè)朝向 options["detect_risk"] = "true" #是否開啟身份證風(fēng)險(xiǎn)類型(身份證復(fù)印件、臨時(shí)身份證、身份證翻拍、修改過的身份證)功能,默認(rèn)不開啟 result1= aipOcr.idcard(get_file_content(filePath1),'front',options) result2= aipOcr.idcard(get_file_content(filePath2),'back',options) print(result1) print(result2) for key in result1['words_result'].keys(): print(key+':'+result1['words_result'][key]['words']) for key in result2['words_result'].keys(): print(key+':'+result2['words_result'][key]['words'])
4.銀行卡識(shí)別
識(shí)別銀行卡并返回卡號(hào)和發(fā)卡行。
# -*- coding: UTF-8 -*- from aip import AipOcr # 定義常量 APP_ID = '11352343' API_KEY = 'Nd5Z1NkGoLDvHwBnD2bFLpCE' SECRET_KEY = 'A9FsnnPj1Ys2Gof70SNgYo23hKOIK8Os' # 初始化AipFace對(duì)象 aipOcr = AipOcr(APP_ID, API_KEY, SECRET_KEY) # 讀取圖片 filePath = "2-7.jpeg" def get_file_content(filePath): with open(filePath, 'rb') as fp: return fp.read() options={} result=aipOcr.bankcard(get_file_content(filePath),options) print(result) #bank_card_type 銀行卡類型,0:不能識(shí)別; 1: 借記卡; 2: 信用卡 for key in result['result']: print(key+':'+str(result['result'][key]))
5.駕駛證識(shí)別
對(duì)機(jī)動(dòng)車駕駛證所有關(guān)鍵字段進(jìn)行識(shí)別。
# -*- coding: UTF-8 -*- from aip import AipOcr # 定義常量 APP_ID = '11352343' API_KEY = 'Nd5Z1NkGoLDvHwBnD2bFLpCE' SECRET_KEY = 'A9FsnnPj1Ys2Gof70SNgYo23hKOIK8Os' # 初始化AipFace對(duì)象 aipOcr = AipOcr(APP_ID, API_KEY, SECRET_KEY) # 讀取圖片 filePath = "2-8.jpg" def get_file_content(filePath): with open(filePath, 'rb') as fp: return fp.read() options={} result=aipOcr.drivingLicense(get_file_content(filePath),options) print(result) for key in result['words_result']: print(key+':'+str(result['words_result'][key]['words']))
6.行駛證識(shí)別
對(duì)機(jī)動(dòng)車行駛證正本所有關(guān)鍵字段進(jìn)行識(shí)別。
# -*- coding: UTF-8 -*- from aip import AipOcr # 定義常量 APP_ID = '11352343' API_KEY = 'Nd5Z1NkGoLDvHwBnD2bFLpCE' SECRET_KEY = 'A9FsnnPj1Ys2Gof70SNgYo23hKOIK8Os' # 初始化AipFace對(duì)象 aipOcr = AipOcr(APP_ID, API_KEY, SECRET_KEY) # 讀取圖片 filePath = "2-9.jpg" def get_file_content(filePath): with open(filePath, 'rb') as fp: return fp.read() options={} result=aipOcr.vehicleLicense(get_file_content(filePath),options) print(result) for key in result['words_result']: print(key+':'+str(result['words_result'][key]['words']))
7.車牌識(shí)別
# -*- coding: UTF-8 -*- from aip import AipOcr # 定義常量 APP_ID = '11352343' API_KEY = 'Nd5Z1NkGoLDvHwBnD2bFLpCE' SECRET_KEY = 'A9FsnnPj1Ys2Gof70SNgYo23hKOIK8Os' # 初始化AipFace對(duì)象 aipOcr = AipOcr(APP_ID, API_KEY, SECRET_KEY) # 讀取圖片 filePath = "2-3.png" def get_file_content(filePath): with open(filePath, 'rb') as fp: return fp.read() options={} options["multi_detect"] = "true" #是否檢測(cè)多張車牌,默認(rèn)為false,當(dāng)置為true的時(shí)候可以對(duì)一張圖片內(nèi)的多張車牌進(jìn)行識(shí)別 result= aipOcr.licensePlate(get_file_content(filePath),options) for i in range(len(result['words_result'])): print(result['words_result'][i]['color']+' '+result['words_result'][i]['number'])
8.營(yíng)業(yè)執(zhí)照識(shí)別
識(shí)別營(yíng)業(yè)執(zhí)照,并返回關(guān)鍵字段的值,包括單位名稱、法人、地址、有效期、證件編號(hào)、社會(huì)信用代碼等。
# -*- coding: UTF-8 -*- from aip import AipOcr # 定義常量 APP_ID = '11352343' API_KEY = 'Nd5Z1NkGoLDvHwBnD2bFLpCE' SECRET_KEY = 'A9FsnnPj1Ys2Gof70SNgYo23hKOIK8Os' # 初始化AipFace對(duì)象 aipOcr = AipOcr(APP_ID, API_KEY, SECRET_KEY) # 讀取圖片 filePath = "2-10.jpg" def get_file_content(filePath): with open(filePath, 'rb') as fp: return fp.read() options={} result=aipOcr.businessLicense(get_file_content(filePath),options) print(result) for key in result['words_result']: print(key+':'+str(result['words_result'][key]['words']))
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Python基于百度AI的文字識(shí)別的示例
- Python3調(diào)用百度AI識(shí)別圖片中的文字功能示例【測(cè)試可用】
- Python基于百度AI實(shí)現(xiàn)OCR文字識(shí)別
- python調(diào)用百度AI接口實(shí)現(xiàn)人流量統(tǒng)計(jì)
- python 使用百度AI接口進(jìn)行人臉對(duì)比的步驟
- Python基于百度AI實(shí)現(xiàn)抓取表情包
- python 百度aip實(shí)現(xiàn)文字識(shí)別的實(shí)現(xiàn)示例
- Python調(diào)用百度AI實(shí)現(xiàn)圖片上文字識(shí)別功能實(shí)例
- Python調(diào)用百度AI實(shí)現(xiàn)圖片上表格識(shí)別功能
相關(guān)文章
使用python實(shí)現(xiàn)滑動(dòng)驗(yàn)證碼功能
這篇文章主要介紹了使用python實(shí)現(xiàn)滑動(dòng)驗(yàn)證碼功能,本文通過示例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下2019-08-08Django框架基礎(chǔ)認(rèn)證模塊auth應(yīng)用示例
這篇文章主要為大家介紹了Django框架認(rèn)證模塊auth示例應(yīng)用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-03-03Django使用django-simple-captcha做驗(yàn)證碼的實(shí)現(xiàn)示例
這篇文章主要介紹了Django使用django-simple-captcha做驗(yàn)證碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01詳解python使用遞歸、尾遞歸、循環(huán)三種方式實(shí)現(xiàn)斐波那契數(shù)列
本篇文章主要介紹了python使用遞歸、尾遞歸、循環(huán)三種方式實(shí)現(xiàn)斐波那契數(shù)列,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2018-01-01解決Django一個(gè)表單對(duì)應(yīng)多個(gè)按鈕的問題
今天小編就為大家分享一篇解決Django一個(gè)表單對(duì)應(yīng)多個(gè)按鈕的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-07-07Python cookbook(數(shù)據(jù)結(jié)構(gòu)與算法)讓字典保持有序的方法
這篇文章主要介紹了Python讓字典保持有序的方法,涉及Python基于collections模塊中的OrderedDict類實(shí)現(xiàn)控制字典順序的相關(guān)操作技巧,需要的朋友可以參考下2018-02-02python模塊hashlib(加密服務(wù))知識(shí)點(diǎn)講解
在本篇文章里小編給大家分享的是關(guān)于python模塊hashlib(加密服務(wù))知識(shí)點(diǎn)內(nèi)容,有需要的朋友們可以學(xué)習(xí)下。2019-11-11Python發(fā)送郵件封裝實(shí)現(xiàn)過程詳解
這篇文章主要介紹了Python發(fā)送郵件封裝實(shí)現(xiàn)過程詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-05-05