-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscene.py
More file actions
56 lines (45 loc) · 1.6 KB
/
scene.py
File metadata and controls
56 lines (45 loc) · 1.6 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
import cv2
from enum import Enum
class States(Enum):
INIT = 0
KEYPOINTS = 1
SELECTION = 2
MATCHING = 3
ESTIMATION = 4
COMPUTE_DISTANCE = 5
class Scene:
def __init__(self, left_img, right_img):
self.keypoints = []
self.selected_points = []
self.distance_points = []
self.nnpoint = []
self.actions = []
self.lines = []
self.left_img = left_img
self.right_img = right_img
self.img_vis = cv2.cvtColor(left_img, cv2.COLOR_GRAY2BGR)
self.copy_img = self.img_vis.copy()
self.status = States.INIT
def draw_point(self, center_coords, r, color):
# image, center_coordinates, radius, color, thickness
cv2.circle(self.img_vis, center_coords, r, color, -1)
self.actions.append((center_coords, r, color))
def delete_point(self):
if len(self.actions):
self.img_vis = self.copy_img.copy()
self.actions.pop()
past_actions = self.actions.copy()
self.actions = []
for point in past_actions:
self.draw_point(point[0], point[1], point[2])
def draw_line(self, pt1, pt2, color):
cv2.line(self.img_vis, pt1, pt2, color, 1)
self.lines.append((pt1, pt2, color))
def delete_line(self):
if len(self.lines):
self.img_vis = self.copy_img.copy()
self.lines.pop()
past_lines = self.lines.pop()
self.lines = []
for line in past_lines:
self.draw_line(line[0], line[1], line[2])