"pose = np.array([[res.x,res.y,res.z,res.visibility] for res in results.pose_landmarks.landmark]).flatten() if results.pose_landmarks else np.zeros(132)\n",
"face = np.array([[res.x, res.y, res.z] for res in results.face_landmarks.landmark]).flatten() if results.face_landmarks else np.zeros(1404)\n",
"lh = np.array([[res.x, res.y, res.z] for res in results.left_hand_landmarks.landmark]).flatten() if results.left_hand_landmarks else np.zeros(21*3)\n",
"rh = np.array([[res.x, res.y, res.z] for res in results.right_hand_landmarks.landmark]).flatten() if results.right_hand_landmarks else np.zeros(21*3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cdba5b51",
"metadata": {},
"outputs": [],
"source": [
"def extract_keypoints(results):\n",
" pose = np.array([[res.x, res.y, res.z, res.visibility] for res in results.pose_landmarks.landmark]).flatten() if results.pose_landmarks else np.zeros(33*4)\n",
" face = np.array([[res.x, res.y, res.z] for res in results.face_landmarks.landmark]).flatten() if results.face_landmarks else np.zeros(468*3)\n",
" lh = np.array([[res.x, res.y, res.z] for res in results.left_hand_landmarks.landmark]).flatten() if results.left_hand_landmarks else np.zeros(21*3)\n",
" rh = np.array([[res.x, res.y, res.z] for res in results.right_hand_landmarks.landmark]).flatten() if results.right_hand_landmarks else np.zeros(21*3)\n",
"\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n",
"ipython 8.24.0 requires typing-extensions>=4.6; python_version < \"3.12\", but you have typing-extensions 4.5.0 which is incompatible.\u001b[0m\u001b[31m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip available: \u001b[0m\u001b[31;49m22.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
"Collecting mediapipe==0.10.3\n",
" Using cached mediapipe-0.10.3-cp310-cp310-macosx_11_0_universal2.whl (53.5 MB)\n",
"Collecting opencv-contrib-python\n",
" Using cached opencv_contrib_python-4.9.0.80-cp37-abi3-macosx_11_0_arm64.whl (44.2 MB)\n",
"Requirement already satisfied: numpy in ./venv/lib/python3.10/site-packages (from mediapipe==0.10.3) (1.24.3)\n",
"Collecting sounddevice>=0.4.4\n",
" Using cached sounddevice-0.4.6-py3-none-macosx_10_6_x86_64.macosx_10_6_universal2.whl (107 kB)\n",
"Collecting matplotlib\n",
" Using cached matplotlib-3.9.0-cp310-cp310-macosx_11_0_arm64.whl (7.8 MB)\n",
"Requirement already satisfied: flatbuffers>=2.0 in ./venv/lib/python3.10/site-packages (from mediapipe==0.10.3) (24.3.25)\n",
"Requirement already satisfied: absl-py in ./venv/lib/python3.10/site-packages (from mediapipe==0.10.3) (2.1.0)\n",
"Collecting attrs>=19.1.0\n",
" Using cached attrs-23.2.0-py3-none-any.whl (60 kB)\n",
"Collecting protobuf<4,>=3.11\n",
" Using cached protobuf-3.20.3-py2.py3-none-any.whl (162 kB)\n",
"Collecting CFFI>=1.0\n",
" Using cached cffi-1.16.0-cp310-cp310-macosx_11_0_arm64.whl (176 kB)\n",
"Collecting contourpy>=1.0.1\n",
" Using cached contourpy-1.2.1-cp310-cp310-macosx_11_0_arm64.whl (244 kB)\n",
"Requirement already satisfied: packaging>=20.0 in ./venv/lib/python3.10/site-packages (from matplotlib->mediapipe==0.10.3) (24.0)\n",
"Requirement already satisfied: python-dateutil>=2.7 in ./venv/lib/python3.10/site-packages (from matplotlib->mediapipe==0.10.3) (2.9.0.post0)\n",
"Collecting pillow>=8\n",
" Using cached pillow-10.3.0-cp310-cp310-macosx_11_0_arm64.whl (3.4 MB)\n",
"Collecting pyparsing>=2.3.1\n",
" Using cached pyparsing-3.1.2-py3-none-any.whl (103 kB)\n",
"Collecting kiwisolver>=1.3.1\n",
" Using cached kiwisolver-1.4.5-cp310-cp310-macosx_11_0_arm64.whl (66 kB)\n",
"Collecting fonttools>=4.22.0\n",
" Using cached fonttools-4.51.0-cp310-cp310-macosx_10_9_universal2.whl (2.8 MB)\n",
"Collecting cycler>=0.10\n",
" Using cached cycler-0.12.1-py3-none-any.whl (8.3 kB)\n",
"Collecting pycparser\n",
" Using cached pycparser-2.22-py3-none-any.whl (117 kB)\n",
"Requirement already satisfied: six>=1.5 in ./venv/lib/python3.10/site-packages (from python-dateutil>=2.7->matplotlib->mediapipe==0.10.3) (1.16.0)\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip available: \u001b[0m\u001b[31;49m22.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
"Collecting scikit-learn==1.3.1\n",
" Using cached scikit_learn-1.3.1-cp310-cp310-macosx_12_0_arm64.whl (9.5 MB)\n",
"Collecting scipy>=1.5.0\n",
" Using cached scipy-1.13.0-cp310-cp310-macosx_12_0_arm64.whl (30.3 MB)\n",
"Collecting threadpoolctl>=2.0.0\n",
" Using cached threadpoolctl-3.5.0-py3-none-any.whl (18 kB)\n",
"Requirement already satisfied: numpy<2.0,>=1.17.3 in ./venv/lib/python3.10/site-packages (from scikit-learn==1.3.1) (1.24.3)\n",
"Collecting joblib>=1.1.1\n",
" Using cached joblib-1.4.2-py3-none-any.whl (301 kB)\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip available: \u001b[0m\u001b[31;49m22.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
"Collecting opencv-python==4.9.0.80\n",
" Using cached opencv_python-4.9.0.80-cp37-abi3-macosx_11_0_arm64.whl (35.4 MB)\n",
"Requirement already satisfied: numpy>=1.17.0 in ./venv/lib/python3.10/site-packages (from opencv-python==4.9.0.80) (1.24.3)\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip available: \u001b[0m\u001b[31;49m22.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
"Collecting matplotlib==3.8.3\n",
" Using cached matplotlib-3.8.3-cp310-cp310-macosx_11_0_arm64.whl (7.5 MB)\n",
"Requirement already satisfied: numpy<2,>=1.21 in ./venv/lib/python3.10/site-packages (from matplotlib==3.8.3) (1.24.3)\n",
"Requirement already satisfied: python-dateutil>=2.7 in ./venv/lib/python3.10/site-packages (from matplotlib==3.8.3) (2.9.0.post0)\n",
"Requirement already satisfied: fonttools>=4.22.0 in ./venv/lib/python3.10/site-packages (from matplotlib==3.8.3) (4.51.0)\n",
"Requirement already satisfied: pillow>=8 in ./venv/lib/python3.10/site-packages (from matplotlib==3.8.3) (10.3.0)\n",
"Requirement already satisfied: contourpy>=1.0.1 in ./venv/lib/python3.10/site-packages (from matplotlib==3.8.3) (1.2.1)\n",
"Requirement already satisfied: pyparsing>=2.3.1 in ./venv/lib/python3.10/site-packages (from matplotlib==3.8.3) (3.1.2)\n",
"Requirement already satisfied: cycler>=0.10 in ./venv/lib/python3.10/site-packages (from matplotlib==3.8.3) (0.12.1)\n",
"Requirement already satisfied: packaging>=20.0 in ./venv/lib/python3.10/site-packages (from matplotlib==3.8.3) (24.0)\n",
"Requirement already satisfied: kiwisolver>=1.3.1 in ./venv/lib/python3.10/site-packages (from matplotlib==3.8.3) (1.4.5)\n",
"Requirement already satisfied: six>=1.5 in ./venv/lib/python3.10/site-packages (from python-dateutil>=2.7->matplotlib==3.8.3) (1.16.0)\n",
"Installing collected packages: matplotlib\n",
" Attempting uninstall: matplotlib\n",
" Found existing installation: matplotlib 3.9.0\n",
" Uninstalling matplotlib-3.9.0:\n",
" Successfully uninstalled matplotlib-3.9.0\n",
"Successfully installed matplotlib-3.8.3\n",
"\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip available: \u001b[0m\u001b[31;49m22.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n"
]
}
],
"source": [
"!pip install tensorflow==2.13.0\n",
"!pip install mediapipe==0.10.3\n",
"!pip install scikit-learn==1.3.1\n",
"!pip install opencv-python==4.9.0.80\n",
"!pip install matplotlib==3.8.3"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "0cdb80ee",
"metadata": {},
"outputs": [],
"source": [
"import cv2\n",
"import numpy as np\n",
"import os\n",
"from matplotlib import pyplot as plt\n",
"import time\n",
"import mediapipe as mp"
]
},
{
"cell_type": "markdown",
"id": "c823bc27",
"metadata": {},
"source": [
"# Collecting keypoints from mediapipe holistics"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "81a10b4a",
"metadata": {},
"outputs": [],
"source": [
"mp_holistic = mp.solutions.holistic #we are bringing the holistic model of mideapipe\n",
"mp_drawing = mp.solutions.drawing_utils #we are also bringing the drawing utilities of mideapipe."
" pose = np.array([[res.x, res.y, res.z, res.visibility] for res in results.pose_landmarks.landmark]).flatten() if results.pose_landmarks else np.zeros(33*4)\n",
" face = np.array([[res.x, res.y, res.z] for res in results.face_landmarks.landmark]).flatten() if results.face_landmarks else np.zeros(468*3)\n",
" lh = np.array([[res.x, res.y, res.z] for res in results.left_hand_landmarks.landmark]).flatten() if results.left_hand_landmarks else np.zeros(21*3)\n",
" rh = np.array([[res.x, res.y, res.z] for res in results.right_hand_landmarks.landmark]).flatten() if results.right_hand_landmarks else np.zeros(21*3)\n",
"2024-05-19 09:25:34.535 Python[49219:945613] WARNING: Secure coding is not enabled for restorable state! Enable secure coding by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState: and returning YES.\n"