-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_ROI.py
47 lines (37 loc) · 1.21 KB
/
get_ROI.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
import cv2
def click_event(event, x, y, flags, params):
lanes = params['lanes']
lane = params['lane']
img = params['image']
if event == cv2.EVENT_LBUTTONDOWN:
lane.append((x, y))
cv2.circle(img, (x, y), 3, (0, 0, 255), -1)
cv2.imshow('image', img)
if len(lane) == 4:
lanes.append(lane)
lane = []
def get_lanes(frame):
cv2.imshow('image', frame)
lanes = []
lane = []
lanes_nested = []
params = {'lanes': lanes, 'lane': lane, 'image': frame}
cv2.setMouseCallback('image', click_event, params)
cv2.waitKey(0)
cv2.destroyAllWindows()
# Convert lane coordinates to nested list format
# lanes_nested = [lane[i:i+4] for i in range(0, len(lanes[0]), 4)]
count = 0
for i in range(int(len(lane) / 2) - 1):
lanes_nested.append(lane[count:count + 4])
count += 2
return lanes_nested
def draw_lanes(frame, lanes):
for lane in lanes:
top_left = lane[0]
bottom_left = lane[1]
top_right = lane[2]
bottom_right = lane[3]
cv2.line(frame, top_left, bottom_left, (255, 0, 0), 2)
cv2.line(frame, top_right, bottom_right, (255, 0, 0), 2)
return frame