diff --git a/PYTHON APPS/GestureControlledVolume/GestureControlledVolume.ipynb b/PYTHON APPS/GestureControlledVolume/GestureControlledVolume.ipynb new file mode 100644 index 00000000..2b648868 --- /dev/null +++ b/PYTHON APPS/GestureControlledVolume/GestureControlledVolume.ipynb @@ -0,0 +1,196 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "bbcc9707", + "metadata": {}, + "outputs": [], + "source": [ + "conda install opencv" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9503238e", + "metadata": {}, + "outputs": [], + "source": [ + "import cv2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e7af804f", + "metadata": {}, + "outputs": [], + "source": [ + "import mediapipe as mp" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "953e7623", + "metadata": {}, + "outputs": [], + "source": [ + "import math " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "889f973c", + "metadata": {}, + "outputs": [], + "source": [ + "pip install pycaw" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0bbc1460", + "metadata": {}, + "outputs": [], + "source": [ + "from ctypes import cast, POINTER\n", + "from comtypes import CLSCTX_ALL\n", + "from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fb4f9175", + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f47550a4", + "metadata": {}, + "outputs": [], + "source": [ + "devices = AudioUtilities.GetSpeakers()\n", + "interface = devices.Activate(\n", + " IAudioEndpointVolume._iid_, CLSCTX_ALL, None)\n", + "volume = cast(interface, POINTER(IAudioEndpointVolume))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0f9c586f", + "metadata": {}, + "outputs": [], + "source": [ + "#volume.GetMute()\n", + "#print(volume.GetMasterVolumeLevel())\n", + "#print(volume.GetVolumeRange())\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3a7cc9ac", + "metadata": {}, + "outputs": [], + "source": [ + "cap = cv2.VideoCapture(0)\n", + "mpHands = mp.solutions.hands\n", + "hands = mpHands.Hands()\n", + "mpDraw = mp.solutions.drawing_utils\n", + "\n", + "\n", + "while True:\n", + " success,img = cap.read()\n", + " imgRGB = cv2.cvtColor(img , cv2.COLOR_BGR2RGB)\n", + " results= hands.process(imgRGB)\n", + " #print(results.multi_hand_landmarks)\n", + " \n", + " if results.multi_hand_landmarks:\n", + " for handLms in results.multi_hand_landmarks:\n", + " lmList =[]\n", + " for id, lm in enumerate (handLms.landmark):\n", + " #print(id, lm)\n", + " h , w , c = img.shape\n", + " cx , cy = int(lm.x*w), int(lm.y*h)\n", + " #print(id, cx, cy)\n", + " lmList.append([id, cx, cy])\n", + " #print(lmList)\n", + " mpDraw.draw_landmarks(img,handLms,mpHands.HAND_CONNECTIONS)\n", + " \n", + " if lmList:\n", + " x1,y1 = lmList[4][1],lmList[4][2]\n", + " x2,y2 = lmList[8][1],lmList[8][2]\n", + " \n", + " cv2.circle(img,(x1,y1),10,(255,0,9),cv2.FILLED)\n", + " cv2.circle(img,(x2,y2),10,(255,0,9),cv2.FILLED)\n", + " cv2.line(img,(x1,y1),(x2,y2),(134,1,175),3)\n", + " \n", + " length = math.hypot(x2-x1,y2-y1)\n", + " print(length)\n", + " \n", + " if length <50:\n", + " z1 = (x1+x2)//2\n", + " z2 = (y1+y2)//2\n", + " cv2.circle(img,(z1,z2),10,(255,0,9),cv2.FILLED)\n", + " \n", + " volRange = volume.GetVolumeRange()\n", + " minVol = volRange[0]\n", + " maxVol = volRange[1]\n", + " vol = np.interp(length,[50,300],[minVol,maxVol])\n", + " volBar = np.interp(length, [50,300],[400,150])\n", + " volPer = np.interp(length, [50,300],[0,100])\n", + " volume.SetMasterVolumeLevel(vol,None)\n", + " cv2.rectangle(img,(50,150),(85,400),(191,62,255),3)\n", + " cv2.rectangle(img,(50,int(volBar)),(85,400),(191,62,255),cv2.FILLED)\n", + " cv2.putText(img,str(int(volPer)),(40,100),cv2.FONT_HERSHEY_DUPLEX,4,(126,58,234))\n", + " \n", + " \n", + " cv2.imshow(\"Image\",img) \n", + " cv2.waitKey(1)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f5735e95", + "metadata": {}, + "outputs": [], + "source": [ + "#length 50-300\n", + "#volRange -24 to +21" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/PYTHON APPS/GestureControlledVolume/README.md b/PYTHON APPS/GestureControlledVolume/README.md new file mode 100644 index 00000000..80ea10b4 --- /dev/null +++ b/PYTHON APPS/GestureControlledVolume/README.md @@ -0,0 +1,21 @@ +## Introduction + +Gesture Controlled Volume is an interactive Python project that allows you to control your computer's audio volume using hand gestures detected by your camera. It combines computer vision, hand tracking, and audio control to provide a unique and intuitive way to adjust audio settings. + +## Features + +- Real-time hand tracking using the MediaPipe library. +- Interactive volume control based on the distance between two fingers. +- Visual feedback on the video feed for a user-friendly experience. + +## Requirements + +To run Gesture Controlled Volume, you need the following: + +- Python 3.x +- OpenCV +- MediaPipe +- NumPy +- pycaw + +You can install these dependencies using the provided `requirements.txt` file. \ No newline at end of file diff --git a/PYTHON APPS/GestureControlledVolume/requirements.txt b/PYTHON APPS/GestureControlledVolume/requirements.txt new file mode 100644 index 00000000..71f1f88f --- /dev/null +++ b/PYTHON APPS/GestureControlledVolume/requirements.txt @@ -0,0 +1,16 @@ +# requirements.txt + +# Specify the required Python version +python_version >= 3.6 + +# OpenCV for computer vision +opencv-python==4.5.3 + +# MediaPipe for hand tracking +mediapipe==0.8.3 + +# NumPy for numerical operations +numpy==1.21.2 + +# pycaw for audio control +pycaw==2021.6.24