-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
63 lines (60 loc) · 1.93 KB
/
app.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
import cv2
from hand_tracking import Tracker
from calculator import Button, draw_calculator
cap = cv2.VideoCapture(0)
cap.set(3, 1280)
cap.set(4, 720)
tracker = Tracker()
equation = ''
result = ''
delay = 0
while True:
success, img = cap.read()
img = cv2.flip(img, 1)
img = tracker.hand_landmark(img)
img, button_list = draw_calculator(img)
img, dist, x1, y1 = tracker.tracking(img)
for button in button_list:
if button.check_click(img, dist, x1, y1) and delay == 0:
if button.value == 'DEL':
if equation=='':
equaion = ''
elif equation == 'error':
equation = ''
else:
equation = equation[:-1]
delay = 1
elif button.value == '^':
if equation == 'error':
equation = ''
equation += '**'
delay = 1
elif button.value == 'CLEAR':
if equation == 'error':
equation = ''
equation = ''
delay = 1
elif button.value == '=':
if equation == 'error':
equation = ''
if equation=='':
equation=''
else:
try:
equation = str(eval(equation))
except:
equation = 'error'
delay = 1
else:
if equation=='error':
equation = ''
equation += button.value
cv2.putText(img, equation, (600, 150), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 0, 255), 2)
delay = 1
if delay:
delay += 1
if delay > 10:
delay = 0
cv2.putText(img, equation, (600, 150), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 0, 255), 2)
cv2.imshow('Image', img)
cv2.waitKey(1)