This repository has been archived by the owner on Jun 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetails.py
65 lines (58 loc) · 1.83 KB
/
details.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
import face_recognition
import picamera
import numpy as np
import os
import pymysql
import sys
camera = picamera.PiCamera()
camera.resolution = (320, 240)
output = np.empty((240, 320, 3), dtype=np.uint8)
#cre for rds instance
REGION = 'us-east-1'
rds_host = "epics.cchqlmtm8iyr.us-east-1.rds.amazonaws.com"
name = "Rishabh"
password = "chitkara"
db_name = "epics"
def save_data(data):
"""
This function fetches content from mysql RDS instance
"""
result = []
conn = pymysql.connect(rds_host, user=name, passwd=password, db=db_name, connect_timeout=5)
with conn.cursor() as cur:
cur.execute("""insert into studentDetails (id, name) values( %s, '%s')""" % (data['id'], data['name']))
cur.execute("""select * from studentDetails""")
conn.commit()
cur.close()
for row in cur:
result.append(list(row))
print ("Data from RDS...")
print (result)
def createFolder(path):
try:
if not os.path.exists("dataset/" + path) :
os.makedirs("dataset/" + path)
except OSError:
print("Error: creating directory" + path)
#intializing the empty dict for student data
data = {}
print("Capturing images")
i = 0
while True:
data["id"] = input("Enter the id: ")
data["name"] = input("Enter the name: ")
createFolder(data["name"])
os.chdir("dataset/" + data["name"])
for j in range(5):
camera.capture(data["id"] + "-" + str(j) + ".jpg")
output = face_recognition.load_image_file(data["id"] + "-" + str(j) + ".jpg")
#new image encoding
face_encodings = face_recognition.face_encodings(output)
#checking that a face is there or not
if len(face_encodings) == 0:
print("Please show a face")
continue
os.chdir("../../")
#saving data to the database
save_data(data)
i += 1