-
Notifications
You must be signed in to change notification settings - Fork 0
/
vision1.py
40 lines (29 loc) · 1.29 KB
/
vision1.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
34
35
36
37
38
39
40
# coding utf-8
# ©2020 Jean-Hugues Roy. GNU GPL v3.
from azure.cognitiveservices.vision.computervision import ComputerVisionClient
from azure.cognitiveservices.vision.computervision.models import OperationStatusCodes
from azure.cognitiveservices.vision.computervision.models import VisualFeatureTypes
from msrest.authentication import CognitiveServicesCredentials
import sys, csv, time, os, requests, json
cle = "chapi" ### CHANGE POUR TA CLÉ À TOI
point = "https://chapo.cognitiveservices.azure.com/" ### CHANGE POUR TON ENDPOINT À TOI
# fin = "donneesUDA.csv"
fout = "instaOUT.csv"
# oeil = ComputerVisionClient(point, CognitiveServicesCredentials(cle))
analyze_url = point + "vision/v3.0/analyze"
fichiers = os.listdir()
for fichier in fichiers:
if fichier.endswith(".jpg"):
print(fichier)
image_data = open(fichier, "rb").read()
entetes = {'Ocp-Apim-Subscription-Key': cle,'Content-Type': 'application/octet-stream'}
params = {'visualFeatures': 'Categories,Description,Color'}
response = requests.post(analyze_url, headers=entetes, params=params, data=image_data)
response.raise_for_status()
analyse = response.json()
print(analyse)
fichierjson = fichier.replace(".jpg",".json")
# print(fichiesrjson)
with open(fichierjson, "w") as prout:
json.dump(analyse, prout)
time.sleep(3)