Skip to content

Commit

Permalink
Handle invalid input
Browse files Browse the repository at this point in the history
* .gitignore: Accept no more .face files in the tree
* face_ident.py: Handle `ValueError' when input is invalid,
	this also prevents quitting a session when pressing K by
	accident
  • Loading branch information
TravorLZH committed Jun 19, 2019
1 parent ba0e08b commit 2a95e15
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.face
22 changes: 15 additions & 7 deletions face_ident.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def decorate(frame,rgb_frame,face_pos,face_codes):
cv2.FONT_HERSHEY_DUPLEX,1.0,(0xFF,0xFF,0xFF),1)
return frame

# Do nothing
def nop():
return None

while vid.isOpened():
ret,frame=vid.read()
if ret==False:
Expand All @@ -58,12 +62,16 @@ def decorate(frame,rgb_frame,face_pos,face_codes):
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])
data=input("Enter ID: ")
try:
i=int(data)
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])
except ValueError:
print("Invalid Input, continue session")

vid.release()

0 comments on commit 2a95e15

Please sign in to comment.