Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visiallization problem #68

Closed
Steven0928 opened this issue Jul 16, 2023 · 9 comments
Closed

Visiallization problem #68

Steven0928 opened this issue Jul 16, 2023 · 9 comments

Comments

@Steven0928
Copy link

python monoscene/scripts/visualization/kitti_vis_pred.py +file=/home/robotlab/reserch/Kittirelated/shared_dir/OccDepth-main/output/kitti/08/000000.pkl +dataset=kitti
Traceback (most recent call last):
  File "/home/robotlab/anaconda3/envs/occdepth/lib/python3.7/site-packages/importlib_metadata/__init__.py", line 292, in __getitem__
    return next(iter(self.select(name=name)))
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "monoscene/scripts/visualization/kitti_vis_pred.py", line 6, in <module>
    from mayavi import mlab
  File "/home/robotlab/anaconda3/envs/occdepth/lib/python3.7/site-packages/mayavi/mlab.py", line 15, in <module>
    from mayavi.core.common import process_ui_events
  File "/home/robotlab/anaconda3/envs/occdepth/lib/python3.7/site-packages/mayavi/core/common.py", line 21, in <module>
    from pyface import api as pyface
  File "/home/robotlab/anaconda3/envs/occdepth/lib/python3.7/site-packages/pyface/api.py", line 13, in <module>
    from .about_dialog import AboutDialog
  File "/home/robotlab/anaconda3/envs/occdepth/lib/python3.7/site-packages/pyface/about_dialog.py", line 15, in <module>
    from .toolkit import toolkit_object
  File "/home/robotlab/anaconda3/envs/occdepth/lib/python3.7/site-packages/pyface/toolkit.py", line 23, in <module>
    toolkit = toolkit_object = find_toolkit("pyface.toolkits")
  File "/home/robotlab/anaconda3/envs/occdepth/lib/python3.7/site-packages/pyface/base_toolkit.py", line 282, in find_toolkit
    return import_toolkit(ETSConfig.toolkit, entry_point)
  File "/home/robotlab/anaconda3/envs/occdepth/lib/python3.7/site-packages/pyface/base_toolkit.py", line 216, in import_toolkit
    entry_point_group = importlib_metadata.entry_points()[entry_point]
  File "/home/robotlab/anaconda3/envs/occdepth/lib/python3.7/site-packages/importlib_metadata/__init__.py", line 294, in __getitem__
    raise KeyError(name)
KeyError: 'pyface.toolkits'

Is it a Qt problem?
How can I solve it ?
Thanks a lot

@anhquancao
Copy link
Collaborator

anhquancao commented Jul 17, 2023

Hi @Steven0928,
Seems like mayavi error. Did you follow this to install mayavi?

@Steven0928
Copy link
Author

Sure I did , but it still reporting error like I mentioned above. :(

@anhquancao
Copy link
Collaborator

anhquancao commented Jul 17, 2023

I think you can use Open3D instead. It is simpler and less error to install. Here is the code I use:

import open3d as o3d

def get_grid_coords(dims, resolution):
  '''
  :param dims: the dimensions of the grid [x, y, z] (i.e. [256, 256, 32])
  :return coords_grid: is the center coords of voxels in the grid
  '''

  # The sensor in centered in X (we go to dims/2 + 1 for the histogramdd)
  g_xx = np.arange(0, dims[0] + 1)
  # The sensor is in Y=0 (we go to dims + 1 for the histogramdd)
  g_yy = np.arange(0, dims[1] + 1)
  # The sensor is in Z=1.73. I observed that the ground was to voxel levels above the grid bottom, so Z pose is at 10
  # if bottom voxel is 0. If we want the sensor to be at (0, 0, 0), then the bottom in z is -10, top is 22
  # (we go to 22 + 1 for the histogramdd)
  # ATTENTION.. Is 11 for old grids.. 10 for new grids (v1.1) (https://github.com/PRBonn/semantic-kitti-api/issues/49)
  sensor_pose = 10
  g_zz = np.arange(0, dims[2] + 1)

  # Obtaining the grid with coords...
  xx, yy, zz = np.meshgrid(g_xx[:-1], g_yy[:-1], g_zz[:-1])

  coords_grid = np.array([xx.flatten(), yy.flatten(), zz.flatten()]).T
  coords_grid = coords_grid.astype(np.float)

  coords_grid = (coords_grid * resolution) + resolution/2

  temp = np.copy(coords_grid)
  temp[:, 0] = coords_grid[:, 1]
  temp[:, 1] = coords_grid[:, 0]
  coords_grid = np.copy(temp)

  return coords_grid, g_xx, g_yy, g_zz

def draw_semantic_open3d(
    voxels,
    cam_param_path="",
    voxel_size=0.2):    

    colors = np.array([
        [0  , 0  , 0, 255],
        [100, 150, 245, 255],
        [100, 230, 245, 255],
        [30, 60, 150, 255],
        [80, 30, 180, 255],
        [100, 80, 250, 255],
        [255, 30, 30, 255],
        [255, 40, 200, 255],
        [150, 30, 90, 255],
        [255, 0, 255, 255],
        [255, 150, 255, 255],
        [75, 0, 75, 255],
        [175, 0, 75, 255],
        [255, 200, 0, 255],
        [255, 120, 50, 255],
        [0, 175, 0, 255],
        [135, 60, 0, 255],
        [150, 240, 80, 255],
        [255, 240, 150, 255],
        [255, 0, 0, 255]]) / 255.0


    grid_coords, _, _, _ = get_grid_coords([voxels.shape[0], voxels.shape[1], voxels.shape[2]], voxel_size)    

    points = np.vstack([grid_coords.T, voxels.reshape(-1)]).T

    # Obtaining voxels with semantic class
    points = points[(points[:, 3] != 0) & (points[:, 3] != 255)] # remove empty voxel and unknown class

    colors = np.take_along_axis(colors, points[:, 3].astype(np.int32).reshape(-1, 1), axis=0)
    
    vis = o3d.visualization.Visualizer()
    vis.create_window(width=1200, height=600)
    ctr = vis.get_view_control()
    param = o3d.io.read_pinhole_camera_parameters(cam_param_path)

    pcd = o3d.geometry.PointCloud()
    pcd.points = o3d.utility.Vector3dVector(points[:, :3])
    pcd.colors = o3d.utility.Vector3dVector(colors[:, :3])
    pcd.estimate_normals()
    vis.add_geometry(pcd)

    ctr.convert_from_pinhole_camera_parameters(param)

    vis.run()  # user changes the view and press "q" to terminate
    param = vis.get_view_control().convert_to_pinhole_camera_parameters()
    o3d.io.write_pinhole_camera_parameters(cam_param_path, param)

@Steven0928
Copy link
Author

Thanks!
It works!
截图 2023-07-17 16-58-32

@anhquancao
Copy link
Collaborator

Perfect!

@AniketDhar
Copy link

What is the "cam_param_path" for Kitti-360 dataset?

@anhquancao
Copy link
Collaborator

Hi @AniketDhar, I don't remember how did I got the params but I set them directly in the code.

@AniketDhar
Copy link

Hi @AniketDhar, I don't remember how did I got the params but I set them directly in the code.

Thanks for the quick response. I saw a filepath, so I expected there might be a json file that I am missing somewhere. But just to be clear, for the Open3D visualizer, you set the camera parameters into a file and load that to o3d.io.read_pinhole_camera_parameters(cam_param_path). Is that correct?

@anhquancao
Copy link
Collaborator

anhquancao commented Aug 16, 2023

ah I understand what you mean. You can provide an arbitrary filepath, if the file is not exist, a camera parameter config file will be saved there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants