Python3使用騰訊云文字識別(騰訊OCR)提取圖片中的文字內(nèi)容實例詳解
百度OCR體驗地址:
https://ai.baidu.com/tech/imagerecognition/general
騰訊OCR體驗地址:
https://cloud.tencent.com/act/event/ocrdemo
測試結(jié)果是:騰訊的效果要比百度的好
騰訊云目前額度是:
每個接口 1,000次/月免費,有6個文字識別的接口,一共是6,000次/月
百度接口調(diào)用之前寫過文章
使用步驟
1、注冊賬號: https://cloud.tencent.com/
2、開通服務:https://console.cloud.tencent.com/ocr/general
3、申請訪問秘鑰:https://console.cloud.tencent.com/cam/capi
4、通過 API 或 SDK 或命令行來使用服務
具體參考《操作指南》:https://cloud.tencent.com/document/product/866/17622
接口使用
1、安裝SDK
https://github.com/TencentCloud/tencentcloud-sdk-python
pip3 install tencentcloud-sdk-python
2、代碼實例
# -*- 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): """ 計費說明:1,000次/月免費 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" # 通用文字識別相關(guān)接口 # https://cloud.tencent.com/document/api/866/37173 mapping = { # 通用印刷體識別(高精度版) ok "GeneralAccurateOCR": GeneralAccurateOCRRequest, # 英文識別 ok "EnglishOCR": EnglishOCRRequest, # 通用印刷體識別 一般 "GeneralBasicOCR": GeneralBasicOCRRequest, # 通用印刷體識別(精簡版)(免費公測版)no "GeneralEfficientOCR": GeneralEfficientOCRRequest, # 通用印刷體識別(高速版)一般 "GeneralFastOCR": GeneralFastOCRRequest, # 通用手寫體識別 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使用騰訊云文字識別(騰訊OCR)提取圖片中的文字內(nèi)容實例請查看下面的相關(guān)鏈接
相關(guān)文章
使用Python發(fā)送Post請求以及解析響應結(jié)果
發(fā)送post的請求參考例子很簡單,實際遇到的情況卻是很復雜的,下面這篇文章主要給大家介紹了關(guān)于如何使用Python發(fā)送Post請求以及解析響應結(jié)果的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2023-06-06pandas.DataFrame寫入數(shù)據(jù)庫的實現(xiàn)方式
這篇文章主要介紹了pandas.DataFrame寫入數(shù)據(jù)庫的實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-08-08