-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadd_person_faces.py
53 lines (46 loc) · 1.45 KB
/
add_person_faces.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
41
42
43
44
45
46
47
48
49
50
51
52
53
import sys
import os
import time
from global_variables import personGroupId
import urllib
import sqlite3
import asyncio
import io
import glob
import os
import sys
import time
import uuid
import requests
from urllib.parse import urlparse
from io import BytesIO
from PIL import Image, ImageDraw
from azure.cognitiveservices.vision.face import FaceClient
from msrest.authentication import CognitiveServicesCredentials
from azure.cognitiveservices.vision.face.models import TrainingStatusType, Person, SnapshotObjectType, OperationStatusType
from global_variables import personGroupId
KEY = '2698a28d0b3a47be9a0177011b4fca38'
# Replace with your regional Base URL
ENDPOINT = 'https://hackcovid.cognitiveservices.azure.com/'
face_client = FaceClient(ENDPOINT, CognitiveServicesCredentials(KEY))
def get_person_id():
person_id = ''
extractId = str(sys.argv[1])[-2:]
connect = sqlite3.connect("Face-DataBase")
c = connect.cursor()
cmd = "SELECT * FROM Students WHERE ID = " + extractId
c.execute(cmd)
row = c.fetchone()
person_id = row[3]
connect.close()
return person_id
if len(sys.argv) is not 1:
images = glob.glob(os.getcwd() + '/dataset/' + str(sys.argv[1]) + '/*.jpg')
person_id = get_person_id()
for image in images:
w = open(image, 'r+b')
print("reading")
result = face_client.person_group_person.add_face_from_stream(
personGroupId, person_id, w)
print(result)
time.sleep(6)