【问题标题】:ImDecode with Gif Images带 Gif 图像的 ImDecode
【发布时间】:2021-02-09 15:10:26
【问题描述】:

当我尝试解码从 URL 获取的 gif 图像时,我得到了一个 none 值。有人可以指导我做错什么吗?我没有太多的图像工作,所以我真的可以使用一些建议。

gif = "someurlthatgoestoagifimage.gif"
resp = urllib.request.urlopen(gif)
image = np.asarray(bytearray(resp.read()), dtype ="uint8")
image = cv2.imdecode(image, cv2.IMREAD_COLOR)

【问题讨论】:

    标签: python decode cv2


    【解决方案1】:

    Opencv 不支持解码 gif 图像。您可以使用 PIL 或 imageio 等其他库来解码或读取图像。

    例如使用imageio,可以读取一个gif图片如下:-

    resp = urllib.request.urlopen(gif_url)
    img_rgb = imageio.imread(resp.read())
    img = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2BGR)
    cv2.imwrite('image.png', img)
    

    参考:How to read gif from url using opencv (python)using imread of OpenCV failed when the image is Ok

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-04
      • 1970-01-01
      • 2019-08-11
      • 2021-11-11
      • 2010-11-04
      • 2018-06-19
      • 2014-04-04
      相关资源
      最近更新 更多