-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
104 lines (88 loc) · 3.35 KB
/
test.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import boto3
import mysql.connector as ms
import os
from flask import Flask, flash, request, redirect, url_for
from werkzeug.utils import secure_filename
def open_database_connection():
return ms.connect(user='admin', password='adminadmin',
host='pennapps.ccd5u6srhchk.us-east-2.rds.amazonaws.com',
database='innodb')
def convert_to_binary_data(filename):
with open(filename, 'rb') as file:
binaryData = file.read()
return binaryData
def update_parent_db(name, age, gender, location, phone, image):
cnx = open_database_connection()
mycursor = cnx.cursor()
query = "INSERT INTO innodb.parents (child_name, age, gender, location, phone, image) VALUES ('" + name + "', " + str(age) + ", '" + gender + "', '" + location + "', " + str(phone) + ", '" + image + "')"
mycursor.execute(query)
cnx.commit()
# result = mycursor.fetchall()
cnx.close()
def update_concerned_citicen_db(name, age, gender, location, phone, image):
cnx = open_database_connection()
mycursor = cnx.cursor()
query = "INSERT INTO innodb.concerned_citizen (child_name, age, gender, location, phone, image) VALUES ('" + name + "', " + str(age) + ", '" + gender + "', '" + location + "', " + str(phone) + ", '" + image + "')"
mycursor.execute(query)
cnx.commit()
# result = mycursor.fetchall()
cnx.close()
def compare(img1, img2):
sourceFile = img1
targetFile = img2
client = boto3.client('rekognition')
imageSource = open(sourceFile, 'rb')
imageTarget = open(targetFile, 'rb')
response = client.compare_faces(SimilarityThreshold=70,
SourceImage={'Bytes': imageSource.read()},
TargetImage={'Bytes': imageTarget.read()})
if response['FaceMatches'] == []:
return None
faceMatch = response['FaceMatches'][0]
similarity = str(faceMatch['Similarity'])
imageSource.close()
imageTarget.close()
return similarity
def compare_all_parent(img):
cnx = open_database_connection()
mycursor = cnx.cursor()
query = "Select image from innodb.parents"
mycursor.execute(query)
images = mycursor.fetchall()
possible_images = []
for image in images:
similarity = compare(img, "static/imagesP/" + image[0])
if similarity == None or int(float(similarity)) <= 90:
continue
else:
if int(float(similarity)) >= 95:
cnx.close()
return image[0]
else:
possible_images.append(image)
if len(possible_images) == 0:
return None
cnx.close()
return possible_images
def compare_all_concerned_citizen(img):
cnx = open_database_connection()
mycursor = cnx.cursor()
query = "Select image from innodb.concerned_citizen"
mycursor.execute(query)
images = mycursor.fetchall()
possible_images = []
print(images)
for image in images:
similarity = compare(img, "static/imagesC/" + image[0])
if similarity == None or int(float(similarity)) <= 90:
continue
else:
if int(float(similarity)) >= 95:
cnx.close()
return image[0]
else:
possible_images.append(image)
if len(possible_images) == 0:
return None
cnx.close()
return possible_images