Skip to content

Commit 5f7fdd5

Browse files
authored
Hand_Gesture_controlled_ppt_presentation (#263)
Add Hand Gesture controlled PPT presentation
1 parent e06a076 commit 5f7fdd5

File tree

7 files changed

+91
-0
lines changed

7 files changed

+91
-0
lines changed
50 KB
Loading
83.5 KB
Loading
573 KB
Loading
409 KB
Loading
39.8 KB
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Hand_Gesture_controlled_ppt_presentation
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import os
2+
from cvzone.HandTrackingModule import HandDetector
3+
import cv2
4+
import numpy as np
5+
6+
7+
width, height = 1280, 720
8+
folderPath = "Presentation"
9+
#camera
10+
cap = cv2.VideoCapture(0)
11+
cap.set(3,width)
12+
cap.set(4,height)
13+
#get list of slides
14+
pathImages = sorted(os.listdir(folderPath), key=len)
15+
print(pathImages)
16+
#var
17+
imgNum = 0
18+
hs,ws = int(120*1.2), int(213*1)
19+
gestureThreshold = 300
20+
btnpressed = False
21+
btncounter = 0
22+
btnDelay = 30
23+
annot =[]
24+
25+
#hand detector
26+
detector = HandDetector(detectionCon=0.8,maxHands=1)
27+
while True:
28+
#import images
29+
30+
success, img = cap.read()
31+
img = cv2.flip(img, 1)
32+
pathFullImage = os.path.join(folderPath, pathImages[imgNum])
33+
imgCurent = cv2.imread(pathFullImage)
34+
35+
hands, img = detector.findHands(img)#, flipType=False
36+
cv2.line(img,(0, gestureThreshold),(width, gestureThreshold),(0,255,0),10)
37+
38+
if hands and btnpressed is False:
39+
hand = hands[0]
40+
fingers =detector.fingersUp(hand)
41+
cx, cy = hand['center']
42+
lmList = hand['lmList']
43+
44+
#contrain values for drawing
45+
xVal = int(np.interp(lmList[8][0],[width//2,w], [0, width]))
46+
yVal = int(np.interp(lmList[8][1], [150, height-150], [0, height]))
47+
indexfinger = xVal,yVal
48+
49+
#print(fingers)
50+
if cy <= gestureThreshold: #if hand is at the height of the face
51+
#gest 1 -left
52+
if fingers == [1,0,0,0,0]:
53+
54+
if imgNum>0:
55+
btnpressed = True
56+
imgNum -= 1
57+
print('left')
58+
elif fingers == [0, 0, 0, 0, 1]:
59+
60+
if imgNum < len(pathImages)-1:
61+
btnpressed = True
62+
print('right')
63+
imgNum += 1
64+
elif fingers == [0, 1, 0, 0, 0]:
65+
print('point')
66+
if fingers == [0, 1, 1, 0, 0]:
67+
cv2.circle(imgCurent, indexfinger, 12, (0, 0, 255), cv2.FILLED)
68+
annot.append(indexfinger)
69+
print('draw')
70+
71+
#btnpressed iteration
72+
if btnpressed:
73+
btncounter += 1
74+
if btncounter > btnDelay:
75+
btncounter = 0
76+
btnpressed = False
77+
78+
for i in range(len(annot)):
79+
if i!=0:
80+
cv2.line(imgCurent,annot[i-1], annot[i],(0,0,200),12)
81+
#add webcam image on the slides
82+
imgSmall = cv2.resize(img, (ws,hs))
83+
h,w, _ = imgCurent.shape
84+
imgCurent[0:hs, w-ws:w] = imgSmall
85+
86+
cv2.imshow("Image", img)
87+
cv2.imshow("Slide",imgCurent)
88+
key = cv2.waitKey(1)
89+
if key == ord('q'):
90+
break

0 commit comments

Comments
 (0)