国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python利用百度AI實現文字識別功能

2020-02-15 23:48:01
字體:
來源:轉載
供稿:網友

本文為大家分享了python實現文字識別功能大全,供大家參考,具體內容如下

1.通用文字識別

# -*- coding: UTF-8 -*-from aip import AipOcr # 定義常量APP_ID = '11352343'API_KEY = 'Nd5Z1NkGoLDvHwBnD2bFLpCE'SECRET_KEY = 'A9FsnnPj1Ys2Gof70SNgYo23hKOIK8Os' # 初始化AipFace對象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() # 定義參數變量options = { 'detect_direction': 'true', 'language_type': 'CHN_ENG',} # 調用通用文字識別接口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.網絡圖片文字識別

識別一些網絡上背景復雜,特殊字體的文字。

# -*- coding: UTF-8 -*-from aip import AipOcr # 定義常量APP_ID = '11352343'API_KEY = 'Nd5Z1NkGoLDvHwBnD2bFLpCE'SECRET_KEY = 'A9FsnnPj1Ys2Gof70SNgYo23hKOIK8Os' # 初始化AipFace對象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" #檢測朝向options["detect_language"] = "true" #檢測語言 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.身份證識別

身份證識別包括正面和背面。

# -*- coding: UTF-8 -*-from aip import AipOcr# 定義常量APP_ID = '11352343'API_KEY = 'Nd5Z1NkGoLDvHwBnD2bFLpCE'SECRET_KEY = 'A9FsnnPj1Ys2Gof70SNgYo23hKOIK8Os' # 初始化AipFace對象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" #檢測朝向options["detect_risk"] = "true"#是否開啟身份證風險類型(身份證復印件、臨時身份證、身份證翻拍、修改過的身份證)功能,默認不開啟 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.銀行卡識別

識別銀行卡并返回卡號和發卡行。

# -*- coding: UTF-8 -*-from aip import AipOcr # 定義常量APP_ID = '11352343'API_KEY = 'Nd5Z1NkGoLDvHwBnD2bFLpCE'SECRET_KEY = 'A9FsnnPj1Ys2Gof70SNgYo23hKOIK8Os' # 初始化AipFace對象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:不能識別; 1: 借記卡; 2: 信用卡for key in result['result']: print(key+':'+str(result['result'][key]))            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高淳县| 江阴市| 大理市| 西藏| 香港 | 周至县| 泗阳县| 阿鲁科尔沁旗| 紫云| 惠安县| 夹江县| 紫阳县| 洮南市| 桐城市| 开化县| 奉贤区| 鄂托克旗| 万荣县| 哈密市| 莎车县| 达日县| 丰宁| 晋中市| 湖北省| 交口县| 扎囊县| 孝义市| 章丘市| 浦北县| 凤庆县| 阆中市| 铁力市| 庆元县| 资溪县| 六安市| 当雄县| 蓝田县| 冀州市| 白玉县| 牟定县| 包头市|