欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python3使用騰訊云文字識(shí)別(騰訊OCR)提取圖片中的文字內(nèi)容實(shí)例詳解

 更新時(shí)間:2020年02月18日 14:31:59   作者:彭世瑜  
這篇文章主要介紹了Python3使用騰訊云文字識(shí)別(騰訊OCR)提取圖片中的文字內(nèi)容方法詳解,需要的朋友可以參考下

百度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)鏈接

相關(guān)文章

最新評(píng)論