Skip to content

Commit

Permalink
Refactor: Don't use mayavi lib
Browse files Browse the repository at this point in the history
  • Loading branch information
maudzung committed Aug 25, 2020
1 parent c4c02b9 commit dd516ff
Showing 1 changed file with 1 addition and 100 deletions.
101 changes: 1 addition & 100 deletions src/utils/visualization_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import numpy as np
import cv2
import mayavi.mlab as mlab

sys.path.append('../')

Expand Down Expand Up @@ -117,108 +116,10 @@ def draw_box_3d(image, corners, color=(0, 0, 255)):
return image


def draw_lidar(lidar, is_grid=False, is_axis=True, is_top_region=True, fig=None):
pxs = lidar[:, 0]
pys = lidar[:, 1]
pzs = lidar[:, 2]
prs = lidar[:, 3]

if fig is None:
fig = mlab.figure(figure=None, bgcolor=(0, 0, 0), fgcolor=None, engine=None, size=(1000, 500))

mlab.points3d(
pxs, pys, pzs, prs,
mode='point', # 'point' 'sphere'
colormap='gnuplot', # 'bone', #'spectral', #'copper',
scale_factor=1,
figure=fig)

# draw grid
if is_grid:
mlab.points3d(0, 0, 0, color=(1, 1, 1), mode='sphere', scale_factor=0.2)

for y in np.arange(-50, 50, 1):
x1, y1, z1 = -50, y, 0
x2, y2, z2 = 50, y, 0
mlab.plot3d([x1, x2], [y1, y2], [z1, z2], color=(0.5, 0.5, 0.5), tube_radius=None, line_width=1, figure=fig)

for x in np.arange(-50, 50, 1):
x1, y1, z1 = x, -50, 0
x2, y2, z2 = x, 50, 0
mlab.plot3d([x1, x2], [y1, y2], [z1, z2], color=(0.5, 0.5, 0.5), tube_radius=None, line_width=1, figure=fig)

# draw axis
if is_grid:
mlab.points3d(0, 0, 0, color=(1, 1, 1), mode='sphere', scale_factor=0.2)

axes = np.array([
[2., 0., 0., 0.],
[0., 2., 0., 0.],
[0., 0., 2., 0.],
], dtype=np.float64)
fov = np.array([ ##<todo> : now is 45 deg. use actual setting later ...
[20., 20., 0., 0.],
[20., -20., 0., 0.],
], dtype=np.float64)

mlab.plot3d([0, axes[0, 0]], [0, axes[0, 1]], [0, axes[0, 2]], color=(1, 0, 0), tube_radius=None, figure=fig)
mlab.plot3d([0, axes[1, 0]], [0, axes[1, 1]], [0, axes[1, 2]], color=(0, 1, 0), tube_radius=None, figure=fig)
mlab.plot3d([0, axes[2, 0]], [0, axes[2, 1]], [0, axes[2, 2]], color=(0, 0, 1), tube_radius=None, figure=fig)
mlab.plot3d([0, fov[0, 0]], [0, fov[0, 1]], [0, fov[0, 2]], color=(1, 1, 1), tube_radius=None, line_width=1,
figure=fig)
mlab.plot3d([0, fov[1, 0]], [0, fov[1, 1]], [0, fov[1, 2]], color=(1, 1, 1), tube_radius=None, line_width=1,
figure=fig)

# draw top_image feature area
if is_top_region:
x1 = cnf.boundary['minX']
x2 = cnf.boundary['maxX']
y1 = cnf.boundary['minY']
y2 = cnf.boundary['maxY']
mlab.plot3d([x1, x1], [y1, y2], [0, 0], color=(0.5, 0.5, 0.5), tube_radius=None, line_width=1, figure=fig)
mlab.plot3d([x2, x2], [y1, y2], [0, 0], color=(0.5, 0.5, 0.5), tube_radius=None, line_width=1, figure=fig)
mlab.plot3d([x1, x2], [y1, y1], [0, 0], color=(0.5, 0.5, 0.5), tube_radius=None, line_width=1, figure=fig)
mlab.plot3d([x1, x2], [y2, y2], [0, 0], color=(0.5, 0.5, 0.5), tube_radius=None, line_width=1, figure=fig)

mlab.orientation_axes()
mlab.view(azimuth=180, elevation=None, distance=50,
focalpoint=[12.0909996, -1.04700089, -2.03249991]) # 2.0909996 , -1.04700089, -2.03249991

return fig


def draw_gt_boxes3d(gt_boxes3d, fig, cls_ids, line_width=2):
num = len(gt_boxes3d)
for n in range(num):
cls_id = int(cls_ids[n])
if cls_id < 0:
continue
color = cnf.colors[cls_id]
color = (color[0] / 255., color[1] / 255., color[2] / 255.)

b = gt_boxes3d[n]

for k in range(0, 4):
i, j = k, (k + 1) % 4
mlab.plot3d([b[i, 0], b[j, 0]], [b[i, 1], b[j, 1]], [b[i, 2], b[j, 2]], color=color, tube_radius=None,
line_width=line_width, figure=fig)

i, j = k + 4, (k + 3) % 4 + 4
mlab.plot3d([b[i, 0], b[j, 0]], [b[i, 1], b[j, 1]], [b[i, 2], b[j, 2]], color=color, tube_radius=None,
line_width=line_width, figure=fig)

i, j = k, k + 4
mlab.plot3d([b[i, 0], b[j, 0]], [b[i, 1], b[j, 1]], [b[i, 2], b[j, 2]], color=color, tube_radius=None,
line_width=line_width, figure=fig)

mlab.view(azimuth=180, elevation=None, distance=50,
focalpoint=[12.0909996, -1.04700089, -2.03249991]) # 2.0909996 , -1.04700089, -2.03249991


def show_rgb_image_with_boxes(img, labels, calib):
for box_idx, label in enumerate(labels):
cls_id, location, dim, ry = label[0], label[1:4], label[4:7], label[7]
if location[2] < 2.0: # The object is too close to the camera, ignore it during visualization
if location[2] < 2.0: # The object is too close to the camera, ignore it during visualization
continue
if cls_id < 0:
continue
Expand Down

0 comments on commit dd516ff

Please sign in to comment.