Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tile Grid: hevc (Main Still Picture) (hvc1 / 0x31637668), yuvj420p(pc, smpte170m/bt470bg/iec61966-2-1), 1080x1440 (default)这种格式的图片会报错 #151

Closed
hjj-lmx opened this issue Dec 24, 2024 · 4 comments

Comments

@hjj-lmx
Copy link

hjj-lmx commented Dec 24, 2024

rgb_res = bi_ref_net.inference(origin_image_bytes)

File "/BiRefNet/BiRefNetModel.py", line 38, in inference
image = Image.open(BytesIO(origin_image_bytes)) # 使用BytesIO来处理字节数据
File "/usr/local/lib/python3.10/dist-packages/PIL/Image.py", line 3536, in open
raise UnidentifiedImageError(msg)
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f56337d2250>

这是我图片的url,
https://watermarkud.tos-cn-shanghai.volces.com/input/2024/12/24/15/ucK19IiORSf.jpg

@hjj-lmx hjj-lmx changed the title 微博里面下载出来的图片传入里面抠图会报错 Tile Grid: hevc (Main Still Picture) (hvc1 / 0x31637668), yuvj420p(pc, smpte170m/bt470bg/iec61966-2-1), 1080x1440 (default) Dec 24, 2024
@hjj-lmx hjj-lmx changed the title Tile Grid: hevc (Main Still Picture) (hvc1 / 0x31637668), yuvj420p(pc, smpte170m/bt470bg/iec61966-2-1), 1080x1440 (default) Tile Grid: hevc (Main Still Picture) (hvc1 / 0x31637668), yuvj420p(pc, smpte170m/bt470bg/iec61966-2-1), 1080x1440 (default)这种格式的图片会报错 Dec 24, 2024
@ZhengPeng7
Copy link
Owner

这个url用requests.get读取, 出来的内容类型不是"image/xx", 所以有问题:

import requests
image_src = 'https://watermarkud.tos-cn-shanghai.volces.com/input/2024/12/24/15/ucK19IiORSf.jpg'
response = requests.get(image_src)
print(response.headers["Content-Type"])
# 'binary/octet-stream'

但其实实质上是因为你这个图像实际上是HEIF格式的, 你右击可以看到.
截屏2024-12-24 23 37 36

参考 https://stackoverflow.com/questions/54395735/how-to-work-with-heic-image-file-types-in-python, 添加

from pillow_heif import register_heif_opener
register_heif_opener()

就可以之后image_ori = Image.open(BytesIO(response.content))了.
如果再不兼容, 可以image_ori = np.array(image_ori).

@hjj-lmx
Copy link
Author

hjj-lmx commented Dec 25, 2024

这个url用requests.get读取,出来的内容类型不是“image/xx”,所以有问题:

import requests
image_src = 'https://watermarkud.tos-cn-shanghai.volces.com/input/2024/12/24/15/ucK19IiORSf.jpg'
response = requests.get(image_src)
print(response.headers["Content-Type"])
# 'binary/octet-stream'

但实际上实质上是因为你这个图像实际上是HEIF格式的,你右击就可以看到。 截屏2024-12-24 23 37 36

参考https://stackoverflow.com/questions/54395735/how-to-work-with-heic-image-file-types-in-python,添加

from pillow_heif import register_heif_opener
register_heif_opener()

之后就可以了image_ori = Image.open(BytesIO(response.content))。 如果再不兼容,可以image_ori = np.array(image_ori)

我是用try把那个包起来了,报错就走pillow_heif的写法

@ZhengPeng7
Copy link
Owner

可以, 但是也没必要?... 因为只是添加register_heif_opener()而已, 并不需要修改正常读取代码的.

@hjj-lmx
Copy link
Author

hjj-lmx commented Dec 26, 2024

可以, 但是也没必要?... 因为只是添加register_heif_opener()而已, 并不需要修改正常读取代码的.

已经按照你提供的方法修改了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants