1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import json
- import numpy as np
- import open3d as o3d
- CUBOID_EXTENT_METERS = 200
- METERS_BELOW_START = 5
- METERS_ABOVE_START = 30
- def main():
- ## Point Cloud
- points = np.array([
- ## These points lie inside the cuboid
- [-2770.94365061042, 722.0595600050154, -20.004812609192445],
- [-2755.94365061042, 710.0595600050154, -20.004812609192445],
- [-2755.94365061042, 710.0595600050154, -15.004812609192445],
- ## These points lie outside the cuboid
- [-2755.94365061042 + CUBOID_EXTENT_METERS, 710.0595600050154, -15.004812609192445],
- [-2755.94365061042, 710.0595600050154 + CUBOID_EXTENT_METERS, -15.004812609192445],
- ]).reshape([-1, 3])
- point_cloud = o3d.geometry.PointCloud()
- point_cloud.points = o3d.utility.Vector3dVector(points)
- ## Start point here corresponds to an ego vehicle position start in a point cloud
- start_position = {'x': -2755.94365061042, 'y': 722.0595600050154, 'z': -20.004812609192445}
- cuboid_points = getCuboidPoints(start_position)
- points = o3d.utility.Vector3dVector(cuboid_points)
- oriented_bounding_box = o3d.geometry.OrientedBoundingBox.create_from_points(points)
- point_cloud_crop = point_cloud.crop(oriented_bounding_box)
- # View original point cloud with the cuboid, all 5 points present
- o3d.visualization.draw_geometries([point_cloud, oriented_bounding_box])
- # View cropped point cloud with the cuboid, only 3 points present
- o3d.visualization.draw_geometries([point_cloud_crop, oriented_bounding_box])
- def getCuboidPoints(start_position):
- return np.array([
- # Vertices Polygon1
- [start_position['x'] + (CUBOID_EXTENT_METERS / 2), start_position['y'] + (CUBOID_EXTENT_METERS / 2), start_position['z'] + METERS_ABOVE_START], # face-topright
- [start_position['x'] - (CUBOID_EXTENT_METERS / 2), start_position['y'] + (CUBOID_EXTENT_METERS / 2), start_position['z'] + METERS_ABOVE_START], # face-topleft
- [start_position['x'] - (CUBOID_EXTENT_METERS / 2), start_position['y'] - (CUBOID_EXTENT_METERS / 2), start_position['z'] + METERS_ABOVE_START], # rear-topleft
- [start_position['x'] + (CUBOID_EXTENT_METERS / 2), start_position['y'] - (CUBOID_EXTENT_METERS / 2), start_position['z'] + METERS_ABOVE_START], # rear-topright
- # Vertices Polygon 2
- [start_position['x'] + (CUBOID_EXTENT_METERS / 2), start_position['y'] + (CUBOID_EXTENT_METERS / 2), start_position['z'] - METERS_BELOW_START],
- [start_position['x'] - (CUBOID_EXTENT_METERS / 2), start_position['y'] + (CUBOID_EXTENT_METERS / 2), start_position['z'] - METERS_BELOW_START],
- [start_position['x'] - (CUBOID_EXTENT_METERS / 2), start_position['y'] - (CUBOID_EXTENT_METERS / 2), start_position['z'] - METERS_BELOW_START],
- [start_position['x'] + (CUBOID_EXTENT_METERS / 2), start_position['y'] - (CUBOID_EXTENT_METERS / 2), start_position['z'] - METERS_BELOW_START],
- ]).astype("float64")
- if __name__ == '__main__':
- main()
|