Repository navigation
Expand file tree
/
Copy pathbutton.py
More file actions
40 lines (35 loc) · 1.62 KB
/
Copy pathbutton.py
File metadata and controls
40 lines (35 loc) · 1.62 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
import cv2
class Button:
def __init__(self, position, width, height, text):
self.position = position
self.width = width
self.height = height
self.text = text
self.colorFill = (255, 255, 255)
self.colorBorder = (0, 0, 0)
self.colorText = (50, 50, 50)
self.colorFillHighlight = (150, 150, 150)
def draw(self, frame):
cv2.rectangle(frame, self.position,
(self.position[0] + self.width,
self.position[1] + self.height),
self.colorFill, cv2.FILLED)
cv2.rectangle(frame, self.position,
(self.position[0] + self.width,
self.position[1] + self.height),
self.colorBorder, cv2.LINE_4)
cv2.putText(frame, self.text, (self.position[0] + 40, self.position[1] + 60),
cv2.FONT_HERSHEY_PLAIN, 2, self.colorText, 2)
def checkClick(self, frame, x, y):
if (self.isBetween(x, self.position[0], self.position[0] + self.width) and
self.isBetween(y, self.position[1], self.position[1] + self.height)):
cv2.rectangle(frame, self.position,
(self.position[0] + self.width,
self.position[1] + self.height),
self.colorFillHighlight, cv2.FILLED)
cv2.putText(frame, self.text, (self.position[0] + 30, self.position[1] + 70),
cv2.FONT_HERSHEY_PLAIN, 4, self.colorText, 4)
return True
return False
def isBetween(self, x, x1, x2):
return x1 <= x <= x2