Write image to file. Args: img (ndarray): Image array to be written. file_path (str): Image file path. params (None or list): Same as opencv's :func:`imwrite` interface. auto_mkdir (bool): If the parent folder of `file_path` does not exist, whether to
(img, file_path, params=None, auto_mkdir=True)
| 133 | |
| 134 | |
| 135 | def imwrite(img, file_path, params=None, auto_mkdir=True): |
| 136 | """Write image to file. |
| 137 | |
| 138 | Args: |
| 139 | img (ndarray): Image array to be written. |
| 140 | file_path (str): Image file path. |
| 141 | params (None or list): Same as opencv's :func:`imwrite` interface. |
| 142 | auto_mkdir (bool): If the parent folder of `file_path` does not exist, |
| 143 | whether to create it automatically. |
| 144 | |
| 145 | Returns: |
| 146 | bool: Successful or not. |
| 147 | """ |
| 148 | if auto_mkdir: |
| 149 | dir_name = os.path.abspath(os.path.dirname(file_path)) |
| 150 | os.makedirs(dir_name, exist_ok=True) |
| 151 | ok = cv2.imwrite(file_path, img, params) |
| 152 | if not ok: |
| 153 | raise IOError('Failed in writing images.') |
| 154 | |
| 155 | |
| 156 | def crop_border(imgs, crop_border): |
no outgoing calls
no test coverage detected