-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
101 lines (77 loc) · 3.03 KB
/
main.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
import cv2
from cvzone.HandTrackingModule import HandDetector
class Button:
def __init__(self,pos,width,height,value):
self.pos = pos
self.width = width
self.height = height
self.value = value
def draw(self,img):
cv2.rectangle(img,self.pos,(self.pos[0]+self.width,self.pos[1]+self.height),(225,225,225),cv2.FILLED)
cv2.rectangle(img,self.pos,(self.pos[0]+self.width,self.pos[1]+self.height),(50,50,50),3)
cv2.putText(img,self.value,(self.pos[0]+40,self.pos[1]+60),cv2.FONT_HERSHEY_PLAIN,2,(50,50,50),2)
def checkClick(self,x,y):
if self.pos[0]<x<self.pos[0]+self.width and self.pos[1]<y<self.pos[1]+self.height:
cv2.rectangle(img,self.pos,(self.pos[0]+self.width,self.pos[1]+self.height),(255,255,255),cv2.FILLED)
cv2.rectangle(img,self.pos,(self.pos[0]+self.width,self.pos[1]+self.height),(50,50,50),3)
cv2.putText(img,self.value,(self.pos[0]+25,self.pos[1]+80),cv2.FONT_HERSHEY_PLAIN,5,(0,0,0),5)
return True
else:
return False
# Webcam
cap = cv2.VideoCapture(0)
cap.set(3,1280) # width
cap.set(4,720) # height
detector = HandDetector(detectionCon=0.8, maxHands=1)
# Creating Buttons
buttonListValues = [['7','8','9','*'],
['4','5','6','-'],
['1','2','3','+'],
['0','/','.','=']]
buttonList = []
for x in range(4):
for y in range(4):
xpos = x*100+800
ypos = y*100+150
buttonList.append(Button((xpos,ypos),100,100,buttonListValues[y][x]))
# Variables
myEquation = ''
delayCounter = 0
# Loop
while True:
# Get image from webcam
success, img = cap.read()
img = cv2.flip(img,1)
# Detection of hand
hands, img = detector.findHands(img,flipType=False)
# Draw all buttons