Skip to content

Commit

Permalink
Updated Read Me & Changed Convert Voxel location
Browse files Browse the repository at this point in the history
  • Loading branch information
ErenBalatkan committed Feb 14, 2020
1 parent 836d8c8 commit ffb3e6d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 29 deletions.
57 changes: 29 additions & 28 deletions DepthVisualizer/DepthVisualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,35 @@ def convert_objects_to_kitti_format(objects):

return converted_objects

@staticmethod
def convert_points_to_voxel_map(points, voxel_map_center, voxel_map_size, voxel_size):
'''
Converts points that are inside specified 3D box into voxels
:param points: List of points where each point has following format [x, y, z, r, g, b]
:param voxel_map_center: Center coordinates of the area that will be voxellized in format [x, y, z]
:param voxel_map_size: Size of the area that will be voxellized in format [width, height, length]
:param voxel_size: Size of the each voxel
:return: A 3D array in x-y-z format where each element is list of size 3 that represents color
'''

voxel_map_size = np.asarray(np.ceil(np.array(voxel_map_size) / voxel_size), np.int32)
center_x, center_y, center_z = voxel_map_center

x_begin, x_end = [center_x + sign * 0.5 * voxel_map_size[0] * voxel_size for sign in [-1, 1]]
y_begin, y_end = [center_y + sign * 0.5 * voxel_map_size[1] * voxel_size for sign in [-1, 1]]
z_begin, z_end = [center_z + sign * 0.5 * voxel_map_size[2] * voxel_size for sign in [-1, 1]]

voxel_map = np.zeros(shape=(*voxel_map_size, 4))
for point in points:
x, y, z, r, g, b = point

if x_begin < x < x_end and y_begin < y < y_end and z_begin < z < z_end:
voxel_map[math.floor((x - x_begin) / voxel_size), math.floor((y - y_begin) / voxel_size),
math.floor((z - z_begin) / voxel_size)] += [r, g, b, 1]

voxel_map = voxel_map[:, :, :, :3] / np.expand_dims(np.clip(voxel_map[:, :, :, 3], 1, None), axis=3)
return voxel_map

@staticmethod
def read_kitti_3d_object(path, convert_format=True):
'''
Expand Down Expand Up @@ -806,34 +835,6 @@ def add_voxel_map(self, voxel_map, voxel_map_center, voxel_size, filter_black_vo

self.add_voxels(voxel_data.flatten())

def convert_points_to_voxel_map(self, points, voxel_map_center, voxel_map_size, voxel_size):
'''
Converts points that are inside specified 3D box into voxels
:param points: List of points where each point has following format [x, y, z, r, g, b]
:param voxel_map_center: Center coordinates of the area that will be voxellized in format [x, y, z]
:param voxel_map_size: Size of the area that will be voxellized in format [width, height, length]
:param voxel_size: Size of the each voxel
:return: A 3D array in x-y-z format where each element is list of size 3 that represents color
'''

voxel_map_size = np.asarray(np.ceil(np.array(voxel_map_size) / voxel_size), np.int32)
center_x, center_y, center_z = voxel_map_center

x_begin, x_end = [center_x + sign * 0.5 * voxel_map_size[0] * voxel_size for sign in [-1, 1]]
y_begin, y_end = [center_y + sign * 0.5 * voxel_map_size[1] * voxel_size for sign in [-1, 1]]
z_begin, z_end = [center_z + sign * 0.5 * voxel_map_size[2] * voxel_size for sign in [-1, 1]]

voxel_map = np.zeros(shape=(*voxel_map_size, 4))
for point in points:
x, y, z, r, g, b = point

if x_begin < x < x_end and y_begin < y < y_end and z_begin < z < z_end:
voxel_map[math.floor((x - x_begin) / voxel_size), math.floor((y - y_begin) / voxel_size),
math.floor((z - z_begin) / voxel_size)] += [r, g, b, 1]

voxel_map = voxel_map[:, :, :, :3] / np.expand_dims(np.clip(voxel_map[:, :, :, 3], 1, None), axis=3)
return voxel_map

def render(self, enable_controls=False):
'''
Renders existing points, lines and voxels to frame
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,22 @@ pip install DepthVisualizer
Please refer to following repository for usage examples
https://github.com/Navhkrin/DepthVisualizer-Examples

#### Keyboard Controls
| Key | Action |
|:-------------:|:-------------:|
| W | Move Forward |
| A | Move Left |
| S | Move Right |
| D | Move Back |
| Left-Shift | Move Up (+z) |
| Left-Control | Move Down (-z) |
| Arrow Up | Turn Up |
| Arrow Left | Turn Left |
| Arrow Right | Turn Right |
| Arrow Down | Turn Down |
| 1 | Enable Point Rendering |
| 2 | Disable Point Rendering |
| 3 | Enable Line Rendering |
| 4 | Disable Line Rendering |
| 5 | Enable Voxel Rendering |
| 6 | Disable Voxel Rendering |
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
setup(
name="DepthVisualizer",
packages=["DepthVisualizer"],
version='0.13',
version='0.14',
license="MIT",
description="Point Cloud & Depth Map visualization library",
author="Eren Balatkan",
Expand Down

0 comments on commit ffb3e6d

Please sign in to comment.