annatn998
annatn998

Reputation: 77

ImDecode with Gif Images

I'm getting a none value returned when I try to decode an gif image I've gotten from a URL. Could someone please direct me towards what I'm doing wrong? I haven't worked too much with images so I could really use some advice.

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

Upvotes: 0

Views: 717

Answers (1)

anilsathyan7
anilsathyan7

Reputation: 1793

Opencv does not support decoding gif images. You can use other libraries like PIL or imageio to decode or read images.

For example using imageio, you can read a gif image as follows:-

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)

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

Upvotes: 3

Related Questions