def test_object_to_world(self):
        sim = Simulator(gui=False, use_egl=False)
        scene = h5py.File('../data/scenes/200210_1654_manually_generated_scenes.hdf5')['scene'][0]
        sim.restore(scene, '../data/3d_models/shapenetsem40')
        sim.cam.pos = [0, 0, 1.5]
        sim.cam.width = 300
        sim.cam.height = 300

        cloud = sim.cam.point_cloud()

        cloud = ortho_pipeline.transform_world_to_camera(cloud, sim.cam)

        net = orthographic.OrthoNet(
            model_fn='/Users/mario/Developer/msc-thesis/data/networks/ggcnn_rss/epoch_29_model.hdf5')

        points, orientations, angles, widths, scores = net.predict(cloud, net.network_predictor,
                                                                   debug=False)
        best_idx = np.argmax(scores)

        p = points[best_idx]
        z = orientations[best_idx]
        x = angles[best_idx]
        w = widths[best_idx]
        y = np.cross(z, x)

        # Camera to world transformation
        p = ortho_pipeline.transform_camera_to_world(p, sim.cam)
        R = ortho_pipeline.get_camera_frame(sim.cam)
        z = R.dot(z.T).T
        x = R.dot(x.T).T

        recloud = ortho_pipeline.transform_camera_to_world(cloud, sim.cam)
        orthographic.render_pose(PointCloud(recloud), p, z, x, w)
Beispiel #2
0
 def test_visualize_wrt_camera(self):
     cloud = PointCloud(np.load('points.npy'))
     eye = np.eye(3)
     core.orthographic.render_frame([0, 0, 0],
                                    eye[0],
                                    eye[1],
                                    eye[2],
                                    cloud=cloud)
Beispiel #3
0
    def test_inverse_transform(self):
        cloud = PointCloud(np.load('object_cloud.npy'))

        pos = np.array([0, 0, 0])
        frame = np.eye(3)
        core.orthographic.render_frame(pos,
                                       frame[0],
                                       frame[1],
                                       frame[2],
                                       cloud=cloud)

        blue = np.array([[0, 0, 1]])
        colors = np.concatenate((np.ones(cloud.cloud.shape), blue))

        front = cloud.front_depth()
        right = cloud.right_depth()
        top = cloud.top_depth()

        points = np.concatenate((cloud.cloud, front.to_object(
            (21, 110)).reshape(1, 3)))
        viewer = pptk.viewer(points)
        viewer.attributes(colors)
        viewer.set(point_size=0.0005)

        points = np.concatenate((cloud.cloud, right.to_object(
            (21, 110)).reshape(1, 3)))
        viewer = pptk.viewer(points)
        viewer.attributes(colors)
        viewer.set(point_size=0.0005)

        points = np.concatenate((cloud.cloud, top.to_object(
            (191, 198)).reshape(1, 3)))
        viewer = pptk.viewer(points)
        viewer.attributes(colors)
        viewer.set(point_size=0.0005)

        plt.subplot(131)
        plt.imshow(front.img)
        plt.scatter([110], [21])
        plt.subplot(132)
        plt.imshow(right.img)
        plt.scatter([110], [21])
        plt.subplot(133)
        plt.imshow(top.img)
        plt.scatter([198], [191])
        plt.show()
Beispiel #4
0
 def test_rotate_points_to_sensible_orientation(self):
     cloud = PointCloud.from_npy('points.npy')
     plane_cloud = cloud.find_plane(th=0.02)
     plane_cloud.pca()
     cloud.cloud = plane_cloud.transform(cloud.cloud)
     cloud.cloud[:, 0] += 0.7
     rotated = cloud.rotate([0, 1, 0], np.radians(-45))
     rotated.save('isolated_cloud.npy')
