{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 0. Install and Import Dependencies" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: mediapipe in .\\.venv\\lib\\site-packages (0.10.21)\n", "Requirement already satisfied: opencv-python in .\\.venv\\lib\\site-packages (4.11.0.86)\n", "Requirement already satisfied: pandas in .\\.venv\\lib\\site-packages (2.3.2)\n", "Requirement already satisfied: scikit-learn in .\\.venv\\lib\\site-packages (1.7.1)\n", "Requirement already satisfied: absl-py in .\\.venv\\lib\\site-packages (from mediapipe) (2.3.1)\n", "Requirement already satisfied: attrs>=19.1.0 in .\\.venv\\lib\\site-packages (from mediapipe) (25.3.0)\n", "Requirement already satisfied: flatbuffers>=2.0 in .\\.venv\\lib\\site-packages (from mediapipe) (25.2.10)\n", "Requirement already satisfied: jax in .\\.venv\\lib\\site-packages (from mediapipe) (0.7.1)\n", "Requirement already satisfied: jaxlib in .\\.venv\\lib\\site-packages (from mediapipe) (0.7.1)\n", "Requirement already satisfied: matplotlib in .\\.venv\\lib\\site-packages (from mediapipe) (3.10.6)\n", "Requirement already satisfied: numpy<2 in .\\.venv\\lib\\site-packages (from mediapipe) (1.26.4)\n", "Requirement already satisfied: opencv-contrib-python in .\\.venv\\lib\\site-packages (from mediapipe) (4.11.0.86)\n", "Requirement already satisfied: protobuf<5,>=4.25.3 in .\\.venv\\lib\\site-packages (from mediapipe) (4.25.8)\n", "Requirement already satisfied: sounddevice>=0.4.4 in .\\.venv\\lib\\site-packages (from mediapipe) (0.5.2)\n", "Requirement already satisfied: sentencepiece in .\\.venv\\lib\\site-packages (from mediapipe) (0.2.1)\n", "Requirement already satisfied: python-dateutil>=2.8.2 in .\\.venv\\lib\\site-packages (from pandas) (2.9.0.post0)\n", "Requirement already satisfied: pytz>=2020.1 in .\\.venv\\lib\\site-packages (from pandas) (2025.2)\n", "Requirement already satisfied: tzdata>=2022.7 in .\\.venv\\lib\\site-packages (from pandas) (2025.2)\n", "Requirement already satisfied: scipy>=1.8.0 in .\\.venv\\lib\\site-packages (from scikit-learn) (1.16.1)\n", "Requirement already satisfied: joblib>=1.2.0 in .\\.venv\\lib\\site-packages (from scikit-learn) (1.5.2)\n", "Requirement already satisfied: threadpoolctl>=3.1.0 in .\\.venv\\lib\\site-packages (from scikit-learn) (3.6.0)\n", "Requirement already satisfied: six>=1.5 in .\\.venv\\lib\\site-packages (from python-dateutil>=2.8.2->pandas) (1.17.0)\n", "Requirement already satisfied: CFFI>=1.0 in .\\.venv\\lib\\site-packages (from sounddevice>=0.4.4->mediapipe) (1.17.1)\n", "Requirement already satisfied: pycparser in .\\.venv\\lib\\site-packages (from CFFI>=1.0->sounddevice>=0.4.4->mediapipe) (2.22)\n", "Requirement already satisfied: ml_dtypes>=0.5.0 in .\\.venv\\lib\\site-packages (from jax->mediapipe) (0.5.3)\n", "Requirement already satisfied: opt_einsum in .\\.venv\\lib\\site-packages (from jax->mediapipe) (3.4.0)\n", "Requirement already satisfied: contourpy>=1.0.1 in .\\.venv\\lib\\site-packages (from matplotlib->mediapipe) (1.3.3)\n", "Requirement already satisfied: cycler>=0.10 in .\\.venv\\lib\\site-packages (from matplotlib->mediapipe) (0.12.1)\n", "Requirement already satisfied: fonttools>=4.22.0 in .\\.venv\\lib\\site-packages (from matplotlib->mediapipe) (4.59.2)\n", "Requirement already satisfied: kiwisolver>=1.3.1 in .\\.venv\\lib\\site-packages (from matplotlib->mediapipe) (1.4.9)\n", "Requirement already satisfied: packaging>=20.0 in .\\.venv\\lib\\site-packages (from matplotlib->mediapipe) (25.0)\n", "Requirement already satisfied: pillow>=8 in .\\.venv\\lib\\site-packages (from matplotlib->mediapipe) (11.3.0)\n", "Requirement already satisfied: pyparsing>=2.3.1 in .\\.venv\\lib\\site-packages (from matplotlib->mediapipe) (3.2.3)\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "%pip install mediapipe opencv-python pandas scikit-learn" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import mediapipe as mp # Import mediapipe\n", "import cv2 # Import opencv\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "mp_drawing = mp.solutions.drawing_utils # Drawing helpers\n", "mp_holistic = mp.solutions.holistic # Mediapipe Solutions\n", "mp_face_mesh = mp.solutions.face_mesh\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 1. Make Some Detections" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "ename": "KeyboardInterrupt", "evalue": "", "output_type": "error", "traceback": [ "\u001b[31m---------------------------------------------------------------------------\u001b[39m", "\u001b[31mKeyboardInterrupt\u001b[39m Traceback (most recent call last)", "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[4]\u001b[39m\u001b[32m, line 13\u001b[39m\n\u001b[32m 10\u001b[39m image.flags.writeable = \u001b[38;5;28;01mFalse\u001b[39;00m \n\u001b[32m 12\u001b[39m \u001b[38;5;66;03m# Make Detections\u001b[39;00m\n\u001b[32m---> \u001b[39m\u001b[32m13\u001b[39m results = \u001b[43mholistic\u001b[49m\u001b[43m.\u001b[49m\u001b[43mprocess\u001b[49m\u001b[43m(\u001b[49m\u001b[43mimage\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 14\u001b[39m \u001b[38;5;66;03m#print(results.face_landmarks)\u001b[39;00m\n\u001b[32m 15\u001b[39m \n\u001b[32m 16\u001b[39m \u001b[38;5;66;03m#face_landmarks, pose_landmarks, left_hand_landmarks, right_hand_landmarks\u001b[39;00m\n\u001b[32m 17\u001b[39m \n\u001b[32m 18\u001b[39m \u001b[38;5;66;03m# Recolor image back to BGR for rendering\u001b[39;00m\n\u001b[32m 19\u001b[39m image.flags.writeable = \u001b[38;5;28;01mTrue\u001b[39;00m \n", "\u001b[36mFile \u001b[39m\u001b[32mc:\\human_action_recognizer\\human_action_recognizer\\.venv\\Lib\\site-packages\\mediapipe\\python\\solutions\\holistic.py:160\u001b[39m, in \u001b[36mHolistic.process\u001b[39m\u001b[34m(self, image)\u001b[39m\n\u001b[32m 136\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mprocess\u001b[39m(\u001b[38;5;28mself\u001b[39m, image: np.ndarray) -> NamedTuple:\n\u001b[32m 137\u001b[39m \u001b[38;5;250m \u001b[39m\u001b[33;03m\"\"\"Processes an RGB image and returns the pose landmarks, left and right hand landmarks, and face landmarks on the most prominent person detected.\u001b[39;00m\n\u001b[32m 138\u001b[39m \n\u001b[32m 139\u001b[39m \u001b[33;03m Args:\u001b[39;00m\n\u001b[32m (...)\u001b[39m\u001b[32m 157\u001b[39m \u001b[33;03m \"enable_segmentation\" is set to true.\u001b[39;00m\n\u001b[32m 158\u001b[39m \u001b[33;03m \"\"\"\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m160\u001b[39m results = \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m.\u001b[49m\u001b[43mprocess\u001b[49m\u001b[43m(\u001b[49m\u001b[43minput_data\u001b[49m\u001b[43m=\u001b[49m\u001b[43m{\u001b[49m\u001b[33;43m'\u001b[39;49m\u001b[33;43mimage\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mimage\u001b[49m\u001b[43m}\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 161\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m results.pose_landmarks: \u001b[38;5;66;03m# pytype: disable=attribute-error\u001b[39;00m\n\u001b[32m 162\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m landmark \u001b[38;5;129;01min\u001b[39;00m results.pose_landmarks.landmark: \u001b[38;5;66;03m# pytype: disable=attribute-error\u001b[39;00m\n", "\u001b[36mFile \u001b[39m\u001b[32mc:\\human_action_recognizer\\human_action_recognizer\\.venv\\Lib\\site-packages\\mediapipe\\python\\solution_base.py:340\u001b[39m, in \u001b[36mSolutionBase.process\u001b[39m\u001b[34m(self, input_data)\u001b[39m\n\u001b[32m 334\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m 335\u001b[39m \u001b[38;5;28mself\u001b[39m._graph.add_packet_to_input_stream(\n\u001b[32m 336\u001b[39m stream=stream_name,\n\u001b[32m 337\u001b[39m packet=\u001b[38;5;28mself\u001b[39m._make_packet(input_stream_type,\n\u001b[32m 338\u001b[39m data).at(\u001b[38;5;28mself\u001b[39m._simulated_timestamp))\n\u001b[32m--> \u001b[39m\u001b[32m340\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_graph\u001b[49m\u001b[43m.\u001b[49m\u001b[43mwait_until_idle\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 341\u001b[39m \u001b[38;5;66;03m# Create a NamedTuple object where the field names are mapping to the graph\u001b[39;00m\n\u001b[32m 342\u001b[39m \u001b[38;5;66;03m# output stream names.\u001b[39;00m\n\u001b[32m 343\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m._output_stream_type_info \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n", "\u001b[31mKeyboardInterrupt\u001b[39m: " ] } ], "source": [ "cap = cv2.VideoCapture(0)\n", "# Initiate holistic model\n", "with mp_holistic.Holistic(min_detection_confidence=0.5, min_tracking_confidence=0.5) as holistic:\n", " \n", " while cap.isOpened():\n", " ret, frame = cap.read()\n", " \n", " # Recolor Feed\n", " image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)\n", " image.flags.writeable = False \n", " \n", " # Make Detections\n", " results = holistic.process(image)\n", " #print(results.face_landmarks)\n", " \n", " #face_landmarks, pose_landmarks, left_hand_landmarks, right_hand_landmarks\n", " \n", " # Recolor image back to BGR for rendering\n", " image.flags.writeable = True \n", " image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)\n", " \n", " \n", " # 1. Right hand\n", " mp_drawing.draw_landmarks(image, results.right_hand_landmarks, mp_holistic.HAND_CONNECTIONS, \n", " mp_drawing.DrawingSpec(color=(80,22,10), thickness=2, circle_radius=4),\n", " mp_drawing.DrawingSpec(color=(80,44,121), thickness=2, circle_radius=2)\n", " )\n", "\n", " # 2 Left Hand\n", " mp_drawing.draw_landmarks(image, results.left_hand_landmarks, mp_holistic.HAND_CONNECTIONS, \n", " mp_drawing.DrawingSpec(color=(121,22,76), thickness=2, circle_radius=4),\n", " mp_drawing.DrawingSpec(color=(121,44,250), thickness=2, circle_radius=2)\n", " )\n", "\n", " # 3. Pose Detections\n", " mp_drawing.draw_landmarks(image, results.pose_landmarks, mp_holistic.POSE_CONNECTIONS, \n", " mp_drawing.DrawingSpec(color=(245,117,66), thickness=2, circle_radius=4),\n", " mp_drawing.DrawingSpec(color=(245,66,230), thickness=2, circle_radius=2)\n", " )\n", " # Export coordinates\n", " try:\n", " # Extract Pose landmarks\n", " pose = results.pose_landmarks.landmark\n", " pose_row = list(np.array([[landmark.x, landmark.y, landmark.z, landmark.visibility] for landmark in pose]).flatten())\n", " \n", " # Extract Face landmarks\n", " face = results.face_landmarks.landmark\n", " face_row = list(np.array([[landmark.x, landmark.y, landmark.z, landmark.visibility] for landmark in face]).flatten())\n", " \n", " # Concate rows\n", " row = pose_row+face_row\n", " \n", " # Append class name \n", " row.insert(0, class_name)\n", " \n", " # Export to CSV\n", " with open('coords.csv', mode='a', newline='') as f:\n", " csv_writer = csv.writer(f, delimiter=',', quotechar='\"', quoting=csv.QUOTE_MINIMAL)\n", " csv_writer.writerow(row) \n", " \n", " except:\n", " pass\n", " \n", " cv2.imshow('Raw Webcam Feed', image)\n", "\n", " if cv2.waitKey(10) & 0xFF == ord('q'):\n", " break\n", "\n", "cap.release()\n", "cv2.destroyAllWindows()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "ename": "KeyboardInterrupt", "evalue": "", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", "Cell \u001b[1;32mIn[4], line 44\u001b[0m\n\u001b[0;32m 37\u001b[0m mp_drawing\u001b[38;5;241m.\u001b[39mdraw_landmarks(image, results\u001b[38;5;241m.\u001b[39mpose_landmarks, mp_holistic\u001b[38;5;241m.\u001b[39mPOSE_CONNECTIONS, \n\u001b[0;32m 38\u001b[0m mp_drawing\u001b[38;5;241m.\u001b[39mDrawingSpec(color\u001b[38;5;241m=\u001b[39m(\u001b[38;5;241m245\u001b[39m,\u001b[38;5;241m117\u001b[39m,\u001b[38;5;241m66\u001b[39m), thickness\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m2\u001b[39m, circle_radius\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m4\u001b[39m),\n\u001b[0;32m 39\u001b[0m mp_drawing\u001b[38;5;241m.\u001b[39mDrawingSpec(color\u001b[38;5;241m=\u001b[39m(\u001b[38;5;241m245\u001b[39m,\u001b[38;5;241m66\u001b[39m,\u001b[38;5;241m230\u001b[39m), thickness\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m2\u001b[39m, circle_radius\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m2\u001b[39m)\n\u001b[0;32m 40\u001b[0m )\n\u001b[0;32m 42\u001b[0m cv2\u001b[38;5;241m.\u001b[39mimshow(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mRaw Webcam Feed\u001b[39m\u001b[38;5;124m'\u001b[39m, image)\n\u001b[1;32m---> 44\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[43mcv2\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mwaitKey\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m10\u001b[39;49m\u001b[43m)\u001b[49m \u001b[38;5;241m&\u001b[39m \u001b[38;5;241m0xFF\u001b[39m \u001b[38;5;241m==\u001b[39m \u001b[38;5;28mord\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mq\u001b[39m\u001b[38;5;124m'\u001b[39m):\n\u001b[0;32m 45\u001b[0m \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[0;32m 47\u001b[0m cap\u001b[38;5;241m.\u001b[39mrelease()\n", "\u001b[1;31mKeyboardInterrupt\u001b[0m: " ] } ], "source": [ "cap = cv2.VideoCapture(0)\n", "# Initiate holistic model\n", "with mp_holistic.Holistic(min_detection_confidence=0.5, min_tracking_confidence=0.5) as holistic:\n", " \n", " while cap.isOpened():\n", " ret, frame = cap.read()\n", " \n", " # Recolor Feed\n", " image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)\n", " image.flags.writeable = True \n", " \n", " # Make Detections\n", " results = holistic.process(image)\n", " # print(results.face_landmarks)\n", " \n", " # face_landmarks, pose_landmarks, left_hand_landmarks, right_hand_landmarks\n", " \n", " # Recolor image back to BGR for rendering\n", " image.flags.writeable = True \n", " image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)\n", " \n", " \n", " \n", " # 1. Right hand\n", " mp_drawing.draw_landmarks(image, results.right_hand_landmarks, mp_holistic.HAND_CONNECTIONS, \n", " mp_drawing.DrawingSpec(color=(80,22,10), thickness=2, circle_radius=4),\n", " mp_drawing.DrawingSpec(color=(80,44,121), thickness=2, circle_radius=2)\n", " )\n", "\n", " # 2. Left Hand\n", " mp_drawing.draw_landmarks(image, results.left_hand_landmarks, mp_holistic.HAND_CONNECTIONS, \n", " mp_drawing.DrawingSpec(color=(121,22,76), thickness=2, circle_radius=4),\n", " mp_drawing.DrawingSpec(color=(121,44,250), thickness=2, circle_radius=2)\n", " )\n", "\n", " # 3. Pose Detections\n", " mp_drawing.draw_landmarks(image, results.pose_landmarks, mp_holistic.POSE_CONNECTIONS, \n", " mp_drawing.DrawingSpec(color=(245,117,66), thickness=2, circle_radius=4),\n", " mp_drawing.DrawingSpec(color=(245,66,230), thickness=2, circle_radius=2)\n", " )\n", " \n", " cv2.imshow('Raw Webcam Feed', image)\n", "\n", " if cv2.waitKey(10) & 0xFF == ord('q'):\n", " break\n", "\n", "cap.release()\n", "cv2.destroyAllWindows()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "results.face_landmarks.landmark[0].visibility" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 2. Capture Landmarks & Export to CSV\n", "\n", "" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: numpy in c:\\users\\deepa\\downloads\\body-language-decoder-main\\myenv\\lib\\site-packages (1.26.4)\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "%pip install numpy\n" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "import csv\n", "import os\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "501" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "num_coords = len(results.pose_landmarks.landmark)+len(results.face_landmarks.landmark)\n", "num_coords" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "landmarks = ['class']\n", "for val in range(1, num_coords+1):\n", " landmarks += ['x{}'.format(val), 'y{}'.format(val), 'z{}'.format(val), 'v{}'.format(val)]" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['class',\n", " 'x1',\n", " 'y1',\n", " 'z1',\n", " 'v1',\n", " 'x2',\n", " 'y2',\n", " 'z2',\n", " 'v2',\n", " 'x3',\n", " 'y3',\n", " 'z3',\n", " 'v3',\n", " 'x4',\n", " 'y4',\n", " 'z4',\n", " 'v4',\n", " 'x5',\n", " 'y5',\n", " 'z5',\n", " 'v5',\n", " 'x6',\n", " 'y6',\n", " 'z6',\n", " 'v6',\n", " 'x7',\n", " 'y7',\n", " 'z7',\n", " 'v7',\n", " 'x8',\n", " 'y8',\n", " 'z8',\n", " 'v8',\n", " 'x9',\n", " 'y9',\n", " 'z9',\n", " 'v9',\n", " 'x10',\n", " 'y10',\n", " 'z10',\n", " 'v10',\n", " 'x11',\n", " 'y11',\n", " 'z11',\n", " 'v11',\n", " 'x12',\n", " 'y12',\n", " 'z12',\n", " 'v12',\n", " 'x13',\n", " 'y13',\n", " 'z13',\n", " 'v13',\n", " 'x14',\n", " 'y14',\n", " 'z14',\n", " 'v14',\n", " 'x15',\n", " 'y15',\n", " 'z15',\n", " 'v15',\n", " 'x16',\n", " 'y16',\n", " 'z16',\n", " 'v16',\n", " 'x17',\n", " 'y17',\n", " 'z17',\n", " 'v17',\n", " 'x18',\n", " 'y18',\n", " 'z18',\n", " 'v18',\n", " 'x19',\n", " 'y19',\n", " 'z19',\n", " 'v19',\n", " 'x20',\n", " 'y20',\n", " 'z20',\n", " 'v20',\n", " 'x21',\n", " 'y21',\n", " 'z21',\n", " 'v21',\n", " 'x22',\n", " 'y22',\n", " 'z22',\n", " 'v22',\n", " 'x23',\n", " 'y23',\n", " 'z23',\n", " 'v23',\n", " 'x24',\n", " 'y24',\n", " 'z24',\n", " 'v24',\n", " 'x25',\n", " 'y25',\n", " 'z25',\n", " 'v25',\n", " 'x26',\n", " 'y26',\n", " 'z26',\n", " 'v26',\n", " 'x27',\n", " 'y27',\n", " 'z27',\n", " 'v27',\n", " 'x28',\n", " 'y28',\n", " 'z28',\n", " 'v28',\n", " 'x29',\n", " 'y29',\n", " 'z29',\n", " 'v29',\n", " 'x30',\n", " 'y30',\n", " 'z30',\n", " 'v30',\n", " 'x31',\n", " 'y31',\n", " 'z31',\n", " 'v31',\n", " 'x32',\n", " 'y32',\n", " 'z32',\n", " 'v32',\n", " 'x33',\n", " 'y33',\n", " 'z33',\n", " 'v33',\n", " 'x34',\n", " 'y34',\n", " 'z34',\n", " 'v34',\n", " 'x35',\n", " 'y35',\n", " 'z35',\n", " 'v35',\n", " 'x36',\n", " 'y36',\n", " 'z36',\n", " 'v36',\n", " 'x37',\n", " 'y37',\n", " 'z37',\n", " 'v37',\n", " 'x38',\n", " 'y38',\n", " 'z38',\n", " 'v38',\n", " 'x39',\n", " 'y39',\n", " 'z39',\n", " 'v39',\n", " 'x40',\n", " 'y40',\n", " 'z40',\n", " 'v40',\n", " 'x41',\n", " 'y41',\n", " 'z41',\n", " 'v41',\n", " 'x42',\n", " 'y42',\n", " 'z42',\n", " 'v42',\n", " 'x43',\n", " 'y43',\n", " 'z43',\n", " 'v43',\n", " 'x44',\n", " 'y44',\n", " 'z44',\n", " 'v44',\n", " 'x45',\n", " 'y45',\n", " 'z45',\n", " 'v45',\n", " 'x46',\n", " 'y46',\n", " 'z46',\n", " 'v46',\n", " 'x47',\n", " 'y47',\n", " 'z47',\n", " 'v47',\n", " 'x48',\n", " 'y48',\n", " 'z48',\n", " 'v48',\n", " 'x49',\n", " 'y49',\n", " 'z49',\n", " 'v49',\n", " 'x50',\n", " 'y50',\n", " 'z50',\n", " 'v50',\n", " 'x51',\n", " 'y51',\n", " 'z51',\n", " 'v51',\n", " 'x52',\n", " 'y52',\n", " 'z52',\n", " 'v52',\n", " 'x53',\n", " 'y53',\n", " 'z53',\n", " 'v53',\n", " 'x54',\n", " 'y54',\n", " 'z54',\n", " 'v54',\n", " 'x55',\n", " 'y55',\n", " 'z55',\n", " 'v55',\n", " 'x56',\n", " 'y56',\n", " 'z56',\n", " 'v56',\n", " 'x57',\n", " 'y57',\n", " 'z57',\n", " 'v57',\n", " 'x58',\n", " 'y58',\n", " 'z58',\n", " 'v58',\n", " 'x59',\n", " 'y59',\n", " 'z59',\n", " 'v59',\n", " 'x60',\n", " 'y60',\n", " 'z60',\n", " 'v60',\n", " 'x61',\n", " 'y61',\n", " 'z61',\n", " 'v61',\n", " 'x62',\n", " 'y62',\n", " 'z62',\n", " 'v62',\n", " 'x63',\n", " 'y63',\n", " 'z63',\n", " 'v63',\n", " 'x64',\n", " 'y64',\n", " 'z64',\n", " 'v64',\n", " 'x65',\n", " 'y65',\n", " 'z65',\n", " 'v65',\n", " 'x66',\n", " 'y66',\n", " 'z66',\n", " 'v66',\n", " 'x67',\n", " 'y67',\n", " 'z67',\n", " 'v67',\n", " 'x68',\n", " 'y68',\n", " 'z68',\n", " 'v68',\n", " 'x69',\n", " 'y69',\n", " 'z69',\n", " 'v69',\n", " 'x70',\n", " 'y70',\n", " 'z70',\n", " 'v70',\n", " 'x71',\n", " 'y71',\n", " 'z71',\n", " 'v71',\n", " 'x72',\n", " 'y72',\n", " 'z72',\n", " 'v72',\n", " 'x73',\n", " 'y73',\n", " 'z73',\n", " 'v73',\n", " 'x74',\n", " 'y74',\n", " 'z74',\n", " 'v74',\n", " 'x75',\n", " 'y75',\n", " 'z75',\n", " 'v75',\n", " 'x76',\n", " 'y76',\n", " 'z76',\n", " 'v76',\n", " 'x77',\n", " 'y77',\n", " 'z77',\n", " 'v77',\n", " 'x78',\n", " 'y78',\n", " 'z78',\n", " 'v78',\n", " 'x79',\n", " 'y79',\n", " 'z79',\n", " 'v79',\n", " 'x80',\n", " 'y80',\n", " 'z80',\n", " 'v80',\n", " 'x81',\n", " 'y81',\n", " 'z81',\n", " 'v81',\n", " 'x82',\n", " 'y82',\n", " 'z82',\n", " 'v82',\n", " 'x83',\n", " 'y83',\n", " 'z83',\n", " 'v83',\n", " 'x84',\n", " 'y84',\n", " 'z84',\n", " 'v84',\n", " 'x85',\n", " 'y85',\n", " 'z85',\n", " 'v85',\n", " 'x86',\n", " 'y86',\n", " 'z86',\n", " 'v86',\n", " 'x87',\n", " 'y87',\n", " 'z87',\n", " 'v87',\n", " 'x88',\n", " 'y88',\n", " 'z88',\n", " 'v88',\n", " 'x89',\n", " 'y89',\n", " 'z89',\n", " 'v89',\n", " 'x90',\n", " 'y90',\n", " 'z90',\n", " 'v90',\n", " 'x91',\n", " 'y91',\n", " 'z91',\n", " 'v91',\n", " 'x92',\n", " 'y92',\n", " 'z92',\n", " 'v92',\n", " 'x93',\n", " 'y93',\n", " 'z93',\n", " 'v93',\n", " 'x94',\n", " 'y94',\n", " 'z94',\n", " 'v94',\n", " 'x95',\n", " 'y95',\n", " 'z95',\n", " 'v95',\n", " 'x96',\n", " 'y96',\n", " 'z96',\n", " 'v96',\n", " 'x97',\n", " 'y97',\n", " 'z97',\n", " 'v97',\n", " 'x98',\n", " 'y98',\n", " 'z98',\n", " 'v98',\n", " 'x99',\n", " 'y99',\n", " 'z99',\n", " 'v99',\n", " 'x100',\n", " 'y100',\n", " 'z100',\n", " 'v100',\n", " 'x101',\n", " 'y101',\n", " 'z101',\n", " 'v101',\n", " 'x102',\n", " 'y102',\n", " 'z102',\n", " 'v102',\n", " 'x103',\n", " 'y103',\n", " 'z103',\n", " 'v103',\n", " 'x104',\n", " 'y104',\n", " 'z104',\n", " 'v104',\n", " 'x105',\n", " 'y105',\n", " 'z105',\n", " 'v105',\n", " 'x106',\n", " 'y106',\n", " 'z106',\n", " 'v106',\n", " 'x107',\n", " 'y107',\n", " 'z107',\n", " 'v107',\n", " 'x108',\n", " 'y108',\n", " 'z108',\n", " 'v108',\n", " 'x109',\n", " 'y109',\n", " 'z109',\n", " 'v109',\n", " 'x110',\n", " 'y110',\n", " 'z110',\n", " 'v110',\n", " 'x111',\n", " 'y111',\n", " 'z111',\n", " 'v111',\n", " 'x112',\n", " 'y112',\n", " 'z112',\n", " 'v112',\n", " 'x113',\n", " 'y113',\n", " 'z113',\n", " 'v113',\n", " 'x114',\n", " 'y114',\n", " 'z114',\n", " 'v114',\n", " 'x115',\n", " 'y115',\n", " 'z115',\n", " 'v115',\n", " 'x116',\n", " 'y116',\n", " 'z116',\n", " 'v116',\n", " 'x117',\n", " 'y117',\n", " 'z117',\n", " 'v117',\n", " 'x118',\n", " 'y118',\n", " 'z118',\n", " 'v118',\n", " 'x119',\n", " 'y119',\n", " 'z119',\n", " 'v119',\n", " 'x120',\n", " 'y120',\n", " 'z120',\n", " 'v120',\n", " 'x121',\n", " 'y121',\n", " 'z121',\n", " 'v121',\n", " 'x122',\n", " 'y122',\n", " 'z122',\n", " 'v122',\n", " 'x123',\n", " 'y123',\n", " 'z123',\n", " 'v123',\n", " 'x124',\n", " 'y124',\n", " 'z124',\n", " 'v124',\n", " 'x125',\n", " 'y125',\n", " 'z125',\n", " 'v125',\n", " 'x126',\n", " 'y126',\n", " 'z126',\n", " 'v126',\n", " 'x127',\n", " 'y127',\n", " 'z127',\n", " 'v127',\n", " 'x128',\n", " 'y128',\n", " 'z128',\n", " 'v128',\n", " 'x129',\n", " 'y129',\n", " 'z129',\n", " 'v129',\n", " 'x130',\n", " 'y130',\n", " 'z130',\n", " 'v130',\n", " 'x131',\n", " 'y131',\n", " 'z131',\n", " 'v131',\n", " 'x132',\n", " 'y132',\n", " 'z132',\n", " 'v132',\n", " 'x133',\n", " 'y133',\n", " 'z133',\n", " 'v133',\n", " 'x134',\n", " 'y134',\n", " 'z134',\n", " 'v134',\n", " 'x135',\n", " 'y135',\n", " 'z135',\n", " 'v135',\n", " 'x136',\n", " 'y136',\n", " 'z136',\n", " 'v136',\n", " 'x137',\n", " 'y137',\n", " 'z137',\n", " 'v137',\n", " 'x138',\n", " 'y138',\n", " 'z138',\n", " 'v138',\n", " 'x139',\n", " 'y139',\n", " 'z139',\n", " 'v139',\n", " 'x140',\n", " 'y140',\n", " 'z140',\n", " 'v140',\n", " 'x141',\n", " 'y141',\n", " 'z141',\n", " 'v141',\n", " 'x142',\n", " 'y142',\n", " 'z142',\n", " 'v142',\n", " 'x143',\n", " 'y143',\n", " 'z143',\n", " 'v143',\n", " 'x144',\n", " 'y144',\n", " 'z144',\n", " 'v144',\n", " 'x145',\n", " 'y145',\n", " 'z145',\n", " 'v145',\n", " 'x146',\n", " 'y146',\n", " 'z146',\n", " 'v146',\n", " 'x147',\n", " 'y147',\n", " 'z147',\n", " 'v147',\n", " 'x148',\n", " 'y148',\n", " 'z148',\n", " 'v148',\n", " 'x149',\n", " 'y149',\n", " 'z149',\n", " 'v149',\n", " 'x150',\n", " 'y150',\n", " 'z150',\n", " 'v150',\n", " 'x151',\n", " 'y151',\n", " 'z151',\n", " 'v151',\n", " 'x152',\n", " 'y152',\n", " 'z152',\n", " 'v152',\n", " 'x153',\n", " 'y153',\n", " 'z153',\n", " 'v153',\n", " 'x154',\n", " 'y154',\n", " 'z154',\n", " 'v154',\n", " 'x155',\n", " 'y155',\n", " 'z155',\n", " 'v155',\n", " 'x156',\n", " 'y156',\n", " 'z156',\n", " 'v156',\n", " 'x157',\n", " 'y157',\n", " 'z157',\n", " 'v157',\n", " 'x158',\n", " 'y158',\n", " 'z158',\n", " 'v158',\n", " 'x159',\n", " 'y159',\n", " 'z159',\n", " 'v159',\n", " 'x160',\n", " 'y160',\n", " 'z160',\n", " 'v160',\n", " 'x161',\n", " 'y161',\n", " 'z161',\n", " 'v161',\n", " 'x162',\n", " 'y162',\n", " 'z162',\n", " 'v162',\n", " 'x163',\n", " 'y163',\n", " 'z163',\n", " 'v163',\n", " 'x164',\n", " 'y164',\n", " 'z164',\n", " 'v164',\n", " 'x165',\n", " 'y165',\n", " 'z165',\n", " 'v165',\n", " 'x166',\n", " 'y166',\n", " 'z166',\n", " 'v166',\n", " 'x167',\n", " 'y167',\n", " 'z167',\n", " 'v167',\n", " 'x168',\n", " 'y168',\n", " 'z168',\n", " 'v168',\n", " 'x169',\n", " 'y169',\n", " 'z169',\n", " 'v169',\n", " 'x170',\n", " 'y170',\n", " 'z170',\n", " 'v170',\n", " 'x171',\n", " 'y171',\n", " 'z171',\n", " 'v171',\n", " 'x172',\n", " 'y172',\n", " 'z172',\n", " 'v172',\n", " 'x173',\n", " 'y173',\n", " 'z173',\n", " 'v173',\n", " 'x174',\n", " 'y174',\n", " 'z174',\n", " 'v174',\n", " 'x175',\n", " 'y175',\n", " 'z175',\n", " 'v175',\n", " 'x176',\n", " 'y176',\n", " 'z176',\n", " 'v176',\n", " 'x177',\n", " 'y177',\n", " 'z177',\n", " 'v177',\n", " 'x178',\n", " 'y178',\n", " 'z178',\n", " 'v178',\n", " 'x179',\n", " 'y179',\n", " 'z179',\n", " 'v179',\n", " 'x180',\n", " 'y180',\n", " 'z180',\n", " 'v180',\n", " 'x181',\n", " 'y181',\n", " 'z181',\n", " 'v181',\n", " 'x182',\n", " 'y182',\n", " 'z182',\n", " 'v182',\n", " 'x183',\n", " 'y183',\n", " 'z183',\n", " 'v183',\n", " 'x184',\n", " 'y184',\n", " 'z184',\n", " 'v184',\n", " 'x185',\n", " 'y185',\n", " 'z185',\n", " 'v185',\n", " 'x186',\n", " 'y186',\n", " 'z186',\n", " 'v186',\n", " 'x187',\n", " 'y187',\n", " 'z187',\n", " 'v187',\n", " 'x188',\n", " 'y188',\n", " 'z188',\n", " 'v188',\n", " 'x189',\n", " 'y189',\n", " 'z189',\n", " 'v189',\n", " 'x190',\n", " 'y190',\n", " 'z190',\n", " 'v190',\n", " 'x191',\n", " 'y191',\n", " 'z191',\n", " 'v191',\n", " 'x192',\n", " 'y192',\n", " 'z192',\n", " 'v192',\n", " 'x193',\n", " 'y193',\n", " 'z193',\n", " 'v193',\n", " 'x194',\n", " 'y194',\n", " 'z194',\n", " 'v194',\n", " 'x195',\n", " 'y195',\n", " 'z195',\n", " 'v195',\n", " 'x196',\n", " 'y196',\n", " 'z196',\n", " 'v196',\n", " 'x197',\n", " 'y197',\n", " 'z197',\n", " 'v197',\n", " 'x198',\n", " 'y198',\n", " 'z198',\n", " 'v198',\n", " 'x199',\n", " 'y199',\n", " 'z199',\n", " 'v199',\n", " 'x200',\n", " 'y200',\n", " 'z200',\n", " 'v200',\n", " 'x201',\n", " 'y201',\n", " 'z201',\n", " 'v201',\n", " 'x202',\n", " 'y202',\n", " 'z202',\n", " 'v202',\n", " 'x203',\n", " 'y203',\n", " 'z203',\n", " 'v203',\n", " 'x204',\n", " 'y204',\n", " 'z204',\n", " 'v204',\n", " 'x205',\n", " 'y205',\n", " 'z205',\n", " 'v205',\n", " 'x206',\n", " 'y206',\n", " 'z206',\n", " 'v206',\n", " 'x207',\n", " 'y207',\n", " 'z207',\n", " 'v207',\n", " 'x208',\n", " 'y208',\n", " 'z208',\n", " 'v208',\n", " 'x209',\n", " 'y209',\n", " 'z209',\n", " 'v209',\n", " 'x210',\n", " 'y210',\n", " 'z210',\n", " 'v210',\n", " 'x211',\n", " 'y211',\n", " 'z211',\n", " 'v211',\n", " 'x212',\n", " 'y212',\n", " 'z212',\n", " 'v212',\n", " 'x213',\n", " 'y213',\n", " 'z213',\n", " 'v213',\n", " 'x214',\n", " 'y214',\n", " 'z214',\n", " 'v214',\n", " 'x215',\n", " 'y215',\n", " 'z215',\n", " 'v215',\n", " 'x216',\n", " 'y216',\n", " 'z216',\n", " 'v216',\n", " 'x217',\n", " 'y217',\n", " 'z217',\n", " 'v217',\n", " 'x218',\n", " 'y218',\n", " 'z218',\n", " 'v218',\n", " 'x219',\n", " 'y219',\n", " 'z219',\n", " 'v219',\n", " 'x220',\n", " 'y220',\n", " 'z220',\n", " 'v220',\n", " 'x221',\n", " 'y221',\n", " 'z221',\n", " 'v221',\n", " 'x222',\n", " 'y222',\n", " 'z222',\n", " 'v222',\n", " 'x223',\n", " 'y223',\n", " 'z223',\n", " 'v223',\n", " 'x224',\n", " 'y224',\n", " 'z224',\n", " 'v224',\n", " 'x225',\n", " 'y225',\n", " 'z225',\n", " 'v225',\n", " 'x226',\n", " 'y226',\n", " 'z226',\n", " 'v226',\n", " 'x227',\n", " 'y227',\n", " 'z227',\n", " 'v227',\n", " 'x228',\n", " 'y228',\n", " 'z228',\n", " 'v228',\n", " 'x229',\n", " 'y229',\n", " 'z229',\n", " 'v229',\n", " 'x230',\n", " 'y230',\n", " 'z230',\n", " 'v230',\n", " 'x231',\n", " 'y231',\n", " 'z231',\n", " 'v231',\n", " 'x232',\n", " 'y232',\n", " 'z232',\n", " 'v232',\n", " 'x233',\n", " 'y233',\n", " 'z233',\n", " 'v233',\n", " 'x234',\n", " 'y234',\n", " 'z234',\n", " 'v234',\n", " 'x235',\n", " 'y235',\n", " 'z235',\n", " 'v235',\n", " 'x236',\n", " 'y236',\n", " 'z236',\n", " 'v236',\n", " 'x237',\n", " 'y237',\n", " 'z237',\n", " 'v237',\n", " 'x238',\n", " 'y238',\n", " 'z238',\n", " 'v238',\n", " 'x239',\n", " 'y239',\n", " 'z239',\n", " 'v239',\n", " 'x240',\n", " 'y240',\n", " 'z240',\n", " 'v240',\n", " 'x241',\n", " 'y241',\n", " 'z241',\n", " 'v241',\n", " 'x242',\n", " 'y242',\n", " 'z242',\n", " 'v242',\n", " 'x243',\n", " 'y243',\n", " 'z243',\n", " 'v243',\n", " 'x244',\n", " 'y244',\n", " 'z244',\n", " 'v244',\n", " 'x245',\n", " 'y245',\n", " 'z245',\n", " 'v245',\n", " 'x246',\n", " 'y246',\n", " 'z246',\n", " 'v246',\n", " 'x247',\n", " 'y247',\n", " 'z247',\n", " 'v247',\n", " 'x248',\n", " 'y248',\n", " 'z248',\n", " 'v248',\n", " 'x249',\n", " 'y249',\n", " 'z249',\n", " 'v249',\n", " 'x250',\n", " 'y250',\n", " 'z250',\n", " ...]" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "landmarks" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [], "source": [ "with open('coords.csv', mode='w', newline='') as f:\n", " csv_writer = csv.writer(f, delimiter=',', quotechar='\"', quoting=csv.QUOTE_MINIMAL)\n", " csv_writer.writerow(landmarks)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "class_name = \"THINKING\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%pip install --upgrade pip setuptools wheel\n" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "ename": "KeyboardInterrupt", "evalue": "", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", "Cell \u001b[1;32mIn[14], line 13\u001b[0m\n\u001b[0;32m 10\u001b[0m image\u001b[38;5;241m.\u001b[39mflags\u001b[38;5;241m.\u001b[39mwriteable \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mFalse\u001b[39;00m \n\u001b[0;32m 12\u001b[0m \u001b[38;5;66;03m# Make Detections\u001b[39;00m\n\u001b[1;32m---> 13\u001b[0m results \u001b[38;5;241m=\u001b[39m \u001b[43mholistic\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mprocess\u001b[49m\u001b[43m(\u001b[49m\u001b[43mimage\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 14\u001b[0m \u001b[38;5;66;03m# print(results.face_landmarks)\u001b[39;00m\n\u001b[0;32m 15\u001b[0m \n\u001b[0;32m 16\u001b[0m \u001b[38;5;66;03m# face_landmarks, pose_landmarks, left_hand_landmarks, right_hand_landmarks\u001b[39;00m\n\u001b[0;32m 17\u001b[0m \n\u001b[0;32m 18\u001b[0m \u001b[38;5;66;03m# Recolor image back to BGR for rendering\u001b[39;00m\n\u001b[0;32m 19\u001b[0m image\u001b[38;5;241m.\u001b[39mflags\u001b[38;5;241m.\u001b[39mwriteable \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m \n", "File \u001b[1;32mc:\\Users\\deepa\\Downloads\\Body-Language-Decoder-main\\myenv\\Lib\\site-packages\\mediapipe\\python\\solutions\\holistic.py:160\u001b[0m, in \u001b[0;36mHolistic.process\u001b[1;34m(self, image)\u001b[0m\n\u001b[0;32m 136\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mprocess\u001b[39m(\u001b[38;5;28mself\u001b[39m, image: np\u001b[38;5;241m.\u001b[39mndarray) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m NamedTuple:\n\u001b[0;32m 137\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Processes an RGB image and returns the pose landmarks, left and right hand landmarks, and face landmarks on the most prominent person detected.\u001b[39;00m\n\u001b[0;32m 138\u001b[0m \n\u001b[0;32m 139\u001b[0m \u001b[38;5;124;03m Args:\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 157\u001b[0m \u001b[38;5;124;03m \"enable_segmentation\" is set to true.\u001b[39;00m\n\u001b[0;32m 158\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m--> 160\u001b[0m results \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mprocess\u001b[49m\u001b[43m(\u001b[49m\u001b[43minput_data\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m{\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mimage\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mimage\u001b[49m\u001b[43m}\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 161\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m results\u001b[38;5;241m.\u001b[39mpose_landmarks: \u001b[38;5;66;03m# pytype: disable=attribute-error\u001b[39;00m\n\u001b[0;32m 162\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m landmark \u001b[38;5;129;01min\u001b[39;00m results\u001b[38;5;241m.\u001b[39mpose_landmarks\u001b[38;5;241m.\u001b[39mlandmark: \u001b[38;5;66;03m# pytype: disable=attribute-error\u001b[39;00m\n", "File \u001b[1;32mc:\\Users\\deepa\\Downloads\\Body-Language-Decoder-main\\myenv\\Lib\\site-packages\\mediapipe\\python\\solution_base.py:340\u001b[0m, in \u001b[0;36mSolutionBase.process\u001b[1;34m(self, input_data)\u001b[0m\n\u001b[0;32m 334\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 335\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_graph\u001b[38;5;241m.\u001b[39madd_packet_to_input_stream(\n\u001b[0;32m 336\u001b[0m stream\u001b[38;5;241m=\u001b[39mstream_name,\n\u001b[0;32m 337\u001b[0m packet\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_make_packet(input_stream_type,\n\u001b[0;32m 338\u001b[0m data)\u001b[38;5;241m.\u001b[39mat(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_simulated_timestamp))\n\u001b[1;32m--> 340\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_graph\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mwait_until_idle\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 341\u001b[0m \u001b[38;5;66;03m# Create a NamedTuple object where the field names are mapping to the graph\u001b[39;00m\n\u001b[0;32m 342\u001b[0m \u001b[38;5;66;03m# output stream names.\u001b[39;00m\n\u001b[0;32m 343\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_output_stream_type_info \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n", "\u001b[1;31mKeyboardInterrupt\u001b[0m: " ] } ], "source": [ "cap = cv2.VideoCapture(0)\n", "# Initiate holistic model\n", "with mp_holistic.Holistic(min_detection_confidence=0.5, min_tracking_confidence=0.5) as holistic:\n", " \n", " while cap.isOpened():\n", " ret, frame = cap.read()\n", " \n", " # Recolor Feed\n", " image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)\n", " image.flags.writeable = False \n", " \n", " # Make Detections\n", " results = holistic.process(image)\n", " # print(results.face_landmarks)\n", " \n", " # face_landmarks, pose_landmarks, left_hand_landmarks, right_hand_landmarks\n", " \n", " # Recolor image back to BGR for rendering\n", " image.flags.writeable = True \n", " image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)\n", " \n", " \n", " # 1. Right hand\n", " mp_drawing.draw_landmarks(image, results.right_hand_landmarks, mp_holistic.HAND_CONNECTIONS, \n", " mp_drawing.DrawingSpec(color=(80,22,10), thickness=2, circle_radius=4),\n", " mp_drawing.DrawingSpec(color=(80,44,121), thickness=2, circle_radius=2)\n", " )\n", "\n", " # 2 Left Hand\n", " mp_drawing.draw_landmarks(image, results.left_hand_landmarks, mp_holistic.HAND_CONNECTIONS, \n", " mp_drawing.DrawingSpec(color=(121,22,76), thickness=2, circle_radius=4),\n", " mp_drawing.DrawingSpec(color=(121,44,250), thickness=2, circle_radius=2)\n", " )\n", "\n", " # 3. Pose Detections\n", " mp_drawing.draw_landmarks(image, results.pose_landmarks, mp_holistic.POSE_CONNECTIONS, \n", " mp_drawing.DrawingSpec(color=(245,117,66), thickness=2, circle_radius=4),\n", " mp_drawing.DrawingSpec(color=(245,66,230), thickness=2, circle_radius=2)\n", " )\n", " # Export coordinates\n", " try:\n", " # Extract Pose landmarks\n", " pose = results.pose_landmarks.landmark\n", " pose_row = list(np.array([[landmark.x, landmark.y, landmark.z, landmark.visibility] for landmark in pose]).flatten())\n", " \n", " # Extract Face landmarks\n", " face = results.face_landmarks.landmark\n", " face_row = list(np.array([[landmark.x, landmark.y, landmark.z, landmark.visibility] for landmark in face]).flatten())\n", " \n", " # Concate rows\n", " row = pose_row+face_row\n", " \n", " # Append class name \n", " row.insert(0, class_name)\n", " \n", " # Export to CSV\n", " with open('coords.csv', mode='a', newline='') as f:\n", " csv_writer = csv.writer(f, delimiter=',', quotechar='\"', quoting=csv.QUOTE_MINIMAL)\n", " csv_writer.writerow(row) \n", " \n", " except:\n", " pass\n", " \n", " cv2.imshow('Raw Webcam Feed', image)\n", "\n", " if cv2.waitKey(10) & 0xFF == ord('q'):\n", " break\n", "\n", "cap.release()\n", "cv2.destroyAllWindows()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 3. Train Custom Model Using Scikit Learn" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3.1 Read in Collected Data and Process" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: pandas in c:\\users\\deepa\\downloads\\body-language-decoder-main\\myenv\\lib\\site-packages (2.2.3)\n", "Requirement already satisfied: numpy>=1.23.2 in c:\\users\\deepa\\downloads\\body-language-decoder-main\\myenv\\lib\\site-packages (from pandas) (1.26.4)\n", "Requirement already satisfied: python-dateutil>=2.8.2 in c:\\users\\deepa\\downloads\\body-language-decoder-main\\myenv\\lib\\site-packages (from pandas) (2.9.0.post0)\n", "Requirement already satisfied: pytz>=2020.1 in c:\\users\\deepa\\downloads\\body-language-decoder-main\\myenv\\lib\\site-packages (from pandas) (2024.2)\n", "Requirement already satisfied: tzdata>=2022.7 in c:\\users\\deepa\\downloads\\body-language-decoder-main\\myenv\\lib\\site-packages (from pandas) (2024.2)\n", "Requirement already satisfied: six>=1.5 in c:\\users\\deepa\\downloads\\body-language-decoder-main\\myenv\\lib\\site-packages (from python-dateutil>=2.8.2->pandas) (1.17.0)\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "%pip install pandas" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: scikit-learn in c:\\users\\deepa\\downloads\\body-language-decoder-main\\myenv\\lib\\site-packages (1.5.2)\n", "Requirement already satisfied: numpy>=1.19.5 in c:\\users\\deepa\\downloads\\body-language-decoder-main\\myenv\\lib\\site-packages (from scikit-learn) (1.26.4)\n", "Requirement already satisfied: scipy>=1.6.0 in c:\\users\\deepa\\downloads\\body-language-decoder-main\\myenv\\lib\\site-packages (from scikit-learn) (1.14.1)\n", "Requirement already satisfied: joblib>=1.2.0 in c:\\users\\deepa\\downloads\\body-language-decoder-main\\myenv\\lib\\site-packages (from scikit-learn) (1.4.2)\n", "Requirement already satisfied: threadpoolctl>=3.1.0 in c:\\users\\deepa\\downloads\\body-language-decoder-main\\myenv\\lib\\site-packages (from scikit-learn) (3.5.0)\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "%pip install scikit-learn" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "\n", "import pandas as pd\n", "from sklearn.model_selection import train_test_split" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "df = pd.read_csv('coords.csv')" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | class | \n", "x1 | \n", "y1 | \n", "z1 | \n", "v1 | \n", "x2 | \n", "y2 | \n", "z2 | \n", "v2 | \n", "x3 | \n", "... | \n", "z499 | \n", "v499 | \n", "x500 | \n", "y500 | \n", "z500 | \n", "v500 | \n", "x501 | \n", "y501 | \n", "z501 | \n", "v501 | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "NORMAL | \n", "0.519949 | \n", "0.536690 | \n", "-1.379617 | \n", "0.999319 | \n", "0.552927 | \n", "0.469329 | \n", "-1.317674 | \n", "0.998447 | \n", "0.572680 | \n", "... | \n", "-0.010598 | \n", "0.0 | \n", "0.592775 | \n", "0.469103 | \n", "0.005446 | \n", "0.0 | \n", "0.598408 | \n", "0.462726 | \n", "0.005611 | \n", "0.0 | \n", "
| 1 | \n", "NORMAL | \n", "0.519344 | \n", "0.538721 | \n", "-1.305471 | \n", "0.999374 | \n", "0.550727 | \n", "0.468455 | \n", "-1.247671 | \n", "0.998578 | \n", "0.571579 | \n", "... | \n", "-0.009568 | \n", "0.0 | \n", "0.587528 | \n", "0.449457 | \n", "0.004852 | \n", "0.0 | \n", "0.593149 | \n", "0.442310 | \n", "0.005043 | \n", "0.0 | \n", "
| 2 | \n", "NORMAL | \n", "0.518772 | \n", "0.541059 | \n", "-1.282752 | \n", "0.999423 | \n", "0.549911 | \n", "0.468389 | \n", "-1.221402 | \n", "0.998701 | \n", "0.571287 | \n", "... | \n", "-0.008896 | \n", "0.0 | \n", "0.587066 | \n", "0.449859 | \n", "0.005509 | \n", "0.0 | \n", "0.592626 | \n", "0.442812 | \n", "0.005717 | \n", "0.0 | \n", "
| 3 | \n", "NORMAL | \n", "0.503458 | \n", "0.481007 | \n", "-1.300024 | \n", "0.999460 | \n", "0.537451 | \n", "0.412866 | \n", "-1.238461 | \n", "0.998778 | \n", "0.559888 | \n", "... | \n", "-0.009015 | \n", "0.0 | \n", "0.565599 | \n", "0.388341 | \n", "0.005163 | \n", "0.0 | \n", "0.571406 | \n", "0.381899 | \n", "0.005210 | \n", "0.0 | \n", "
| 4 | \n", "NORMAL | \n", "0.476874 | \n", "0.458428 | \n", "-1.473020 | \n", "0.999286 | \n", "0.512836 | \n", "0.392423 | \n", "-1.386732 | \n", "0.998602 | \n", "0.537356 | \n", "... | \n", "-0.002948 | \n", "0.0 | \n", "0.550542 | \n", "0.383945 | \n", "0.016083 | \n", "0.0 | \n", "0.557199 | \n", "0.376718 | \n", "0.016706 | \n", "0.0 | \n", "
5 rows × 2005 columns
\n", "| \n", " | class | \n", "x1 | \n", "y1 | \n", "z1 | \n", "v1 | \n", "x2 | \n", "y2 | \n", "z2 | \n", "v2 | \n", "x3 | \n", "... | \n", "z499 | \n", "v499 | \n", "x500 | \n", "y500 | \n", "z500 | \n", "v500 | \n", "x501 | \n", "y501 | \n", "z501 | \n", "v501 | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 879 | \n", "THINKING | \n", "0.558214 | \n", "0.592767 | \n", "-0.726623 | \n", "0.999975 | \n", "0.599663 | \n", "0.547845 | \n", "-0.668754 | \n", "0.999930 | \n", "0.618402 | \n", "... | \n", "-0.007293 | \n", "0.0 | \n", "0.633891 | \n", "0.546936 | \n", "0.003600 | \n", "0.0 | \n", "0.641294 | \n", "0.541917 | \n", "0.003701 | \n", "0.0 | \n", "
| 880 | \n", "THINKING | \n", "0.558373 | \n", "0.593758 | \n", "-0.727085 | \n", "0.999975 | \n", "0.599709 | \n", "0.548577 | \n", "-0.668927 | \n", "0.999928 | \n", "0.618432 | \n", "... | \n", "-0.006939 | \n", "0.0 | \n", "0.634387 | \n", "0.547939 | \n", "0.003726 | \n", "0.0 | \n", "0.641842 | \n", "0.542788 | \n", "0.003798 | \n", "0.0 | \n", "
| 881 | \n", "THINKING | \n", "0.558471 | \n", "0.594725 | \n", "-0.728832 | \n", "0.999975 | \n", "0.599729 | \n", "0.549300 | \n", "-0.671824 | \n", "0.999927 | \n", "0.618442 | \n", "... | \n", "-0.006761 | \n", "0.0 | \n", "0.634546 | \n", "0.548129 | \n", "0.004192 | \n", "0.0 | \n", "0.641936 | \n", "0.543106 | \n", "0.004277 | \n", "0.0 | \n", "
| 882 | \n", "THINKING | \n", "0.558155 | \n", "0.593852 | \n", "-0.747497 | \n", "0.999974 | \n", "0.599593 | \n", "0.548590 | \n", "-0.688479 | \n", "0.999927 | \n", "0.618332 | \n", "... | \n", "-0.006395 | \n", "0.0 | \n", "0.636311 | \n", "0.547712 | \n", "0.004480 | \n", "0.0 | \n", "0.643608 | \n", "0.542625 | \n", "0.004508 | \n", "0.0 | \n", "
| 883 | \n", "THINKING | \n", "0.557955 | \n", "0.593185 | \n", "-0.755457 | \n", "0.999974 | \n", "0.599538 | \n", "0.548135 | \n", "-0.695629 | \n", "0.999927 | \n", "0.618290 | \n", "... | \n", "-0.006667 | \n", "0.0 | \n", "0.636146 | \n", "0.547180 | \n", "0.004218 | \n", "0.0 | \n", "0.643464 | \n", "0.541991 | \n", "0.004261 | \n", "0.0 | \n", "
5 rows × 2005 columns
\n", "| \n", " | class | \n", "x1 | \n", "y1 | \n", "z1 | \n", "v1 | \n", "x2 | \n", "y2 | \n", "z2 | \n", "v2 | \n", "x3 | \n", "... | \n", "z499 | \n", "v499 | \n", "x500 | \n", "y500 | \n", "z500 | \n", "v500 | \n", "x501 | \n", "y501 | \n", "z501 | \n", "v501 | \n", "
|---|
0 rows × 2005 columns
\n", "Pipeline(steps=[('standardscaler', StandardScaler()),\n",
" ('randomforestclassifier', RandomForestClassifier())])In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. Pipeline(steps=[('standardscaler', StandardScaler()),\n",
" ('randomforestclassifier', RandomForestClassifier())])StandardScaler()
RandomForestClassifier()