-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFaceDetection.py
More file actions
70 lines (51 loc) · 1.73 KB
/
FaceDetection.py
File metadata and controls
70 lines (51 loc) · 1.73 KB
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
## load the library and files
import cv2
import numpy as np
import matplotlib.pyplot as plt
import os
import face_recognition
class setAndGetName:
"""
this class is created for set and get the current person name.
"""
def __init__(self):
self.name = "NoPerson"
## this is used for get the current person on the frame
@property
def getName(self):
# time.sleep(2)
return self.name
## this is used for set the name of the person
@getName.setter
def setName(self,newName):
self.name = newName
## created the one object
ObjectName = setAndGetName()
def EncodeFaceData():
"""
enocde face data which is used as training data set.
return face encoded data and person name.
"""
## Variables for known face encoder and there name
knowFaceEncoder = []
knowFaceName = []
## take pata from the disk
currentPath = os.getcwd()
listpath = currentPath + "/FaceData"
## get the list of picture. it use as train data
listOfPicture = os.listdir(listpath)
## taking name of person and there face data from the list of picture
for i in range(len(listOfPicture)):
name = listOfPicture[i].split(".")[0]
knowFaceName.append(name)
fileName = "FaceData/" + listOfPicture[i]
img = face_recognition.load_image_file(fileName)
faceEncoding = face_recognition.face_encodings(img)[0]
knowFaceEncoder.append(faceEncoding)
# print(knowFaceName)
# print(knowFaceEncoder)
## return knowFaceName, and there Enoceding
return (knowFaceName,knowFaceEncoder)
## this function just return the name of the person
def getName():
return ObjectName.getName