-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutil.py
58 lines (46 loc) · 1.74 KB
/
util.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
import cv2
import numpy as np
INPUT_PATH = 'input/'
OUTPUT_PATH = 'output/'
POINT_MAPS_PATH = 'point_maps/'
FRAMES_PATH = 'frames/'
BLUE = (255, 0, 0)
GREEN = (0, 255, 0)
RED = (0, 0, 255)
def drawInliersOutliers(image, point_map, inliers):
"""
inliers: set of (x1, y1) points
"""
rows, cols = image.shape
retImage = np.zeros((rows, cols, 3), dtype='uint8')
retImage[:, :, :] = np.dstack([image] * 3)
# Draw circles on top of the lines
for x1, y1, x2, y2 in point_map:
point = (int(x1), int(y1))
color = GREEN if (x1, y1, x2, y2) in inliers else RED
cv2.circle(retImage, point, 4, color, 1)
return retImage
def drawMatches(image1, image2, point_map, inliers=None, max_points=1000):
"""
inliers: set of (x1, y1) points
"""
rows1, cols1 = image1.shape
rows2, cols2 = image2.shape
matchImage = np.zeros((max(rows1, rows2), cols1 + cols2, 3), dtype='uint8')
matchImage[:rows1, :cols1, :] = np.dstack([image1] * 3)
matchImage[:rows2, cols1:cols1 + cols2, :] = np.dstack([image2] * 3)
small_point_map = [point_map[i] for i in np.random.choice(len(point_map), max_points)]
# draw lines
for x1, y1, x2, y2 in small_point_map:
point1 = (int(x1), int(y1))
point2 = (int(x2 + image1.shape[1]), int(y2))
color = BLUE if inliers is None else (
GREEN if (x1, y1, x2, y2) in inliers else RED)
cv2.line(matchImage, point1, point2, color, 1)
# Draw circles on top of the lines
for x1, y1, x2, y2 in small_point_map:
point1 = (int(x1), int(y1))
point2 = (int(x2 + image1.shape[1]), int(y2))
cv2.circle(matchImage, point1, 5, BLUE, 1)
cv2.circle(matchImage, point2, 5, BLUE, 1)
return matchImage