Python3使用騰訊云文字識(shí)別(騰訊OCR)提取圖片中的文字內(nèi)容實(shí)例詳解
百度OCR體驗(yàn)地址:
https://ai.baidu.com/tech/imagerecognition/general
騰訊OCR體驗(yàn)地址:
https://cloud.tencent.com/act/event/ocrdemo
測(cè)試結(jié)果是:騰訊的效果要比百度的好
騰訊云目前額度是:
每個(gè)接口 1,000次/月免費(fèi),有6個(gè)文字識(shí)別的接口,一共是6,000次/月
百度接口調(diào)用之前寫過(guò)文章
python實(shí)現(xiàn)百度OCR圖片識(shí)別過(guò)程解析
使用步驟
1、注冊(cè)賬號(hào): https://cloud.tencent.com/
2、開(kāi)通服務(wù):https://console.cloud.tencent.com/ocr/general
3、申請(qǐng)?jiān)L問(wèn)秘鑰:https://console.cloud.tencent.com/cam/capi
4、通過(guò) API 或 SDK 或命令行來(lái)使用服務(wù)
具體參考《操作指南》:https://cloud.tencent.com/document/product/866/17622
接口使用
1、安裝SDK
https://github.com/TencentCloud/tencentcloud-sdk-python
pip3 install tencentcloud-sdk-python
2、代碼實(shí)例
# -*- coding: utf-8 -*- import json from tencentcloud.common import credential from tencentcloud.common.profile.client_profile import ClientProfile from tencentcloud.common.profile.http_profile import HttpProfile from tencentcloud.ocr.v20181119 import ocr_client from tencentcloud.ocr.v20181119.models import ( GeneralAccurateOCRRequest, EnglishOCRRequest, GeneralBasicOCRRequest, GeneralEfficientOCRRequest, GeneralFastOCRRequest, GeneralHandwritingOCRRequest ) class TencentOcr(object): """ 計(jì)費(fèi)說(shuō)明:1,000次/月免費(fèi) https://cloud.tencent.com/document/product/866/17619 """ SECRET_ID = "你的秘鑰 SECRET_ID" SECRET_KEY = "你的秘鑰 SECRET_KEY" # 地域列表 # https://cloud.tencent.com/document/api/866/33518#.E5.9C.B0.E5.9F.9F.E5.88.97.E8.A1.A8 Region = "ap-beijing" endpoint = "ocr.tencentcloudapi.com" # 通用文字識(shí)別相關(guān)接口 # https://cloud.tencent.com/document/api/866/37173 mapping = { # 通用印刷體識(shí)別(高精度版) ok "GeneralAccurateOCR": GeneralAccurateOCRRequest, # 英文識(shí)別 ok "EnglishOCR": EnglishOCRRequest, # 通用印刷體識(shí)別 一般 "GeneralBasicOCR": GeneralBasicOCRRequest, # 通用印刷體識(shí)別(精簡(jiǎn)版)(免費(fèi)公測(cè)版)no "GeneralEfficientOCR": GeneralEfficientOCRRequest, # 通用印刷體識(shí)別(高速版)一般 "GeneralFastOCR": GeneralFastOCRRequest, # 通用手寫體識(shí)別 ok "GeneralHandwritingOCR": GeneralHandwritingOCRRequest, } def __init__(self): cred = credential.Credential(self.SECRET_ID, self.SECRET_KEY) httpProfile = HttpProfile() httpProfile.endpoint = self.endpoint clientProfile = ClientProfile() clientProfile.httpProfile = httpProfile self.client = ocr_client.OcrClient(cred, self.Region, clientProfile) def get_image_text(self, image_url, ocr="GeneralAccurateOCR"): req = self.mapping[ocr]() req.ImageUrl = image_url resp = getattr(self.client, ocr)(req) return json.loads(resp.to_json_string())['TextDetections'][0]['DetectedText'] def main(): tencentOcr = TencentOcr() url = "https://ocr-demo-1254418846.cos.ap-guangzhou.myqcloud.com/general/GeneralBasicOCR/GeneralBasicOCR3.jpg" print(tencentOcr.get_image_text(url, ocr="GeneralHandwritingOCR")) if __name__ == '__main__': main()
更多關(guān)于Python3使用騰訊云文字識(shí)別(騰訊OCR)提取圖片中的文字內(nèi)容實(shí)例請(qǐng)查看下面的相關(guān)鏈接
- Python 圖片文字識(shí)別的實(shí)現(xiàn)之PaddleOCR
- Python 實(shí)現(xiàn)任意區(qū)域文字識(shí)別(OCR)操作
- Python圖像處理之圖片文字識(shí)別功能(OCR)
- Python調(diào)用百度OCR實(shí)現(xiàn)圖片文字識(shí)別的示例代碼
- Python基于百度AI實(shí)現(xiàn)OCR文字識(shí)別
- python調(diào)用文字識(shí)別OCR輕松搞定驗(yàn)證碼
- python 3調(diào)用百度OCR API實(shí)現(xiàn)剪貼板文字識(shí)別
- 基于Python實(shí)現(xiàn)圖像文字識(shí)別OCR工具
- python實(shí)戰(zhàn)教程之OCR文字識(shí)別方法匯總
相關(guān)文章
使用Python發(fā)送Post請(qǐng)求以及解析響應(yīng)結(jié)果
發(fā)送post的請(qǐng)求參考例子很簡(jiǎn)單,實(shí)際遇到的情況卻是很復(fù)雜的,下面這篇文章主要給大家介紹了關(guān)于如何使用Python發(fā)送Post請(qǐng)求以及解析響應(yīng)結(jié)果的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-06-06python實(shí)現(xiàn)二叉查找樹(shù)實(shí)例代碼
這篇文章主要介紹了python實(shí)現(xiàn)二叉查找樹(shù)實(shí)例代碼,分享了相關(guān)代碼示例,小編覺(jué)得還是挺不錯(cuò)的,具有一定借鑒價(jià)值,需要的朋友可以參考下2018-02-02tensorflow實(shí)現(xiàn)圖像的裁剪和填充方法
今天小編就為大家分享一篇tensorflow實(shí)現(xiàn)圖像的裁剪和填充方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-07-07python實(shí)現(xiàn)查詢蘋果手機(jī)維修進(jìn)度
這篇文章主要介紹了python實(shí)現(xiàn)查詢蘋果手機(jī)維修進(jìn)度,這里用到了最重要的一個(gè)知識(shí)是python中如何設(shè)置cookie支持以及開(kāi)啟調(diào)試模式,需要的朋友可以參考下2015-03-03pandas.DataFrame寫入數(shù)據(jù)庫(kù)的實(shí)現(xiàn)方式
這篇文章主要介紹了pandas.DataFrame寫入數(shù)據(jù)庫(kù)的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-08-08python的格式化輸出(format,%)實(shí)例詳解
Python中格式化字符串目前有兩種陣營(yíng):%和format,哪一種比較適合我們使用呢?下面腳本之家小編給大家介紹下python的格式化輸出(format,%)實(shí)例詳解,感興趣的朋友一起看看吧2018-06-06Jupyter notebook遠(yuǎn)程訪問(wèn)服務(wù)器的方法
今天小編就為大家分享一篇Jupyter notebook遠(yuǎn)程訪問(wèn)服務(wù)器的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-05-05