Read a image, return uint8 RGB array of shape (H, W, 3).
(path: Union[str, os.PathLike, IO])
| 64 | |
| 65 | |
| 66 | def read_image(path: Union[str, os.PathLike, IO]) -> np.ndarray: |
| 67 | """ |
| 68 | Read a image, return uint8 RGB array of shape (H, W, 3). |
| 69 | """ |
| 70 | if isinstance(path, (str, os.PathLike)): |
| 71 | data = Path(path).read_bytes() |
| 72 | else: |
| 73 | data = path.read() |
| 74 | image = cv2.cvtColor(cv2.imdecode(np.frombuffer(data, np.uint8), cv2.IMREAD_COLOR), cv2.COLOR_BGR2RGB) |
| 75 | return image |
| 76 | |
| 77 | |
| 78 | def write_image(path: Union[str, os.PathLike, IO], image: np.ndarray, quality: int = 95): |