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)
| 31 | |
| 32 | |
| 33 | def imwrite(img, file_path, params=None, auto_mkdir=True): |
| 34 | """Write image to file. |
| 35 | |
| 36 | Args: |
| 37 | img (ndarray): Image array to be written. |
| 38 | file_path (str): Image file path. |
| 39 | params (None or list): Same as opencv's :func:`imwrite` interface. |
| 40 | auto_mkdir (bool): If the parent folder of `file_path` does not exist, |
| 41 | whether to create it automatically. |
| 42 | |
| 43 | Returns: |
| 44 | bool: Successful or not. |
| 45 | """ |
| 46 | if auto_mkdir: |
| 47 | dir_name = os.path.abspath(os.path.dirname(file_path)) |
| 48 | os.makedirs(dir_name, exist_ok=True) |
| 49 | return cv2.imwrite(file_path, img, params) |
| 50 | |
| 51 | |
| 52 | def img2tensor(imgs, bgr2rgb=True, float32=True): |
no outgoing calls
no test coverage detected