| 37 | self.file_client = None |
| 38 | |
| 39 | def __call__(self, results): |
| 40 | if self.file_client is None: |
| 41 | self.file_client = mmcv.FileClient(**self.file_client_args) |
| 42 | |
| 43 | if results['img_prefix'] is not None: |
| 44 | filename = osp.join(results['img_prefix'], results['image_path']) |
| 45 | else: |
| 46 | filename = results['image_path'] |
| 47 | |
| 48 | if filename.endswith('smc'): |
| 49 | assert 'image_id' in results, 'Load image from .smc, ' \ |
| 50 | 'but image_id is not provided.' |
| 51 | device, device_id, frame_id = results['image_id'] |
| 52 | smc_reader = SMCReader(filename) |
| 53 | img = smc_reader.get_color(device, |
| 54 | device_id, |
| 55 | frame_id, |
| 56 | disable_tqdm=True) |
| 57 | img = img.squeeze() # (1, H, W, 3) -> (H, W, 3) |
| 58 | img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR) # BGR is used |
| 59 | del smc_reader |
| 60 | else: |
| 61 | img_bytes = self.file_client.get(filename) |
| 62 | img = mmcv.imfrombytes(img_bytes, flag=self.color_type) |
| 63 | |
| 64 | if self.to_float32: |
| 65 | img = img.astype(np.float32) |
| 66 | |
| 67 | results['filename'] = filename |
| 68 | results['ori_filename'] = results['image_path'] |
| 69 | results['img'] = img |
| 70 | results['img_shape'] = img.shape[:2] |
| 71 | results['ori_shape'] = img.shape[:2] |
| 72 | num_channels = 1 if len(img.shape) < 3 else img.shape[2] |
| 73 | results['img_norm_cfg'] = dict(mean=np.zeros(num_channels, |
| 74 | dtype=np.float32), |
| 75 | std=np.ones(num_channels, |
| 76 | dtype=np.float32), |
| 77 | to_rgb=False) |
| 78 | return results |
| 79 | |
| 80 | def __repr__(self): |
| 81 | repr_str = (f'{self.__class__.__name__}(' |