-
Notifications
You must be signed in to change notification settings - Fork 0
/
roi_class.py
99 lines (77 loc) · 2.38 KB
/
roi_class.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
#!/usr/bin/env python3
class roi:
def __init__(self, roi_x, roi_y, roi_h, roi_w, frame_base, movement_steps, size_change_steps):
self.x, self.y, self.h, self.w = roi_x, roi_y, roi_h, roi_w
self.frame_y,self.frame_x=frame_base.shape[:2]
self.steps = movement_steps
self.size_steps = size_change_steps
def display_val(self):
return f"x : {self.x}, y : {self.y}, h : {self.h}, w : {self.w}"
def moveup(self):
self.y -= self.steps
def movedown(self):
self.y += self.steps
def moveleft(self):
self.x -= self.steps
def moveright(self):
self.x += self.steps
def create_box(self):
A = (self.x+1, self.y+1)
C = (self.x - self.w - 1, self.y - self.h - 1)
return A, C
def check_all(self):
if self.y < 50:
self.y = 50
if self.y > self.frame_y:
self.y = self.frame_y
if self.x < 50:
self.x = 50
if self.x > self.frame_x:
self.x = self.frame_x
if self.w > self.frame_x:
self.w = self.frame_x
if self.h > self.frame_y:
self.h = self.frame_y
if self.w < 50:
self.w = 50
if self.h < 50:
self.h = 50
if self.x - self.w <0:
self.x = self.w
if self.y - self.h < 0:
self.y =self.h
def increase_size(self):
self.h += self.size_steps
self.w += self.size_steps
def decrease_size(self):
self.h -= self.size_steps
self.w -= self.size_steps
def restore_shape(self):
self.h = self.frame_x//5
self.w = self.frame_x//5
self.x = self.frame_x//2
self.y = self.frame_x//2
def create_roi_zone(self):
# format [y1,y2,x1,x2]
y1 = self.y - self.h
y2 = self.y
x1 = self.x - self.w
x2 = self.x
return [y1, y2, x1, x2]
def action_control(self, key):
if key == ord('w'):
self.moveup()
elif key == ord('s'):
self.movedown()
elif key == ord('a'):
self.moveleft()
elif key == ord('d'):
self.moveright()
elif key == ord('i'):
self.increase_size()
elif key == ord('k'):
self.decrease_size()
elif key == ord('r'):
self.restore_shape()
else:
pass