Importing Required Modules
Firstly we need to sets up the necessary dependencies for a Python program that may involve computer vision, audio control, and screen brightness control.
Python3
import cv2 import mediapipe as mp import pyautogui import math from enum import IntEnum from ctypes import cast, POINTER from comtypes import CLSCTX_ALL from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume from google.protobuf.json_format import MessageToDict import screen_brightness_control as sbcontrol |
The imported libraries and modules in the code snippet serve various purposes for the Python program. he code snippet also includes two custom classes, Gest and HLabel, which define enumerations for gesture encodings and multi-handedness labels, respectively. These enumerations assign integer values to different gestures and hand labels for easier identification and processing in the program.
Python3
# To create GUI import tkinter as tk from PIL import ImageTk, Image pyautogui.FAILSAFE = False mp_drawing = mp.solutions.drawing_utils mp_hands = mp.solutions.hands # Gesture Encodings class Gest(IntEnum): # Binary Encoded FIST = 0 PINKY = 1 RING = 2 MID = 4 LAST3 = 7 INDEX = 8 FIRST2 = 12 LAST4 = 15 THUMB = 16 PALM = 31 # Extra Mappings V_GEST = 33 TWO_FINGER_CLOSED = 34 PINCH_MAJOR = 35 PINCH_MINOR = 36 # Multi-handedness Labels class HLabel(IntEnum): MINOR = 0 MAJOR = 1 |
Real-Time AI Virtual Mouse System Using Computer Vision
AI Virtual Mouse is a software that allows users to give inputs of a mouse to the system without using the actual mouse. To the extreme, it can also be called hardware as it uses an ordinary camera. A virtual muse can usually be operated with multiple input devices, which may include an actual mouse or computer keyboard. The virtual mouse uses a web camera with the help of different image processing techniques. Using figures detection methods for instant Camera access and a user-friendly interface makes it more easily accessible. The system is used to implement a motion-tracking mouse, a physical mouse that saves time and also reduces effort. The hand movements of a user are mapped into mouse inputs. A web camera is set to take images continuously. Most laptops today are equipped with webcams, which have recently been used in security applications utilizing face recognition. To harness the full potential of a webcam, it can be used for vision-based CC which would effectively eliminate the need for a computer mouse or mouse pad. The usefulness of a webcam can also be greatly extended to other HCI applications such as a sign language database or motion controller.
Software Specification:
- Python Libraries: Various Python libraries like OpenCV, NumPy, PyAutoGUI, and TensorFlow can be used for building the Al virtual mouse system.
- Open CV: This library is used for image and video processing, which can be used for hand detection and tracking.
- NumPy: NumPy is used for numerical computations, and it is used to process the captured images.
- PyAutoGUI: PyAuto GUI is used to control the mouse movements and clicks.
- Mediapipe: A cross-platform framework for building multi-modal applied machine learning pipelines.
- Comtypes: A Python module that provides access to Windows COM and .NET components.
- Screen-Brightness-Control: A Python module for controlling the brightness of the screen on Windows, Linux, and macOS.
Detecting which Fingure is Up and Performing the particular Mouse Function
Over here we are detecting which finger is Up using the tip ID of the respective finger that we found using the MideaPipe and the respective figure that we found using the Mediapipe and the respective coordinates of the fingers that are up, according to that we found using the MediaPipe and the respective co-coordinates of the figures that are up and according to that the particular mouse function is performed.
Mouse Functions depending on the Hand Gestures and Hand Tip Detection. Using Computer Vision for the mouse cursor moving around the system window. If the index fingure is up with tip Id = 1 or both the index finger with tip Id = 1 and the middle finger with tip Id =2 are up, the mouse cursor is made to move around the window of the computer using the AutoPy package of Python.