-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStream.py
More file actions
209 lines (123 loc) · 6.15 KB
/
Stream.py
File metadata and controls
209 lines (123 loc) · 6.15 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import cv2
from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtWidgets import QLabel, QVBoxLayout, QWidget
import numpy as np
from PyQt5.QtCore import QTimer
from cvzone.HandTrackingModule import HandDetector
from cvzone.PoseModule import PoseDetector
import pyautogui
from PyQt5.QtCore import Qt
import autopy
def Is_Blank(Image):
# Count the number of zeros in the image array
num_zeros = np.count_nonzero(Image == 0)
Percentage_Zeros= num_zeros/np.prod(Image.shape)
if Percentage_Zeros > 0.8:
return True
return False
class Present(QWidget):
def __init__(self, camera_index):
super().__init__()
layout = QVBoxLayout()
self.video_capture = cv2.VideoCapture(camera_index, cv2.CAP_DSHOW)
self.video_label = QLabel(self)
self.video_label.setAlignment(Qt.AlignCenter)
layout.addWidget(self.video_label)
self.setLayout(layout)
self.timer = QTimer(self)
self.timer.timeout.connect(self.get_frame)
self.timer.start(2) # Retrieve frames every 5ms
def SDPE(self):
pyautogui.FAILSAFE = False
pTime = 0
WScr,HScr = autopy.screen.size()
gestureTh = 0
Get_Out = False
Smoothning = 3
plocX,plocY = 0,0
clocX,clocY = 0,0
# Initialize the PoseDetector class with the given parameters
Pose_detector = PoseDetector(staticMode=False,
modelComplexity=1,
smoothLandmarks=True,
enableSegmentation=False,
smoothSegmentation=True,
detectionCon=0.5,
trackCon=0.5)
Handetector = HandDetector(detectionCon=0.8,minTrackCon=0.7,maxHands=1)
while True:
Frame = self.get_frame()
Frame = cv2.flip(Frame, 1)
# Resize the frame
Frame = cv2.resize(Frame, (800, 600))
# The dimension s of the frame :
_, WCam = Frame.shape[:2]
# Find the human pose in the frame
Frame = Pose_detector.findPose(Frame,draw=False)
PoselmList,_ = Pose_detector.findPosition(Frame, draw=False, bboxWithHands=False)
if 11 < len(PoselmList):
gestureTh = int(PoselmList[11][1])
hands,Frame = Handetector.findHands(Frame)
if hands:
hand = hands[0]
FingersUp_list = Handetector.fingersUp(hand)
lmlist = hand['lmList']
x8,y8 = lmlist[8][0],lmlist[8][1]
FingersUp_list = Handetector.fingersUp(hand)
if lmlist[0][1] < gestureTh:
pyautogui.keyUp('ctrl')
if hand['type'] == 'Left': ## It's Right hand in reality hhhh
# Go UP :
if FingersUp_list == [1,0,0,0,0]:
pyautogui.press('pgup',interval=1)
# Go Down:
if FingersUp_list == [0,0,0,0,1]:
pyautogui.press('pgdn',interval=1)
# Moving the Mouse :
if FingersUp_list == [0,1,0,0,0]:
x8 = np.interp(x8,(WCam-300,WCam-200),(0,WScr))
y8 = np.interp(y8,(80,150),(0,HScr))
#Smoothen the values :
clocX = plocX + (x8-plocX)/Smoothning
clocY = plocY + (y8-plocY)/Smoothning
autopy.mouse.move(clocX,clocY)
plocX,plocY = clocX,clocY
# Clicking:
if FingersUp_list == [1,1,0,0,0]:
pyautogui.click()
pyautogui.sleep(0.5)
# Double Click:
if FingersUp_list == [1,1,1,0,0]:
pyautogui.doubleClick()
# Zoom In
if FingersUp_list == [0,1,1,0,0]:
pyautogui.keyDown('ctrl')
pyautogui.scroll(30)
# Zoom Out
if FingersUp_list == [0,1,1,1,0]:
pyautogui.keyDown('ctrl')
pyautogui.scroll(-30)
if hand['type'] == 'Right':
# Get Out:
if FingersUp_list == [1,1,1,1,1]:
Get_Out = True
# Frame Rate :
#cTime = time.time()
#fps = 1/(cTime-pTime)
#pTime = cTime
#cv2.putText(Frame,str(int(fps)),(20,50),cv2.FONT_HERSHEY_PLAIN,3,(255,0,0),3)
#Draw the Threshold
#cv2.line(Frame,(0,gestureTh),(int(WScr),gestureTh),(0,255,0),10)
#cv2.circle(Frame, (500,gestureTh-300), 10, (255,0,0), -1)
#cv2.circle(Frame, (WCam-80,gestureTh-500), 10, (0,255,0), -1)
#cv2.imshow('Image',Frame)
if cv2.waitKey(1) & 0xFF == ord('q') or Get_Out:
pyautogui.keyUp('ctrl')
cv2.destroyAllWindows()
return Get_Out
def get_frame(self):
ret, frame = self.video_capture.read()
if ret:
return frame
else:
return None