Exemple #1
0
    def get_new_images(self):
        # Construct the Images State Vector
        # Order is Front Center, Front Right, Front Left
        tic = time.time()
        self.client.simPause(True)
        if (self.image_mask_FC_FR_FL[0] and self.image_mask_FC_FR_FL[1]
                and self.image_mask_FC_FR_FL[2]):
            images = self.client.simGetImages([
                client.ImageRequest("0", client.ImageType.Scene, False,
                                    False),  # Front Center
                client.ImageRequest("1", client.ImageType.Scene, False,
                                    False),  # Front Right
                client.ImageRequest("2", client.ImageType.Scene, False, False)
            ])  # Front Left
            img1d_FC = np.fromstring(images[0].image_data_uint8,
                                     dtype=np.uint8)
            img_rgba_FC = np.array(img1d_FC.reshape(images[0].height,
                                                    images[0].width, 4),
                                   dtype=np.uint8)
            img_rgb_FC = img_rgba_FC[:, :, 0:3]

            img1d_FR = np.fromstring(images[1].image_data_uint8,
                                     dtype=np.uint8)
            img_rgba_FR = np.array(img1d_FR.reshape(images[1].height,
                                                    images[1].width, 4),
                                   dtype=np.uint8)
            img_rgb_FR = img_rgba_FR[:, :, 0:3]

            img1d_FL = np.fromstring(images[2].image_data_uint8,
                                     dtype=np.uint8)
            img_rgba_FL = np.array(img1d_FL.reshape(images[2].height,
                                                    images[2].width, 4),
                                   dtype=np.uint8)
            img_rgb_FL = img_rgba_FL[:, :, 0:3]

            # Can either use the RGBA images or the RGB Images
            self.images_rgba = np.dstack(
                (img_rgba_FC, img_rgba_FR, img_rgba_FL))
            self.images_rgb = np.dstack((img_rgb_FC, img_rgb_FR, img_rgb_FL))
            self.time_to_grab_images = time.time() - tic

        # We Just want front view
        elif (self.image_mask_FC_FR_FL[0] and not self.image_mask_FC_FR_FL[1]
              and not self.image_mask_FC_FR_FL[2]):
            images = self.client.simGetImages([
                client.ImageRequest("0", client.ImageType.Scene, False, False)
            ])  # Front Center
            img1d_FC = np.fromstring(images[0].image_data_uint8,
                                     dtype=np.uint8)
            img_rgba_FC = np.array(img1d_FC.reshape(images[0].height,
                                                    images[0].width, 4),
                                   dtype=np.uint8)
            img_rgb_FC = img_rgba_FC[:, :, 0:3]
            self.images_rgba = img_rgba_FC
            self.images_rgb = img_rgb_FC
            self.time_to_grab_images = time.time() - tic
        self.client.simPause(False)
Exemple #2
0
 def retrieval_3d(self, client, camera_name, img_arg1=True, img_arg2=False):
     images = client.simGetImages([
         client.ImageRequest(camera_name, client.ImageType.Scene, img_arg1,
                             img_arg2)
     ])  # Front Center
     img = np.fromstring(images[0].image_data_uint8, dtype=np.uint8)
     img = np.array(img.reshape(images[0].height, images[0].width, 3),
                    dtype=np.uint8)
     return img
    def get_new_images(self, vehicleName):
        # Wait to grad images
        tic = time.time()
        print("Collecting Images from AirSim")
        if (self.image_mask_FC_FR_FL[0] and self.image_mask_FC_FR_FL[1]
                and self.image_mask_FC_FR_FL[2]):
            images = self.client.simGetImages(
                [
                    client.ImageRequest("0", client.ImageType.Scene, False,
                                        False),  # Front Center
                    client.ImageRequest("1", client.ImageType.Scene, False,
                                        False),  # Front Right
                    client.ImageRequest("2", client.ImageType.Scene, False,
                                        False)
                ],
                vehicle_name=vehicleName)  # Front Left
            img1d_FC = np.fromstring(images[0].image_data_uint8,
                                     dtype=np.uint8)
            img_rgba_FC = np.array(img1d_FC.reshape(images[0].height,
                                                    images[0].width, 4),
                                   dtype=np.uint8)
            img_rgb_FC = img_rgba_FC[:, :, 0:3]

            img1d_FR = np.fromstring(images[1].image_data_uint8,
                                     dtype=np.uint8)
            img_rgba_FR = np.array(img1d_FR.reshape(images[1].height,
                                                    images[1].width, 4),
                                   dtype=np.uint8)
            img_rgb_FR = img_rgba_FR[:, :, 0:3]

            img1d_FL = np.fromstring(images[2].image_data_uint8,
                                     dtype=np.uint8)
            img_rgba_FL = np.array(img1d_FL.reshape(images[2].height,
                                                    images[2].width, 4),
                                   dtype=np.uint8)
            img_rgb_FL = img_rgba_FL[:, :, 0:3]

            # Can either use the RGBA images or the RGB Images

            self.images_rgba[vehicleName] = np.dstack(
                (img_rgba_FC, img_rgba_FR, img_rgba_FL))
            self.images_rgb[vehicleName] = np.dstack(
                (img_rgb_FC, img_rgb_FR, img_rgb_FL))
            print('Images Collected!')
            print("Time to Grab Images: ", time.time() - tic)

        # We Just want front
        elif (self.image_mask_FC_FR_FL[0] and not self.image_mask_FC_FR_FL[1]
              and not self.image_mask_FC_FR_FL[2]):
            images = self.client.simGetImages([
                client.ImageRequest("0", client.ImageType.Scene, False, False)
            ],
                                              vehicle_name=vehicleName)
            img1d_FC = np.fromstring(images[0].image_data_uint8,
                                     dtype=np.uint8)
            img_rgba_FC = np.array(img1d_FC.reshape(images[0].height,
                                                    images[0].width, 4),
                                   dtype=np.uint8)
            img_rgb_FC = img_rgba_FC[:, :, 0:3]
            self.images_rgba[vehicleName] = img_rgba_FC
            self.images_rgb[vehicleName] = img_rgb_FC
            print('Images Collected!')
            print("Time to Grab Images: ", time.time() - tic)

        else:
            print("A screw up in set new images")
