-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsearch_index_face.py
29 lines (28 loc) · 1.04 KB
/
search_index_face.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
import boto3
import sys
import json
import sqlite3
from datetime import datetime
conn = sqlite3.connect('mark.db')
collection_name = "ANything_here"
image_file = str(sys.argv[1])
now = datetime.now()
formatted_date = now.strftime('%Y-%m-%d %H:%M:%S')
def search_faces_by_image():
# assumes aws default region and credentials
rekognition_client = boto3.client('rekognition')
with open(image_file, 'rb') as image:
rekognition_response = rekognition_client.search_faces_by_image(
Image={'Bytes': image.read()},
CollectionId=collection_name)
try:
output = rekognition_response['FaceMatches'][0]['Face']['ExternalImageId']
#print(output)
conn.execute("INSERT INTO ATT(NAME,DATE) VALUES(?, ?)",(output, formatted_date))
conn.commit()
conn.close()
print("uploaded to database successfully")
except IndexError:
print("User not registered, please register first. Contact Dept")
search_faces_by_image()
''' module fetches image result + stores into mark.db '''