-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOLDAPI.py
More file actions
27 lines (24 loc) · 867 Bytes
/
OLDAPI.py
File metadata and controls
27 lines (24 loc) · 867 Bytes
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
import requests
import json
url = "https://cloudvisionapi1.cognitiveservices.azure.com/vision/v3.2/read/analyze"
KEY = "d81912de6f73464599b75f320ea5bcf2"
def fetchResults(file):
with open(f'./{file}', 'rb') as f:
data = f.read()
headers = {
'Ocp-Apim-Subscription-Key': KEY,
'Content-Type': 'image/png'
}
response = requests.request("POST", url, headers=headers, data=data)
location = response.headers['Operation-Location']
headers = {
'Ocp-Apim-Subscription-Key': KEY
}
response = requests.request("GET", location, headers=headers)
final_data = json.loads(response.text)
set_of_words_found = []
for elem in final_data['analyzeResult']['readResults']:
for el in elem["lines"]:
set_of_words_found.append(el["text"])
return set_of_words_found
print(fetchResults('./0.png'))