Exemple #4
0
    def pset_simulator_state_info(self):
        # This function will set the latest simulator information within the class
        # The State's components will be
        self.client.simPause(True)
        # Get Base Inertial States

        # Collect and Display Elapsed Time Between States
        self.toc = time.time()
        self.dt = self.toc - self.tic
        for vn in self.vehicle_names:
            state = self.client.simGetGroundTruthKinematics(vehicle_name=vn)
            pos = (state['position']['x_val'], state['position']['y_val'],
                   state['position']['z_val'])
            vel = (state['linear_velocity']['x_val'],
                   state['linear_velocity']['y_val'],
                   state['linear_velocity']['z_val'])
            acc = (state['linear_acceleration']['x_val'],
                   state['linear_acceleration']['y_val'],
                   state['linear_acceleration']['z_val'])
            angVel = (state['angular_velocity']['x_val'],
                      state['angular_velocity']['y_val'],
                      state['angular_velocity']['z_val'])
            angAcc = (state['angular_acceleration']['x_val'],
                      state['angular_acceleration']['y_val'],
                      state['angular_acceleration']['z_val'])

            # Store the current state
            self.current_inertial_states[vn] = np.array([
                pos[0] - self.initial_position[vn][0],
                pos[1] - self.initial_position[vn][1],
                pos[2] - self.initial_position[vn][2],
                vel[0] - self.initial_velocity[vn][0],
                vel[1] - self.initial_velocity[vn][1],
                vel[2] - self.initial_velocity[vn][2], acc[0], acc[1], acc[2],
                angVel[0], angVel[1], angVel[2], angAcc[0], angAcc[1],
                angAcc[2]
            ])

        # Posx, Posy, PosZ, Vx, Vy, Vz, Ax, Ay, Az, AngVelx, AngVely, AngVelz, AngAccx, AngAccy, AngAccz

        # Construct the Images State Vector
        # Order is Front Center, Front Right, Front Left
        for vn in self.vehicle_names:
            if (self.image_mask_FC_FR_FL[0] and self.image_mask_FC_FR_FL[1]
                    and self.image_mask_FC_FR_FL[2]):
                images = self.client.simGetImages(
                    [
                        client.ImageRequest("0", client.ImageType.Scene, False,
                                            False),  # Front Center
                        client.ImageRequest("1", client.ImageType.Scene, False,
                                            False),  # Front Right
                        client.ImageRequest("2", client.ImageType.Scene, False,
                                            False)
                    ],
                    vehicle_name=vn)  # Front Left
                img1d_FC = np.fromstring(images[0].image_data_uint8,
                                         dtype=np.uint8)
                img_rgba_FC = np.array(img1d_FC.reshape(
                    images[0].height, images[0].width, 4),
                                       dtype=np.uint8)
                img_rgb_FC = img_rgba_FC[:, :, 0:3]

                img1d_FR = np.fromstring(images[1].image_data_uint8,
                                         dtype=np.uint8)
                img_rgba_FR = np.array(img1d_FR.reshape(
                    images[1].height, images[1].width, 4),
                                       dtype=np.uint8)
                img_rgb_FR = img_rgba_FR[:, :, 0:3]

                #plt.imshow(img_rgb_FR)
                #plt.show()
                #time.sleep(2)

                img1d_FL = np.fromstring(images[2].image_data_uint8,
                                         dtype=np.uint8)
                img_rgba_FL = np.array(img1d_FL.reshape(
                    images[2].height, images[2].width, 4),
                                       dtype=np.uint8)
                img_rgb_FL = img_rgba_FL[:, :, 0:3]

                #plt.imshow(img_rgb_FL)
                #plt.show()
                #time.sleep(2)

                # Can either use the RGBA images or the RGB Images
                self.images_rgba[vn] = np.dstack(
                    (img_rgba_FC, img_rgba_FR, img_rgba_FL))
                self.images_rgb[vn] = np.dstack(
                    (img_rgb_FC, img_rgb_FR, img_rgb_FL))
                print("Time to Grab All Images: ", time.time() - self.toc)

            # We Just want front view
            elif (self.image_mask_FC_FR_FL[0]
                  and not self.image_mask_FC_FR_FL[1]
                  and not self.image_mask_FC_FR_FL[2]):
                images = self.client.simGetImages(
                    [
                        client.ImageRequest("0", client.ImageType.Scene, False,
                                            False)
                    ],
                    vehicle_name=vn)  # Front Center
                img1d_FC = np.fromstring(images[0].image_data_uint8,
                                         dtype=np.uint8)
                img_rgba_FC = np.array(img1d_FC.reshape(
                    images[0].height, images[0].width, 4),
                                       dtype=np.uint8)
                img_rgb_FC = img_rgba_FC[:, :, 0:3]

                self.images_rgba[vn] = img_rgba_FC
                self.images_rgb[vn] = img_rgb_FC
                print("Time to Grab Images: ", time.time() - self.toc)

        self.client.simPause(False)
        # Store X and Y position information as well
        self.extra_metadata = self.dt
        # Start the timer again as the next state is saved. Return the current state and meta-data
        self.tic = time.time()
