96 lines
2.6 KiB
Plaintext
96 lines
2.6 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from deepface import DeepFace\n",
|
|
"import cv2\n",
|
|
"from pathlib import Path\n",
|
|
"import uuid\n",
|
|
"import pandas as pd"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Take pictures"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Take a picture using opencv with <uuid>.jpg\n",
|
|
"# Then delete it after\n",
|
|
"cap = cv2.VideoCapture(0)\n",
|
|
"ret, frame = cap.read()\n",
|
|
"cap.release()\n",
|
|
"# uuid_str = str(uuid.uuid4())\n",
|
|
"# uuid_path = Path(uuid_str + \".jpg\")\n",
|
|
"# cv2.imwrite(str(uuid_path), frame)\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",
|
|
"dfs = DeepFace.find(frame, db_path = \"faces\", enforce_detection=False)\n",
|
|
"# Get the identity of the person\n",
|
|
"for i, pd_dataframe in enumerate(dfs):\n",
|
|
" # Sort the dataframe by confidence\n",
|
|
" # inplace=True means that the dataframe is modified so we don't need to assign it to a new variable\n",
|
|
" pd_dataframe.sort_values(by=['VGG-Face_cosine'], inplace=True, ascending=False)\n",
|
|
" print(f'On dataframe {i}')\n",
|
|
" print(pd_dataframe)\n",
|
|
" # Get the most likely identity\n",
|
|
" # print(f'Most likely identity: {pd_dataframe.iloc[0][\"identity\"]}')\n",
|
|
" # We could use Path to get the parent directory of the image to use as the identity\n",
|
|
" print(f'Most likely identity: {Path(pd_dataframe.iloc[0][\"identity\"]).parent.name}')\n",
|
|
" # Get the most likely identity's confidence\n",
|
|
" print(f'Confidence: {pd_dataframe.iloc[0][\"VGG-Face_cosine\"]}')\n",
|
|
"\n",
|
|
"# uuid_path.unlink()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Stream"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"DeepFace.stream(db_path=\"faces\")"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": ".venv",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.10.5"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|