-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.py
More file actions
110 lines (85 loc) · 3.33 KB
/
Copy pathproject.py
File metadata and controls
110 lines (85 loc) · 3.33 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
import notify2
import sys
import os
import math
import asyncio
import cv2
import mediapipe as mp
directory = '.'
if len(sys.argv) > 1:
directory = sys.argv[1]
def fire_and_forget(f):
def wrapped(*args, **kwargs):
return asyncio.get_event_loop().run_in_executor(None, f, *args, *kwargs)
return wrapped
@fire_and_forget
def make_commit():
os.system('git add ' + directory)
os.system('git commit -m "Changes in ' + directory + ' pushed by gcommit"')
os.system('git push')
print('gcommit: done commit and push of ' + directory)
notify2.init('gcommit')
n = notify2.Notification('GCommit', 'Changes in ' + directory + ' have been pushed')
n.show()
cap = cv2.VideoCapture(0)
mpHands = mp.solutions.hands
hands = mpHands.Hands()
mpDraw = mp.solutions.drawing_utils
img_stretch = cv2.imread('resized.png')
rows, cols, channels = img_stretch.shape
img2gray = cv2.cvtColor(img_stretch, cv2.COLOR_BGR2GRAY)
ret, mask = cv2.threshold(img2gray, 200, 255, cv2.THRESH_BINARY)
mask_inv = cv2.bitwise_not(mask)
# Take only region of logo from logo image.
img_stretch_fg = cv2.bitwise_and(img_stretch, img_stretch, mask = mask_inv)
first_enter = True
font = cv2.FONT_HERSHEY_SIMPLEX
fontScale = 1
color = (255, 0, 0)
thickness = 2
while True:
success, image = cap.read()
image = cv2.flip(image, 1)
imageRGB = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
results = hands.process(imageRGB)
h, w, c = image.shape
desired_h = 0.5 * h
desired_w = 0.2 * w
# cv2.rectangle(image, (3, 3), (int(desired_w), int(desired_h)), (34, 123, 249), 3)
roi = image[0:rows, -1-cols:-1]
image_bg = cv2.bitwise_and(roi, roi, mask = mask)
dst = cv2.add(image_bg, img_stretch_fg)
image[0:rows, -1-cols:-1] = dst
# checking whether a hand is detected
if results.multi_hand_landmarks:
for handLms in results.multi_hand_landmarks[0:]: # working with each hand
for id, lm in enumerate(handLms.landmark):
h, w, c = image.shape
cx, cy = int(lm.x * w), int(lm.y * h)
if id == 0:
pos0 = (cx, cy)
if id == 12:
pos1 = (cx, cy)
if id == 8:
pos_pointer = (cx, cy)
distance=(pos0[0] - pos1[0]) * (pos0[0] - pos1[0]) + (pos0[1] - pos1[1]) * (pos0[1] - pos1[1])
distance=math.sqrt(distance)
if distance < 0.2 * h:
if (pos_pointer[0] < desired_w and pos_pointer[1] < desired_h):
cv2.putText(image, 'ok, uploaded', (30, 30), font, fontScale, (170, 203, 86), thickness, cv2.LINE_AA)
if (first_enter):
print('pushing now')
make_commit()
print('out of pushing')
first_enter = False
else:
text = cv2.putText(image, 'Now stretch!', (30, 30), font, fontScale, (170, 203, 86), thickness, cv2.LINE_AA)
first_enter = True
else:
cv2.putText(image, 'move back', (30, 30), font, fontScale, (34, 123, 249), thickness, cv2.LINE_AA)
mpDraw.draw_landmarks(image, handLms, mpHands.HAND_CONNECTIONS)
cv2.imshow("Output", image)
if cv2.waitKey(1) == 27:
break
cap.release()
cv2.destroyAllWindows()