Exemple #5
0
    def get_new_images(self):
        # Wait to grad images
        tic = time.time()
        if (self.image_mask_FC_FR_FL[0] and self.image_mask_FC_FR_FL[1]
                and self.image_mask_FC_FR_FL[2]):

            images = self.client.simGetImages([
                client.ImageRequest("0", client.ImageType.Scene, False,
                                    False),  # Front Center
                client.ImageRequest("1", client.ImageType.Scene, False,
                                    False),  # Front Right
                client.ImageRequest("2", client.ImageType.Scene, False, False)
            ])  # Front Left
            img1d_FC = np.fromstring(images[0].image_data_uint8,
                                     dtype=np.uint8)
            img_rgba_FC = np.array(img1d_FC.reshape(images[0].height,
                                                    images[0].width, 4),
                                   dtype=np.uint8)
            img_rgb_FC = img_rgba_FC[:, :, 0:3]

            img1d_FR = np.fromstring(images[1].image_data_uint8,
                                     dtype=np.uint8)
            img_rgba_FR = np.array(img1d_FR.reshape(images[1].height,
                                                    images[1].width, 4),
                                   dtype=np.uint8)
            img_rgb_FR = img_rgba_FR[:, :, 0:3]

            img1d_FL = np.fromstring(images[2].image_data_uint8,
                                     dtype=np.uint8)
            img_rgba_FL = np.array(img1d_FL.reshape(images[2].height,
                                                    images[2].width, 4),
                                   dtype=np.uint8)
            img_rgb_FL = img_rgba_FL[:, :, 0:3]

            # Can either use the RGBA images or the RGB Images

            self.images_rgba = np.dstack(
                (img_rgba_FC, img_rgba_FR, img_rgba_FL))
            self.images_rgb = np.dstack((img_rgb_FC, img_rgb_FR, img_rgb_FL))
            self.time_to_grab_images = time.time() - tic
            print("Time to Grab Images: ", self.time_to_grab_images)

        # We Just want front
        elif (self.image_mask_FC_FR_FL[0] and not self.image_mask_FC_FR_FL[1]
              and not self.image_mask_FC_FR_FL[2]):
            images = self.client.simGetImages([
                client.ImageRequest("0", client.ImageType.Scene, False, False)
            ])
            img1d_FC = np.fromstring(images[0].image_data_uint8,
                                     dtype=np.uint8)
            img_rgba_FC = np.array(img1d_FC.reshape(images[0].height,
                                                    images[0].width, 4),
                                   dtype=np.uint8)
            img_rgb_FC = img_rgba_FC[:, :, 0:3]
            self.images_rgba = img_rgba_FC
            self.images_rgb = img_rgb_FC
            self.time_to_grab_images = time.time() - tic
            print("Time to Grab Images: ", self.time_to_grab_images)

        else:
            print("A screw up in set new images")