-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgesture,.py
140 lines (116 loc) · 4.13 KB
/
gesture,.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
from cvzone.HandTrackingModule import HandDetector
import cv2
import os
import numpy as np
from comtypes import client
from spire.presentation.common import *
from spire.presentation import *
# Create a Presentation object
presentation = Presentation()
# Load a PowerPoint presentation
presentation.LoadFromFile("./1ST REVIEW.pptx")#give the path of the powerpoint file
# Loop through the slides in the presentation
for i, slide in enumerate(presentation.Slides):
# Specify the output file name
fileName ="./Presentation/"+str(i) + ".png"
# Save each slide as a PNG image
image = slide.SaveAsImage()
image.Save(fileName)
image.Dispose()
# Parameters
width, height = 1280, 720
gestureThreshold = 300
folderPath = "./Presentation"
# Camera Setup
cap = cv2.VideoCapture(0)
cap.set(3, width)
cap.set(4, height)
# Hand Detector
detectorHand = HandDetector(detectionCon=0.8, maxHands=1)
# Variables
imgList = []
delay = 30
buttonPressed = False
counter = 0
drawMode = False
imgNumber = 0
delayCounter = 0
annotations = [[]]
annotationNumber = -1
annotationStart = False
hs, ws = int(120 * 1), int(213 * 1) # width and height of small image
# Get list of presentation images
pathImages = sorted(os.listdir(folderPath), key=len)
print(pathImages)
while True:
# Get image frame
success, img = cap.read()
img = cv2.flip(img, 1)
pathFullImage = os.path.join(folderPath, pathImages[imgNumber])
imgCurrent = cv2.imread(pathFullImage)
# Find the hand and its landmarks
hands, img = detectorHand.findHands(img) # with draw
# Draw Gesture Threshold line
cv2.line(img, (0, gestureThreshold), (width, gestureThreshold), (0, 255, 0), 10)
if hands and buttonPressed is False: # If hand is detected
hand = hands[0]
cx, cy = hand["center"]
lmList = hand["lmList"] # List of 21 Landmark points
fingers = detectorHand.fingersUp(hand) # List of which fingers are up
# Constrain values for easier drawing
xVal = int(np.interp(lmList[8][0], [width // 2, width], [0, width]))
yVal = int(np.interp(lmList[8][1], [150, height-150], [0, height]))
indexFinger = xVal, yVal
if cy <= gestureThreshold: # If hand is at the height of the face
if fingers == [1, 1, 1, 1, 1]:
print("Left")
buttonPressed = True
if imgNumber > 0:
imgNumber -= 1
annotations = [[]]
annotationNumber = -1
annotationStart = False
if fingers == [0, 1, 1, 1, 1]:
print("Right")
buttonPressed = True
if imgNumber < len(pathImages) - 1:
imgNumber += 1
annotations = [[]]
annotationNumber = -1
annotationStart = False
if fingers == [0, 1, 1, 0, 0]:
cv2.circle(imgCurrent, indexFinger, 12, (0, 0, 255), cv2.FILLED)
if fingers == [0, 1, 0, 0, 0]:
if annotationStart is False:
annotationStart = True
annotationNumber += 1
annotations.append([])
print(annotationNumber)
annotations[annotationNumber].append(indexFinger)
cv2.circle(imgCurrent, indexFinger, 12, (0, 0, 255), cv2.FILLED)
else:
annotationStart = False
if fingers == [0, 1, 1, 1, 0]:
if annotations:
annotations.pop(-1)
annotationNumber -= 1
buttonPressed = True
else:
annotationStart = False
if buttonPressed:
counter += 1
if counter > delay:
counter = 0
buttonPressed = False
for i, annotation in enumerate(annotations):
for j in range(len(annotation)):
if j != 0:
cv2.line(imgCurrent, annotation[j - 1], annotation[j], (0, 0, 200), 12)
imgSmall = cv2.resize(img, (ws, hs))
h, w, _ = imgCurrent.shape
imgCurrent[0:hs, w - ws: w] = imgSmall
cv2.imshow("Slides", imgCurrent)
cv2.imshow("Image", img)
key = cv2.waitKey(1)
if key == ord('q'):
break