Have you ever wished you could control your PowerPoint presentations with just a wave of your hand? Imagine presenting to an audience and effortlessly switching slides with natural hand gestures, no clicker required. Thanks to Python, OpenCV, and MediaPipe, this futuristic concept can be a reality!
In this blog, we'll explore a Python script that enables you to navigate your PowerPoint presentation using hand gestures. This script detects your hand movements via your webcam and translates them into slide navigation commands.
Prerequisites
This project combines MediaPipe
for hand detection and win32com.client
to interact with Microsoft PowerPoint. Here’s a breakdown of what it does:
- Hand Detection: Detects left and right hands using your webcam feed.
-
Slide Control:
- A left-hand gesture moves to the previous slide.
- A right-hand gesture advances to the next slide.
- Seamless Interaction: Automatically syncs with your PowerPoint presentation to control slides in real-time.
How It Works
-
Dependencies
The script uses the following Python libraries:
- Hand Detection:: Detects left and right hands using your webcam feed.
- Slide Control::
- Seamless Interaction:: Automatically syncs with your PowerPoint presentation to control slides in real-time.
Install the required libraries using the following commands:
pip install opencv-python mediapipe pywin32
-
Core Logic
The script:
-
Opens a PowerPoint Presentation
: It uses
win32com.client
to open the specified PowerPoint file in slideshow mode. - Captures Webcam Feed: : Uses OpenCV to capture live video from your webcam.
- Detects Hand Gestures : MediaPipe detects hands and identifies whether the left or right hand is raised.
-
Controls Slides:
- If a left hand is detected, it moves to the previous slide.
- If a right hand is detected, it advances to the next slide.
-
Opens a PowerPoint Presentation
: It uses
-
Usage Instructions
Replace the
file_path
variable in the script with the path to your PowerPoint file. For example:file_path = "C:/Users/YourName/Presentation.pptx"
run the script:
python hand_gesture_ppt.py
Control the slideshow:
- Classrooms : Raise your left hand to go back.
- Conferences : Raise your right hand to move forward.
Press 'q' to exit the application.
Code Walkthrough
Here's the full code for the hand gesture-based PowerPoint controller:
import cv2
import time
import mediapipe as mp
import win32com.client
from google.protobuf.json_format import MessageToDict
def pptx_controller(app, hands, file_path):
app = win32com.client.Dispatch("PowerPoint.Application")
presentation = app.Presentations.Open(FileName=file_path, ReadOnly=1)
presentation.SlideShowSettings.run()
def moveRight():
time.sleep(1)
presentation.SlideShowWindow.View.Next()
def moveLeft():
time.sleep(1)
presentation.SlideShowWindow.View.Previous()
cap = cv2.VideoCapture(0)
while True:
success, img = cap.read()
if success:
imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
results = hands.process(imgRGB)
if results.multi_hand_landmarks:
for i in results.multi_handedness:
label = MessageToDict(i)['classification'][0]['label']
if label == 'Left':
cv2.putText(img, label+' Hand', (20, 50),cv2.FONT_HERSHEY_COMPLEX, 0.9, (0, 255, 0), 2)
moveLeft()
if label == 'Right':
cv2.putText(img, label+' Hand', (460, 50), cv2.FONT_HERSHEY_COMPLEX,0.9, (0, 255, 0), 2)
moveRight()
if cv2.waitKey(1) & 0xff == ord('q'):
break
if __name__ == '__main__':
app = win32com.client.Dispatch("PowerPoint.Application")
mpHands = mp.solutions.hands
hands = mpHands.Hands(
static_image_mode=False,
model_complexity=1,
min_detection_confidence=0.75,
min_tracking_confidence=0.75,
max_num_hands=2)
file_path = "./" # Replace with your presentation file path
pptx_controller(app, hands, file_path)
The script will create a
transcription.txt
file
containing the video title and transcription.
Why This is Cool
- Hands-Free Control : No need for clickers or remotes
- Interactive Presentations : Engage your audience with effortless navigation
- Easy to Customize : Modify the gestures or add additional features like gesture-based annotations.
Applications
- Classrooms : Teachers can navigate slides without needing to be near their laptop.
- Conferences : Impress your audience with a tech-savvy presentation style.
- Remote Meetings : Use it to control slides in virtual meetings while maintaining focus on the camera.
Enhancements and Future Ideas
- Custom Gestures : Add more gestures for advanced controls like starting/stopping the slideshow.
- Voice Commands : Combine with speech recognition for voice-enabled controls.
- Gesture Feedback : Display visual feedback on the screen for each gesture.
Comments
Post a Comment