def get_image_from_path(src_path, img_entry, ret_bytes=False): """ skimage.io.imread() can read filenames or urls imghdr.what() can read filenames or bytes """ if not isinstance(img_entry, str): return img_entry if is_http(img_entry): if ret_bytes: return get_image_from_http_bytes(img_entry) return img_entry if src_path or os.path.isabs(img_entry): return get_abs_path(src_path, img_entry) with open_file(img_entry, 'rb') as f: if ret_bytes: return f.read() return f
def get_image_from_path( src_path: Union[str, torch.Tensor], img_entry: Union[str, bytes], ret_bytes: bool = False ) -> Union[BytesIO, BinaryIO, TextIO, bytes, str]: if not isinstance(img_entry, str): return img_entry if is_http(img_entry): if ret_bytes: # Returns BytesIO. return get_image_from_http_bytes(img_entry) return img_entry if src_path or os.path.isabs(img_entry): return get_abs_path(src_path, img_entry) with open_file(img_entry, "rb") as f: if ret_bytes: return f.read() return f
def get_image_from_path( <<<<<<< HEAD src_path: Union[str, torch.Tensor], img_entry: Union[str, bytes], ret_bytes: bool = False <<<<<<< HEAD ) -> Union[BinaryIO, TextIO, bytes]: ======= ======= src_path: Union[str, torch.Tensor], img_entry: Union[str, bytes], ret_bytes: bool = False >>>>>>> upstream/master ) -> Union[BytesIO, BinaryIO, TextIO, bytes, str]: >>>>>>> upstream/master if not isinstance(img_entry, str): return img_entry if is_http(img_entry): if ret_bytes: # Returns BytesIO. return get_image_from_http_bytes(img_entry) return img_entry if src_path or os.path.isabs(img_entry): return get_abs_path(src_path, img_entry) with open_file(img_entry, "rb") as f: if ret_bytes: return f.read() return f def is_image(src_path: str, img_entry: Union[bytes, str]) -> bool: if not isinstance(img_entry, str): return False