Beispiel #5
0
    def test_orthographic_projection(self):
        cloud = PointCloud(self.pcd)
        front, side, top, pca = cloud.orthographic_projection()

        ax = self.render_pcd(self.pcd)
        ax = self.render_frame(ax, pca.mean_, pca.components_)

        plt.figure()
        plt.subplot(1, 3, 1)
        plt.scatter(front[:, 0], front[:, 1])
        plt.title('Front')
        plt.subplot(1, 3, 2)
        plt.scatter(side[:, 0], side[:, 1])
        plt.title('Side')
        plt.subplot(1, 3, 3)
        plt.scatter(top[:, 0], top[:, 1])
        plt.title('Top')
        plt.show()
Beispiel #6
0
    def test_to_depth(self):

        cloud = PointCloud(np.load('object_cloud.npy'))

        pos = np.array([0, 0, 0])
        frame = np.eye(3)
        core.orthographic.render_frame(pos,
                                       frame[0],
                                       frame[1],
                                       frame[2],
                                       cloud=cloud)

        front, right, top = cloud.orthographic_depth()
        plt.subplot(131)
        plt.imshow(front.img)
        plt.subplot(132)
        plt.imshow(right.img)
        plt.subplot(133)
        plt.imshow(top.img)
        plt.colorbar()
        plt.show()
Beispiel #7
0
    def test_full_pipeline(self):
        cloud = PointCloud.from_file('pcd0116.txt')
        # cloud.filter_roi([-np.inf, np.inf, -np.inf, np.inf, 0, 500])
        cloud.filter_roi([0, 1400, -np.inf, np.inf, 0, 500])
        cloud.remove_plane()

        cloud.render()

        cloud.pca()
        plt.subplot(1, 3, 1)
        plt.imshow(cloud.to_depth(index=0))
        plt.subplot(1, 3, 2)
        plt.imshow(cloud.to_depth(index=1))
        plt.subplot(1, 3, 3)
        plt.imshow(cloud.to_depth(index=2))
        plt.show()
    def test_transform_world_to_camera(self):
        sim = Simulator(use_egl=False)
        scenes_ds = h5py.File('../data/scenes/shapenetsem40_5.hdf5', 'r')
        scene = scenes_ds['scene'][np.random.randint(len(scenes_ds['scene'][:]))]
        sim.restore(scene, os.environ['MODELS_PATH'])

        sim.cam.pos = [1, 1, 1.5]
        sim.cam.width = 600
        sim.cam.height = 600

        cloud = sim.cam.point_cloud()
        print 'cloud was generated'

        cloud = ortho_pipeline.transform_world_to_camera(cloud, sim.cam)

        eye = np.eye(3)
        orthographic.render_frame([0, 0, 0], eye[0], eye[1], eye[2], cloud=PointCloud(cloud))
Beispiel #9
0
 def test_rotate(self):
     pcd = np.load('isolated_cloud.npy')
     cloud = PointCloud(pcd)
     rotated = cloud.rotate([0, 1, 0], np.radians(45))
     rotated.render()
Beispiel #10
0
 def test_render(self):
     pcd = np.load('points.npy')
     cloud = PointCloud(pcd)
     cloud.render()
     cloud.render(use_pptk=False, subsample=0.01)
Beispiel #11
0
 def test_find_plane(self):
     pcd = np.load('points.npy')
     cloud = PointCloud(pcd)
     mean, normal = cloud.find_plane()
Beispiel #12
0
 def test_filter_and_ransac(self):
     cloud = PointCloud.from_file('pcd0116.txt')
     cloud.filter_roi([0, 1400, -np.inf, np.inf, 0, 500])
     cloud.remove_plane()
     cloud.render()
Beispiel #13
0
 def test_filter_roi(self):
     cloud = PointCloud(self.pcd)
     cloud.filter_roi([-0.5, 0.5] * 3)
     self.render_pcd(cloud.cloud)
     plt.show()
Beispiel #14
0
 def test_from_file(self):
     cloud = PointCloud.from_file('pcd0116.txt')
     cloud.render()
Beispiel #15
0
 def test_remove_plane(self):
     cloud = PointCloud(self.pcd)
     self.render_pcd(self.pcd)
     cloud.remove_plane()
     self.render_pcd(cloud.cloud)
     plt.show()