A simple pipeline to load image.
| 53 | |
| 54 | |
| 55 | class LoadImage: |
| 56 | """A simple pipeline to load image.""" |
| 57 | def __init__(self, color_type='color', channel_order='bgr'): |
| 58 | self.color_type = color_type |
| 59 | self.channel_order = channel_order |
| 60 | |
| 61 | def __call__(self, results): |
| 62 | """Call function to load images into results. |
| 63 | |
| 64 | Args: |
| 65 | results (dict): A result dict contains the image_path. |
| 66 | |
| 67 | Returns: |
| 68 | dict: ``results`` will be returned containing loaded image. |
| 69 | """ |
| 70 | if isinstance(results['image_path'], str): |
| 71 | results['image_file'] = results['image_path'] |
| 72 | img = mmcv.imread(results['image_path'], self.color_type, |
| 73 | self.channel_order) |
| 74 | elif isinstance(results['image_path'], np.ndarray): |
| 75 | results['image_file'] = '' |
| 76 | if self.color_type == 'color' and self.channel_order == 'rgb': |
| 77 | img = cv2.cvtColor(results['image_path'], cv2.COLOR_BGR2RGB) |
| 78 | else: |
| 79 | img = results['image_path'] |
| 80 | else: |
| 81 | raise TypeError('"image_path" must be a numpy array or a str or ' |
| 82 | 'a pathlib.Path object') |
| 83 | |
| 84 | results['img'] = img |
| 85 | return results |
| 86 | |
| 87 | |
| 88 | def inference_image_based_model( |
no outgoing calls
no test coverage detected