-
Notifications
You must be signed in to change notification settings - Fork 1
/
visual_debug.py
141 lines (105 loc) · 4.08 KB
/
visual_debug.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import cv2 as cv
import numpy as np
from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import
import matplotlib.pyplot as plt
import config
# visualize 3d points in a scatter plot
def visualize_3d_scatter(m_pts):
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
ax.scatter3D(m_pts[:,0], m_pts[:,1], m_pts[:,2], s=100, c='red')
plt.show()
def visualize_3d_lines(m_edges):
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
for edge in m_edges:
line = []
# extract end points
edge_start = edge[0:3]
edge_end = edge[3:6]
line.append(edge_start)
line.append(edge_end)
line = np.asarray(line)
ax.plot3D(line[:, 0], line[:, 1], line[:, 2], 'blue')
plt.show()
def visualize_3d_lines_pts(m_edges, m_pts_sampled, m_pts_edges):
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
for edge in m_edges:
line = []
# extract end points
edge_start = edge[0:3]
edge_end = edge[3:6]
line.append(edge_start)
line.append(edge_end)
line = np.asarray(line)
ax.plot3D(line[:, 0], line[:, 1], line[:, 2], 'blue')
# plot points
ax.scatter3D(m_pts_sampled[:, 0], m_pts_sampled[:, 1], m_pts_sampled[:, 2], s=100, c='red')
ax.scatter3D(m_pts_edges[:, 0], m_pts_edges[:, 1], m_pts_edges[:, 2], s=100, c='green')
plt.show()
def visualize_2d_pts(pts_2d):
fig = plt.figure()
ax = fig.add_subplot(111)
plt.scatter(pts_2d[:, 0], pts_2d[:, 1], marker='o');
ax.set_xlim([0, 1024])
ax.set_ylim([0, 768])
plt.show()
def visualize_3d_pts_img(pts_2d_edge, pts_2d_ctrl):
# Create a white image
img = np.ones((768, 1024, 3), np.float)
img = img * 255
# img = cv.imread('dataset_eval/0001.png')
# plot sedge points
for point in pts_2d_edge:
cv.circle(img, (int(point[0]), int(point[1])), 5, (0, 0, 255), -1)
# plot control points
for point in pts_2d_ctrl:
cv.circle(img, (int(point[0]), int(point[1])), 5, (255, 0, 0), -1)
# draw edges between edges
for i in range(8):
if (i + 1)%4 ==0:
cv.line(img, (int(pts_2d_edge[i,0]),int(pts_2d_edge[i,1])),
(int(pts_2d_edge[i-3,0]),int(pts_2d_edge[i-3,1])),
(0,255,0),2)
else:
cv.line(img, (int(pts_2d_edge[i, 0]), int(pts_2d_edge[i, 1])),
(int(pts_2d_edge[i+1, 0]), int(pts_2d_edge[i+1, 1])),
(0, 255, 0), 2)
for i in range(4):
cv.line(img, (int(pts_2d_edge[i, 0]), int(pts_2d_edge[i, 1])),
(int(pts_2d_edge[i +4, 0]), int(pts_2d_edge[i +4, 1])),
(0, 255, 0), 2)
cv.imshow('Object Projection', img)
cv.waitKey(0)
def visualize_2d_pts_img(img, img2, points_1, points_2, both=True):
# if (img == None):
# img = cv.cvtColor(img, cv.COLOR_GRAY2RGB)
# else:
# img = np.ones((768, 1024, 3), np.float)
# img = img * 255
img = cv.cvtColor(img, cv.COLOR_GRAY2RGB)
for point in points_1:
cv.circle(img, (int(point[0]), int(point[1])), 5, (0, 0, 255), -1)
cv.circle(img2, (int(point[0]), int(point[1])), 5, (0, 0, 255), -1)
if both:
for point in points_2:
cv.circle(img, (int(point[0]), int(point[1])), 5, (255, 0, 0), -1)
cv.circle(img2, (int(point[0]), int(point[1])), 5, (255, 0, 0), -1)
dashboard_img = cv.hconcat([img, img2])
scale_percent = 60 # percent of original size
width = int(dashboard_img.shape[1] * scale_percent / 100)
height = int(dashboard_img.shape[0] * scale_percent / 100)
dim = (width, height)
resized = cv.resize(dashboard_img, dim, interpolation=cv.INTER_AREA)
cv.imshow('Object Projection', resized)
cv.waitKey(0)