| 93 | time.sleep(1) |
| 94 | |
| 95 | def get_camera_data(self, camera_type = 'color'): |
| 96 | valid_types = {'color', 'object_mask', 'depth'} |
| 97 | if camera_type not in valid_types: |
| 98 | raise ValueError(f"Invalid camera type. Expected one of {valid_types}, but got '{camera_type}'.") |
| 99 | |
| 100 | if camera_type == 'color': |
| 101 | image_type = airsim.ImageType.Scene |
| 102 | elif camera_type == 'depth': |
| 103 | image_type = airsim.ImageType.DepthPlanar |
| 104 | else: |
| 105 | image_type = airsim.ImageType.Segmentation |
| 106 | |
| 107 | responses = self._client.simGetImages([airsim.ImageRequest('front_custom', image_type, False, False)]) |
| 108 | response = responses[0] |
| 109 | if response.pixels_as_float: |
| 110 | img_data = np.array(response.image_data_float, dtype=np.float32) |
| 111 | img_data = np.reshape(img_data, (response.height, response.width)) |
| 112 | else: |
| 113 | img_data = np.frombuffer(response.image_data_uint8, dtype=np.uint8) |
| 114 | img_data = img_data.reshape(response.height, response.width, 3) |
| 115 | |
| 116 | return img_data |
| 117 | |
| 118 | def save_image(self, image_data, file_path): |
| 119 | cv2.imwrite(file_path, image_data) |