-
Notifications
You must be signed in to change notification settings - Fork 0
/
ocrimage.py
33 lines (28 loc) · 3.52 KB
/
ocrimage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# coding: utf-8
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkocr.v1.region.ocr_region import OcrRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkocr.v1 import *
if __name__ == "__main__":
ak = "8TZ6BMUOMWO9BORZI0GG"
sk = "2bFlDAwKF7zidUYHOzUfnoTuI3hKDOwyp7ClLgAt"
credentials = BasicCredentials(ak, sk) # 替换为实际的AK和SK
client = OcrClient.new_builder() \
.with_credentials(credentials) \
.with_region(OcrRegion.value_of("cn-north-4")) \
.build()
try:
request = RecognizeGeneralTextRequest()
request.body = GeneralTextRequestBody(
image="iVBORw0KGgoAAAANSUhEUgAAADwAAAAUCAYAAADRA14pAAAHJ0lEQVRYR23YR6tUSxQF4LrmnBUVDDgQBP+NOBMRA+accxZzxoAgDgTH/hIn4kQUA+acs/36q8fqd7zPgqZPn7Nr19prx9NdpZTW0KFDy7t370pXV1dptVqlf//+5cuXL6VPnz719+/fv0uPHj3Kjx8/2uKlDBgwoHz+/LleZ40ePbq8ePHij3u9e/eu+3/+/NnRTWDgwIHl06dP/5Olf/DgweXDhw9lyJAh5f3796Vnz57l169fVRae79+/l169elWd+W7KODM4c07so6Or/aN1586dMnLkyKqUsE25jmL3GWohADk+Wc+fP68gDx8+XEaNGlVu375dxowZU5YsWVIcaD/SgAMa+CyGHTt2rBowf/78Mm7cuM4zxtpjff36tfTr1698+/atXLx4scyaNauMGDGivHr1qn438ZB3P3Zx4LBhwwrEbSe0KouA9O3bt7KP6b+tN2/elOHDh1cviAQgu6+PHz+WQYMG1dsBTCfGrdevX1dSyTRBxhDk7du3748zkILQ6GH82bNnK5HLly/vnBdi2EJeJHKa6+qkNnstN2KIDYzhTcwiw2EI4FkGNll3Y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BtUc1gn40AGCev0T0DtPX36dG03KWaJjmfPntXWwjPkmq0KwGvXrpUZM2bUszInI2Hy5Mll0aJF1SjeN3sjxhIRDJZ2lvojIhVBBEubrvag37p161ZlltHN9pTxLR6nRMvQDrIoyvMUj0xuiHCt4GTMZJh706dPL/fv36/GOjN5lqJnAgtw9cK+kCZMN23a9Ee1f/DgQfUgAmFKNU9EIYO+6mHTCcYxmRzKaxqGVq9eXXOsOVUBnbyJ8SkcTdI8YyzvB0gmrOR1wjvVOsQ1I4msAiR0m2OpfObJjLfxNGzNFxaEGYY6g0czfF0rFEDyEvaFA2blhepoQAEiM6qcOXr0aGU2r5LCXEHLEBADQpa99CScQ5woun79erl582ZNIwZKqSlTptTUefz4cTlz5kxnglKkeFCup6fnZSizBN379+//rw9nosIKYMLb8MBYORjWFavLly9XENpRs2ApDPbS5dryYiDUpM3UqVPLzJkz63uylTNTJ5oDRGqJZ4xbv359jRTRKBKRMW3atOoIVRgeESCHQ2Rzsnv48OF/RUtI1R7VeKEPCJvkExlGpDdTSvmyZcsqKe6vW7euFhJLD5a7iJs9e3bnpd4r36NHjyqJeedutqG8k8MSb2ltwjE5LBdVbfkJg/3y3ChrxWA2wIN0q9rYFmzlhX/x4sVVsYIQD+UlmrBGvmXLlk7BYigyACEvDSzXzb9VeIQnrLzhpEaE5BCZOsDwprywTRFz/8qVK2XOnDnVUNXb8yz/uEgLGOBFrqUe/QPKJeZ0Jw6zfwAAAABJRU5ErkJggg=="
)
response = client.recognize_general_text(request)
print(response)
response_dict = response.to_dict()
words = response_dict['result']['words_block_list'][0]['words']
print(words)
except exceptions.ClientRequestException as e:
print(e.status_code)
print(e.request_id)
print(e.error_code)
print(e.error_msg)