{"id":28211613,"url":"https://github.com/asadiahmad/gesture-detection","last_synced_at":"2026-04-29T10:02:27.147Z","repository":{"id":292021484,"uuid":"979563723","full_name":"AsadiAhmad/Gesture-Detection","owner":"AsadiAhmad","description":"Real-time Gesture Detection using CUDA-accelerated OpenCV in Python.","archived":false,"fork":false,"pushed_at":"2025-05-17T20:41:58.000Z","size":10529,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-20T07:44:11.639Z","etag":null,"topics":["computer-vision","cuda","gesture-recognition","gpu-acceleration","open-pose","opencv","opencv-cuda","pose-detection","real-time"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AsadiAhmad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-07T17:55:16.000Z","updated_at":"2025-05-21T09:20:44.000Z","dependencies_parsed_at":"2025-06-20T07:50:02.620Z","dependency_job_id":null,"html_url":"https://github.com/AsadiAhmad/Gesture-Detection","commit_stats":null,"previous_names":["asadiahmad/gesture-detection"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AsadiAhmad/Gesture-Detection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AsadiAhmad%2FGesture-Detection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AsadiAhmad%2FGesture-Detection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AsadiAhmad%2FGesture-Detection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AsadiAhmad%2FGesture-Detection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AsadiAhmad","download_url":"https://codeload.github.com/AsadiAhmad/Gesture-Detection/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AsadiAhmad%2FGesture-Detection/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32420356,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T06:29:02.080Z","status":"ssl_error","status_checked_at":"2026-04-29T06:29:00.631Z","response_time":110,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computer-vision","cuda","gesture-recognition","gpu-acceleration","open-pose","opencv","opencv-cuda","pose-detection","real-time"],"created_at":"2025-05-17T18:09:43.595Z","updated_at":"2026-04-29T10:02:27.141Z","avatar_url":"https://github.com/AsadiAhmad.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gesture-Detection\nReal-time Gesture Detection using CUDA-accelerated OpenCV in Python. Leverages GPU for high-performance image processing tasks, ensuring efficient and responsive gesture recognition.\n\n\u003cdiv display=flex align=center\u003e\n  \u003cimg src=\"/Gif/Gesture.gif\" width=\"600px\"/\u003e\n\u003c/div\u003e\n\n## Tech :hammer_and_wrench: Languages and Tools :\n\n\u003cdiv\u003e\n  \u003cimg src=\"https://github.com/devicons/devicon/blob/master/icons/python/python-original.svg\" title=\"Python\" alt=\"Python\" width=\"40\" height=\"40\"/\u003e\u0026nbsp;\n  \u003cimg src=\"https://github.com/devicons/devicon/blob/master/icons/jupyter/jupyter-original.svg\" title=\"Jupyter Notebook\" alt=\"Jupyter Notebook\" width=\"40\" height=\"40\"/\u003e\u0026nbsp;\n  \u003cimg src=\"https://assets.st-note.com/img/1670632589167-x9aAV8lmnH.png\" title=\"Google Colab\" alt=\"Google Colab\" width=\"40\" height=\"40\"/\u003e\u0026nbsp;\n  \u003cimg src=\"https://github.com/AsadiAhmad/AsadiAhmad/blob/main/Logo/Python/math.png\" title=\"Math\" alt=\"Math\" width=\"40\" height=\"40\"/\u003e\u0026nbsp;\n  \u003cimg src=\"https://github.com/devicons/devicon/blob/master/icons/opencv/opencv-original.svg\" title=\"OpenCV\" alt=\"OpenCV\" width=\"40\" height=\"40\"/\u003e\u0026nbsp;\n  \u003cimg src=\"https://github.com/devicons/devicon/blob/master/icons/numpy/numpy-original.svg\" title=\"Numpy\" alt=\"Numpy\" width=\"40\" height=\"40\"/\u003e\u0026nbsp;\n  \u003cimg src=\"https://www.svgrepo.com/show/373541/cuda.svg\" title=\"CUDA\" alt=\"CUDA\" width=\"40\" height=\"40\"/\u003e\u0026nbsp;\n  \u003cimg src=\"https://github.com/devicons/devicon/blob/master/icons/matplotlib/matplotlib-original.svg\"  title=\"MatPlotLib\" alt=\"MatPlotLib\" width=\"40\" height=\"40\"/\u003e\u0026nbsp;\n  \u003cimg src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/1/12/Google_Drive_icon_%282020%29.svg/1200px-Google_Drive_icon_%282020%29.svg.png\"  title=\"Gdown\" alt=\"Gdown\" width=\"40\" height=\"40\"/\u003e\u0026nbsp;\n\u003c/div\u003e\n\n- Python : Popular language for implementing Neural Network\n- Jupyter Notebook : Best tool for running python cell by cell\n- Google Colab : Best Space for running Jupyter Notebook with hosted server\n- Math : Essential Python library for basic mathematical operations and functions\n- OpenCV : Best Library for working with images\n- Numpy : Best Library for working with arrays in python\n- CUDA : used for NVIDIA GPU acceleration and get better frame rate\n- MatPlotLib : Library for showing the charts in python\n- GDown : Download Resources from Google Drive\n\n## 💻 Run the Notebook on Google Colab\n\nYou can easily run this code on google colab by just clicking this badge [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://github.com/AsadiAhmad/Gesture-Detection/blob/main/Code/Gesture_Detection.ipynb)\n\nLive version not have google colab version because the google colab will crash.\n\n## Models\n\nWe have used caffe Open Pose model. we have the code for donwloading the model.\n\n```python\ngdown.download(id=\"1D3ytIZ-ZMMd5MbvVbf2Sn5oZ1L0aQ9IG\", output=\"pose_deploy_linevec_faster_4_stages.prototxt\", quiet=False)\ngdown.download(id=\"1f-fCSTg7qFHRVKGIptyPJsgNwRs4XDsK\", output=\"pose_iter_160000.caffemodel\", quiet=False)\n```\n\n## 📝 Tutorial\n\n### Step 1: Install CUDA toolkit\nThe first steps are haveing a NVIDIA GPU and download and install the CUDA Toolki (I have used the version 11.7.0) [![CUDA](https://img.shields.io/badge/nVIDIA-%2376B900.svg?style=for-the-badge\u0026logo=nVIDIA\u0026logoColor=white)](https://developer.nvidia.com/cuda-toolkit-archive)\n\nCheck CUDA version:\n```sh\nnvcc --version\n```\n\n### Step 2: Install cuDNN\nAfter that you should donwload and install the cuDN (I have used the version 8.6.0 for 11.X CUDA) [![cuDNN](https://img.shields.io/badge/nVIDIA-%2376B900.svg?style=for-the-badge\u0026logo=nVIDIA\u0026logoColor=white)](https://developer.nvidia.com/rdp/cudnn-archive)\n\nAfter these installation make sure you move the dll files from the cuDNN zip file into the CUDA installation path.\n\n### Step 3: Install OpenCV with CMake\nNow you have installed the CUDA and cuDNN now we use the Visual studio and CMake to build our OpenCV with CUDA. you can watch this video [![YouTube](https://img.shields.io/badge/YouTube-%23FF0000.svg?style=for-the-badge\u0026logo=YouTube\u0026logoColor=white)](https://www.youtube.com/watch?v=5NwU1MmmqWo)\n\n### Step 4: Import Libraries\n\nwe need to import these libraries :\n\n`math`, `numpy`, `cv2`, `gdown`, `time`\n\n```python\nimport math\nimport numpy as np\nimport cv2 as cv\nimport gdown\nimport time\n```\n\n### Step 5: Verify CUDA\n\nfor running the code and check the installation we need to verify the cuda with opencv.\n\n```python\nprint(\"CUDA Enabled:\", cv.cuda.getCudaEnabledDeviceCount())\nprint(\"OpenCV Build Info:\")\nprint(cv.getBuildInformation())\n```\n\n### Step 6: Download Resources\n\nWe need to download the Caffe modele.\n\nWe download models from my google drive for protecting the repo in future.\n\n```python\ngdown.download(id=\"1D3ytIZ-ZMMd5MbvVbf2Sn5oZ1L0aQ9IG\", output=\"pose_deploy_linevec_faster_4_stages.prototxt\", quiet=False)\ngdown.download(id=\"1f-fCSTg7qFHRVKGIptyPJsgNwRs4XDsK\", output=\"pose_iter_160000.caffemodel\", quiet=False)\n```\n\n### Step 7: Load Models\n\nWe load the Caffe models for pose detection. also we set the cuda here\n\n```python\nprotoFile = \"pose_deploy_linevec_faster_4_stages.prototxt\"\nweightsFile = \"pose_iter_160000.caffemodel\"\n\nnet = cv.dnn.readNetFromCaffe(protoFile, weightsFile)\nnet.setPreferableBackend(cv.dnn.DNN_BACKEND_CUDA)\nnet.setPreferableTarget(cv.dnn.DNN_TARGET_CUDA)\n```\n\n### Step 8: Set Body Points\n\nin here we define the structure of the body skeleton by connecting the points of the body\n\n```python\nnPoints = 15\nPOSE_PAIRS = [[0,1], [1,2], [2,3], [3,4], [1,5], [5,6], [6,7], [1,14], [14,8], [8,9], [9,10], [14,11], [11,12], [12,13]]\n```\n\n### Step 9: Convert image to blob\n\nThis section works with GPU\n\n```python\ndef convert_image_to_blob(frame):\n    return cv.dnn.blobFromImage(frame, 1.0/255, (256, 256), (0, 0, 0), swapRB=False, crop=False)\n```\n\n### Step 10: Run Inference Async (forward pass)\n\nIn this section we run move forward through the model for pose detection. this section used GPU.\n\n```python\ndef run_inference():\n    if not hasattr(run_inference, '_warmed_up'):\n        net.forward()\n        run_inference._warmed_up = True\n\n    return net.forward()\n```\n\n### Step 11: Extract points\n\nIn this section we extract all body points (15 points here). this section use CPU\n\n```python\ndef extract_keypoints(output, height, width):\n    points = []\n    for i in range(15):\n        probMap = output[0, i, :, :]\n        _, _, _, max_loc = cv.minMaxLoc(probMap)\n        points.append((int(max_loc[0] * width / output.shape[3]), \n                       int(max_loc[1] * height / output.shape[2])))\n    return points\n```\n\n### Step 12: Display Points \u0026 Skeleton\n\nin this section we use the POSE_PIARS to draw the skeleton of the body. this section uses CPU.\n\n```python\n# CPU based\ndef draw_skeleton(frame, points, POSE_PAIRS): \n    image_skeleton = frame.copy()\n\n    for pair in POSE_PAIRS:\n        partA, partB = pair\n        if points[partA] and points[partB]:\n            cv.line(image_skeleton, points[partA], points[partB], (255, 255, 0), 2)\n            cv.circle(image_skeleton, points[partA], 8, (255, 0, 0), thickness=-1, lineType=cv.FILLED)\n    return image_skeleton\n```\n\n### Step 13: Classifying Gesture\n\nThis section tries to classigying the gesture with points of the body. this section uses CPU.\n\n```python\ndef calculate_angle(line):\n    point1 = line[0]\n    point2 = line[1]\n    if not point1 or not point2:\n        return None\n    \n    x1, y1 = point1\n    x2, y2 = point2\n    dx = x2 - x1\n    dy = y2 - y1\n    \n    angle_rad = math.atan2(dy, dx)\n    angle_deg = math.degrees(angle_rad)\n    if angle_deg \u003c 0:\n        angle_deg += 360\n        \n    return angle_deg\n```\n\n```python\ndef classify_pose(points): # CPU based\n    try:\n        # each points od body are (width, height)\n        head = points[0]\n        neck = points[1]\n        right_shoulder = points[2]\n        right_elbow = points[3]\n        right_wrist = points[4]\n        left_shoulder = points[5]\n        left_elbow = points[6]\n        left_wrist = points[7]\n        right_hip = points[8]\n        right_knee = points[9]\n        right_ankle = points[10]\n        left_hip = points[11]\n        left_knee = points[12]\n        left_ankle = points[13]\n        center = points[14]\n\n        # each line of the body\n        head_line = (head, neck)\n        right_shoulder_line = (neck, right_shoulder)\n        left_shoulder_line = (neck, left_shoulder)\n        torso_line = (neck, center)\n\n        right_upper_arm_line = (right_shoulder, right_elbow)\n        right_lower_arm_line = (right_elbow, right_wrist)\n        left_upper_arm_line = (left_shoulder, left_elbow)\n        left_lower_arm_line = (left_elbow, left_wrist)\n\n        right_thigh_line = (right_hip, right_knee)\n        right_shin_line = (right_knee, right_ankle)\n        left_thigh_line = (left_hip, left_knee)\n        left_shin_line = (left_knee, left_ankle)\n\n        right_hip_line = (center, right_hip)\n        left_hip_line = (center, left_hip)\n\n        if not neck or not center:\n            return \"none\"\n        \n        # detecting Position\n        torso_angle = calculate_angle(torso_line)\n        vertical_torso = False\n        horizental_torso = False\n        if (70 \u003c torso_angle \u003c 110):\n            vertical_torso = True\n        if (150 \u003c torso_angle \u003c 210) or (330 \u003c torso_angle) or (torso_angle \u003c 30):\n            horizental_torso = True\n\n        right_thigh_angle = calculate_angle(right_thigh_line)\n        vertical_right_thigh = False\n        horizental_right_thigh = False\n        if (70 \u003c right_thigh_angle \u003c 110):\n            vertical_right_thigh = True\n        if (150 \u003c right_thigh_angle \u003c 210) or (330 \u003c right_thigh_angle) or (right_thigh_angle \u003c 30):\n            horizental_right_thigh = True\n\n        left_thigh_angle = calculate_angle(left_thigh_line)\n        vertical_left_thigh = False\n        horizental_left_thigh = False\n        if (70 \u003c left_thigh_angle \u003c 110):\n            vertical_left_thigh = True\n        if (150 \u003c left_thigh_angle \u003c 210) or (330 \u003c left_thigh_angle) or (left_thigh_angle \u003c 30):\n            horizental_left_thigh = True\n        \n        # Standing gesture\n        if vertical_torso and vertical_right_thigh and vertical_left_thigh:\n            return \"standing\"\n\n        # Sitting gesture\n        if horizental_left_thigh and horizental_right_thigh and vertical_torso:\n            return \"sitting\"\n\n        # Laying gesture\n        if horizental_torso:\n            return \"laying\"\n\n    except:\n        return \"none\"\n\n    return \"none\"\n```\n\n### Step 14: Put every thing together\n\n```python\ndef detect_gesture(frame, POSE_PAIRS):\n    blob = convert_image_to_blob(frame)\n    net.setInput(blob)\n    output = run_inference()\n    points = extract_keypoints(output, frame.shape[0], frame.shape[1])\n    frame_with_skeleton = draw_skeleton(frame, points, POSE_PAIRS)\n    label = classify_pose(points)\n    return frame_with_skeleton, label\n```\n\n### Step 15: Run Live Gesture Detection\n\nIf you want to use laptop camera use the `cap = cv.VideoCapture(0)` code if you want to use your phone camera you can install IP Webcam and use the second code `cap = cv.VideoCapture('http://21.118.71.170:8080/video', cv.CAP_FFMPEG)`.\n\n```python\ncap = cv.VideoCapture(0)\n# cap = cv.VideoCapture('http://21.118.71.170:8080/video', cv.CAP_FFMPEG)\ncap.set(cv.CAP_PROP_FRAME_WIDTH, 640)\ncap.set(cv.CAP_PROP_FRAME_HEIGHT, 480)\n\nframe_count = 0\nskip_frames = 3\n\nprev_time = time.time()\nwhile True:\n    ret, frame = cap.read()\n    if not ret:\n        break\n\n    frame_count += 1\n    if frame_count % skip_frames != 0:\n        continue\n\n    frame = cv.flip(frame, 1)\n    frame = cv.resize(frame, (640, 480))\n    output_frame, label = detect_gesture(frame, POSE_PAIRS)\n\n    curr_time = time.time()\n    fps = 1 / (curr_time - prev_time)\n    prev_time = curr_time\n\n    cv.putText(output_frame, f\"FPS: {fps:.1f}\", (520, 30), \n                cv.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)\n\n    cv.putText(output_frame, label, (10, 30),\n               cv.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), 2)\n    cv.imshow('Gesture Detection', output_frame)\n\n    k = cv.waitKey(5) \u0026 0xFF\n    if k == 27:\n        break\n\ncv.destroyAllWindows()\ncap.release()\n```\n\n## 🪪 License\n\nThis project is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasadiahmad%2Fgesture-detection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasadiahmad%2Fgesture-detection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasadiahmad%2Fgesture-detection/lists"}