Fixed unknown face causing error

This commit is contained in:
slashtechno 2023-11-02 19:54:55 -05:00
parent 1cf74e13ed
commit b5d95ed963
Signed by: slashtechno
GPG Key ID: 8EC1D9D9286C2B17
3 changed files with 18 additions and 3 deletions

12
.vscode/launch.json vendored
View File

@ -4,9 +4,19 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{
"name": "Quick Debug",
"type": "python",
"request": "launch",
"module": "wyzely_detect",
"args": [
"--run-scale", "0.25", "--view-scale", "0.5", "--no-remove-representations"
],
"justMyCode": true
},
{ {
// "name": "Python: Module", // "name": "Python: Module",
"name": "Debug Wyzely Detect", "name": "Full Debug",
"type": "python", "type": "python",
"request": "launch", "request": "launch",
"module": "wyzely_detect", "module": "wyzely_detect",

View File

@ -36,7 +36,7 @@
"# cv2.imwrite(str(uuid_path), frame)\n", "# cv2.imwrite(str(uuid_path), frame)\n",
"# dfs = DeepFace.find(img_path=str(uuid_path), db_path = \"faces\")\n", "# dfs = DeepFace.find(img_path=str(uuid_path), db_path = \"faces\")\n",
"# Don't throw an error if no face is detected (enforce_detection=False)\n", "# Don't throw an error if no face is detected (enforce_detection=False)\n",
"dfs = DeepFace.find(frame, db_path = \"faces\", enforce_detection=False, silent=False, model_name=\"ArcFace\", detector_backend=\"opencv\")\n", "dfs = DeepFace.find(frame, db_path = \"faces\", enforce_detection=True, silent=False, model_name=\"ArcFace\", detector_backend=\"opencv\")\n",
"# Get the identity of the person\n", "# Get the identity of the person\n",
"for i, pd_dataframe in enumerate(dfs):\n", "for i, pd_dataframe in enumerate(dfs):\n",
" # Sort the dataframe by confidence\n", " # Sort the dataframe by confidence\n",

View File

@ -138,7 +138,12 @@ def recognize_face(
# The last row is the highest confidence # The last row is the highest confidence
# So we can just grab the path from there # So we can just grab the path from there
# iloc = Integer LOCation # iloc = Integer LOCation
try:
path_to_image = Path(df.iloc[-1]["identity"]) path_to_image = Path(df.iloc[-1]["identity"])
# Seems this is caused when someone steps into frame and their face is detected but not recognized
except IndexError:
print("Face present but not recognized")
return None
# If the parent name is the same as the path to the database, then set label to the image name instead of the parent name # If the parent name is the same as the path to the database, then set label to the image name instead of the parent name
if path_to_image.parent == Path(path_to_directory): if path_to_image.parent == Path(path_to_directory):
label = path_to_image.name label = path_to_image.name