Skip to content

Commit

Permalink
Allow registration of new faces
Browse files Browse the repository at this point in the history
* face_ident.py: Press K in the session to register
* known_people/: Registered some people
  • Loading branch information
TravorLZH committed Jun 16, 2019
1 parent 36b0e98 commit ba0e08b
Show file tree
Hide file tree
Showing 4 changed files with 403 additions and 10 deletions.
29 changes: 19 additions & 10 deletions face_ident.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,15 @@
encoding=fr.face_encodings(img)[0]
name=parts[0]
name=name.replace('_',' ')
print("Append `%s' to face library" % name)
print("Storing `%s' to face library" % name)
encodings.append(encoding)
names.append(name)

vid=cv2.VideoCapture(0)

def decorate(frame):
small=cv2.resize(frame,(0,0),fx=1.0/k,fy=1.0/k)
rgb_frame=small[...,::-1] # Convert it to RGB to increase efficiency
face_pos=fr.face_locations(rgb_frame,model="cnn")
face_codes=fr.face_encodings(rgb_frame,face_pos)
for (top,right,bottom,left),code in zip(face_pos,face_codes):
name="Unknown"
def decorate(frame,rgb_frame,face_pos,face_codes):
for i,((top,right,bottom,left),code) in enumerate(zip(face_pos,face_codes)):
name="Unknown ID %d" % i
faces=fr.compare_faces(encodings,code)
distances=fr.face_distance(encodings,code)
i=np.argmin(distances)
Expand All @@ -52,9 +48,22 @@ def decorate(frame):
break
# Create mirror image
frame=cv2.flip(frame,1)
frame=decorate(frame)
small=cv2.resize(frame,(0,0),fx=1.0/k,fy=1.0/k)
rgb_frame=small[...,::-1] # Convert it to RGB to increase efficiency
face_pos=fr.face_locations(rgb_frame,model="cnn")
face_codes=fr.face_encodings(rgb_frame,face_pos)
frame=decorate(frame,rgb_frame,face_pos,face_codes)
cv2.imshow("That is you",frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
key=cv2.waitKey(1) & 0xFF
if key==ord('q'):
break
elif key==ord('k'): # Pause
i=int(input("Enter ID: "))
name=input("Enter new name for ID %d: " % i)
filename=os.path.join(imgdir,name.replace(' ',"_")+".face")
encodings.append(face_codes[i])
names.append(name)
print("Storing `%s' to face library" % name)
np.savetxt(filename,face_codes[i])

vid.release()
128 changes: 128 additions & 0 deletions known_people/Donald_Trump.face
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
-1.020342931151390076e-01
1.200587898492813110e-01
4.850743338465690613e-02
-5.663006007671356201e-02
-9.253808110952377319e-02
-8.404755033552646637e-03
1.382903195917606354e-02
-1.903876960277557373e-01
9.820067882537841797e-02
-9.436608850955963135e-02
2.347556054592132568e-01
-4.414010047912597656e-02
-3.691104352474212646e-01
-9.668398648500442505e-02
-3.254296630620956421e-02
1.228156164288520813e-01
-1.390475779771804810e-01
-8.533739298582077026e-02
-1.955763101577758789e-01
-1.408686041831970215e-01
2.980661392211914062e-02
8.745272457599639893e-02
-1.782165467739105225e-02
-3.770576044917106628e-02
-1.174804717302322388e-01
-2.736296951770782471e-01
-7.869172841310501099e-02
-3.814060613512992859e-02
-7.620263844728469849e-03
-5.485776066780090332e-02
6.935122609138488770e-02
6.922493875026702881e-02
-1.823893040418624878e-01
-6.022018939256668091e-02
-2.130283974111080170e-02
1.246503181755542755e-02
-4.662146046757698059e-02
-3.841790556907653809e-02
1.614171415567398071e-01
2.972311899065971375e-02
-1.460627019405364990e-01
1.060663722455501556e-02
2.948180586099624634e-02
1.833506822586059570e-01
2.393800318241119385e-01
-4.832873493432998657e-02
3.741981461644172668e-02
-1.480538249015808105e-01
9.779086709022521973e-02
-2.349338680505752563e-01
-3.458290547132492065e-02
1.743777841329574585e-01
8.870637416839599609e-02
1.133315563201904297e-01
5.485950782895088196e-02
-1.195066720247268677e-01
-2.489904314279556274e-02
2.110137492418289185e-01
-1.426928043365478516e-01
6.200216710567474365e-02
6.078580766916275024e-02
-2.129787206649780273e-01
-3.641434758901596069e-02
-4.647343605756759644e-02
4.800515249371528625e-02
3.991442173719406128e-02
-5.795181542634963989e-02
-1.670650690793991089e-01
2.207440286874771118e-01
-1.732801496982574463e-01
-1.433310210704803467e-01
7.191070914268493652e-02
-6.881225109100341797e-02
-1.587972044944763184e-01
-3.396464884281158447e-01
2.559570595622062683e-02
3.667889237403869629e-01
1.831490844488143921e-01
-2.145817577838897705e-01
-3.996154665946960449e-02
-1.095595508813858032e-01
-3.886312246322631836e-02
8.711037784814834595e-02
3.777070716023445129e-02
-1.190937496721744537e-02
-1.239689290523529053e-01
-1.104131489992141724e-01
1.231338828802108765e-02
2.296476811170578003e-01
-2.641525119543075562e-02
-2.105482295155525208e-02
2.913248240947723389e-01
4.346753284335136414e-02
3.056976571679115295e-02
4.058135300874710083e-02
5.538888275623321533e-02
-1.312119662761688232e-01
-2.682563289999961853e-02
-8.838839083909988403e-02
-4.586690291762351990e-02
1.430796086788177490e-02
-1.240319460630416870e-01
3.526008501648902893e-02
9.706833958625793457e-02
-1.051599979400634766e-01
2.519935965538024902e-01
-1.844852976500988007e-02
1.836628839373588562e-02
-4.327420517802238464e-02
-1.000218689441680908e-01
3.883952647447586060e-02
7.529310137033462524e-02
2.026244550943374634e-01
-1.703071296215057373e-01
2.097851037979125977e-01
1.904078572988510132e-01
-1.702325046062469482e-02
1.447537392377853394e-01
6.791721284389495850e-02
8.399353921413421631e-02
-6.954259425401687622e-02
-7.175317406654357910e-02
-1.748209744691848755e-01
-1.402127444744110107e-01
6.510082632303237915e-03
-1.180696394294500351e-02
3.934037312865257263e-02
3.240234032273292542e-02
128 changes: 128 additions & 0 deletions known_people/Mr_Zhu.face
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
-7.355438917875289917e-02
1.373609751462936401e-01
9.756255149841308594e-02
-6.498730927705764771e-02
-4.906767979264259338e-02
-5.101280659437179565e-02
-8.590562641620635986e-02
-1.129110902547836304e-01
8.909698575735092163e-02
-7.981204986572265625e-02
2.759754061698913574e-01
-4.155012592673301697e-02
-1.567892432212829590e-01
-1.967596709728240967e-01
-8.487291634082794189e-02
1.737896502017974854e-01
-1.759859621524810791e-01
-1.378223150968551636e-01
-5.696194246411323547e-02
-2.969358861446380615e-02
1.655838042497634888e-01
6.527515500783920288e-02
-1.513766497373580933e-02
-3.288621455430984497e-02
-1.272971630096435547e-01
-3.458005487918853760e-01
-6.853707134723663330e-02
-5.770307034254074097e-02
3.317193686962127686e-02
-5.881768092513084412e-02
-1.736049354076385498e-02
7.271074503660202026e-02
-1.887504458427429199e-01
-7.001717388629913330e-02
3.037430718541145325e-02
9.417869150638580322e-02
-4.676074534654617310e-02
-3.914079815149307251e-02
1.409570127725601196e-01
-8.900620043277740479e-03
-2.067425101995468140e-01
9.429360181093215942e-02
2.207532525062561035e-02
2.803470790386199951e-01
2.492480278015136719e-01
9.273961186408996582e-03
5.031063035130500793e-02
-1.211516410112380981e-01
1.410976052284240723e-01
-1.516423821449279785e-01
4.651401191949844360e-03
1.769452393054962158e-01
8.623350411653518677e-02
8.951820433139801025e-02
4.336046054959297180e-02
-6.670949608087539673e-02
1.473864540457725525e-02
1.501462906599044800e-01
-1.256725788116455078e-01
5.050266161561012268e-03
8.287856727838516235e-02
-1.411949098110198975e-01
-1.433263346552848816e-02
-1.049573570489883423e-01
1.614230573177337646e-01
4.762198776006698608e-03
-1.270188242197036743e-01
-1.731928437948226929e-01
1.462906301021575928e-01
-9.616811573505401611e-02
-1.157431602478027344e-01
5.230129882693290710e-02
-1.716981679201126099e-01
-1.260527521371841431e-01
-3.288218677043914795e-01
3.245067596435546875e-02
3.760630488395690918e-01
8.583465218544006348e-02
-2.299163639545440674e-01
5.837657302618026733e-02
-9.343139827251434326e-03
4.981565475463867188e-02
1.635300368070602417e-01
1.496027708053588867e-01
8.882205933332443237e-03
1.854525879025459290e-02
-9.231759607791900635e-02
3.448739647865295410e-03
2.127969712018966675e-01
-4.840007424354553223e-02
-7.051850855350494385e-02
2.086415290832519531e-01
-8.034877479076385498e-03
9.861498326063156128e-02
4.351300001144409180e-02
-9.519420564174652100e-03
-4.186411947011947632e-02
4.625216126441955566e-02
-1.259805560111999512e-01
2.617566473782062531e-02
4.512518644332885742e-03
-3.753003478050231934e-02
-3.694711625576019287e-02
1.229228824377059937e-01
-3.351051360368728638e-02
1.627100110054016113e-01
3.593681380152702332e-03
1.331358104944229126e-01
-2.247733063995838165e-02
-5.238573998212814331e-02
-6.412017345428466797e-02
-1.561401411890983582e-02
9.671727567911148071e-02
-1.802742034196853638e-01
2.333934307098388672e-01
1.688493043184280396e-01
7.437217235565185547e-02
9.416627883911132812e-02
1.683755367994308472e-01
4.807676747441291809e-02
-1.831506565213203430e-02
-3.418589383363723755e-02
-2.292943894863128662e-01
-4.243741184473037720e-02
9.621351957321166992e-02
-2.459418401122093201e-02
1.011348292231559753e-01
-1.530571095645427704e-02
Loading

0 comments on commit ba0e08b

Please sign in to comment.