Beispiel #1
0
def draw_bbox_open3d(cloud_points_array):
    cloud = geometry.PointCloud()
    cloud.points = utility.Vector3dVector(np.asarray(cloud_points_array))
    minBound = cloud.get_min_bound()
    maxBound = cloud.get_max_bound()

    box_center = np.array([
        maxBound[0] - minBound[0], maxBound[1] - minBound[1],
        maxBound[2] - minBound[2]
    ])
    points = [[minBound[0], maxBound[1], minBound[2]],
              [maxBound[0], maxBound[1], minBound[2]],
              [maxBound[0], minBound[1], minBound[2]],
              [minBound[0], minBound[1], minBound[2]],
              [minBound[0], minBound[1], maxBound[2]],
              [maxBound[0], minBound[1], maxBound[2]],
              [maxBound[0], maxBound[1], maxBound[2]],
              [minBound[0], maxBound[1], maxBound[2]], [0, 0, 0],
              [box_center[0], box_center[1], box_center[2]]]
    lines = [[0, 1], [1, 2], [2, 3], [0, 3], [0, 7], [1, 6], [2, 5], [3, 4],
             [4, 5], [4, 7], [5, 6], [6, 7]]

    colors = [[0, 255, 0] for i in range(0, len(lines))]
    line_set = geometry.LineSet()
    line_set.points = utility.Vector3dVector(points)
    line_set.lines = utility.Vector2iVector(lines)
    line_set.colors = utility.Vector3dVector(colors)
    return line_set
Beispiel #2
0
 def load_point_cloud(self, normalize=False):
     """ Method used for reading the off file that holds the pcd points and populate the point_cloud and normal points inside this object."""
     try:
         try:
             file_extension = (str(self.path).rsplit("\\", 1)[1]).rsplit(".", 1)[1]
         except Exception as e:
             print('Exception at path split.', e)
         if file_extension == "off" or file_extension == "OFF":
                 if normalize:
                     points_array, normals_array = read_off_file(self.path)
                     normalized_points = normalize_cloud(points_array)
                     self.point_cloud.points = utility.Vector3dVector(normalized_points)
                 else:
                     points_array, normals_array = read_off_file(self.path)
                     self.point_cloud.points = utility.Vector3dVector(points_array)
         elif file_extension == 'pcd':
             io.read_point_cloud(self.path, self.point_cloud)
         elif file_extension == 'ply':
             self.mesh = io.read_triangle_mesh(self.path)
             self.point_cloud.points = utility.Vector3dVector(self.mesh.vertices)
     except Exception as e:
         print('Exception at reading off file.', e)
Beispiel #3
0
    def translate_to_origin(self, point=None):
        """
            Translates object into origin, based on its centroid
        :return: [out] Sets the point cloud translated into origin.
        """
        assert len(self.point_cloud.points) > 0
        if point is None:
            centroid = compute_centroid(self.point_cloud.points)
            translated_points = translate_point_cloud(self.point_cloud.points, centroid, action="translate")
        else:
            translated_points = translate_point_cloud(self.point_cloud.xyz, [0, 0, 0], action="translate")

        self.point_cloud.points = utility.Vector3dVector(translated_points)
def delaunay_triangulation(points_array):
    import numpy as np
    from scipy.spatial import Delaunay
    from open3d.open3d import geometry, utility

    u = [point[0] for point in points_array]
    v = [point[1] for point in points_array]

    tri = Delaunay(np.array([u, v]).T)
    mesh = geometry.TriangleMesh()
    mesh.vertices = utility.Vector3dVector(points_array)
    mesh.triangles = utility.Vector3iVector(tri.simplices)

    mesh.remove_duplicated_triangles()
    mesh.remove_degenerate_triangles()

    return mesh
Beispiel #5
0
 def __init__(self, points):
     self.point_cloud = geometry.PointCloud()
     self.point_cloud.points = utility.Vector3dVector(points)
     self.cloud_down = geometry.PointCloud()
     self.cloud_fpfh = registration.RegistrationResult()
     self.centroid = []
Beispiel #6
0
    # DECLARING OBJECTS
    source_primitive_cloud_path = PATHS.PATH_TO_PRIMITIVES.CAR.root + "CarPrimitive_15_500.off"
    srcPrimitive = IoPrimitive(source_primitive_cloud_path)
    srcPrimitive.load_primitive()
    srcPrimitive.compute_normals(30)
    srcPrimitive.point_cloud.normalize_normals()
    srcPrimitive.point_cloud.paint_uniform_color([1, 0, 0])

    frame = 8  # sample id from kitti dataset
    final_clouds = []
    lidar, labels = load_cloud_and_labels(frame)
    img_dir = str(PATHS.KITTI.IMG_ROOT + '%06d.png' % frame)
    pc_dir = str(PATHS.KITTI.PC_ROOT + '%06d.bin' % frame)
    calib_dir = str(PATHS.KITTI.CALIB_ROOT + '%06d.txt' % frame)
    full_cloud_points = align_img_and_pc(img_dir, pc_dir, calib_dir)
    full_cloud.points = utility.Vector3dVector(
        np.array(full_cloud_points[:, 0:3]))
    full_cloud.colors = utility.Vector3dVector(
        [[0, 0, 0] for i in range(0, len(full_cloud.points))])
    # keep original labels, and work on original labels
    lab_cnt = 0
    for line in labels:
        # Clear cloud to be repopulated
        values = line.split(' ')
        lab_cnt += 1
        [
            cls, obj_lv_image, occl_state, obs_angl, bb_l, bb_t, bb_r, bb_d, h,
            w, l, y, z, x, rot
        ] = values
        x = float(x)
        y = float(y)
        z = float(z)