This Python script utilizes the OpenCV and MediaPipe libraries to control the Hill Climb Racing game using hand gestures. The program captures the video feed from the default camera, tracks hand movements, and interprets specific gestures to generate commands for controlling the game.
- Python
- OpenCV
- MediaPipe
- PyAutoGUI
The script consists of the following key components:
- Import necessary libraries:
- cv2 (OpenCV)
- mediapipe
- pyautogui
- time
- Initialize video capture from the default camera.
- Create instances for hand tracking using MediaPipe and initialize drawing utilities.
- Define functions for finding commands based on hand landmarks and for tracing hand movements.
- Inside the main loop:
- Read frames from the camera.
- Flip the frame horizontally for better user experience.
- Process the frame to detect hand landmarks and draw connections.
- Identify commands based on hand gestures.
- Control the Hill Climb Racing game using PyAutoGUI based on detected commands.
- Show the processed frame with hand landmarks on a window.
- Exit the loop if the 'q' key is pressed.
- Command 1: Move the vehicle by pressing gas.
- Command 2: Stop the vehicle by applyinig brakes.
- No Command: No vehicle movement.
Ensure that the required libraries are installed before running the script. The program captures your hand gestures through the camera and translates them into commands for controlling the Hill Climb Racing game.
- This script assumes that the Hill Climb Racing game is running and active.
- Adjustments may be needed for optimal hand gesture detection based on environmental conditions and camera placement.
- Exit the program by pressing the 'q' key in the output window.
Author: Livisha K