Ask Your Question
0

cv2.imread fail to open gif image

asked 2020-02-20 12:55:41 -0600

raggupta2 gravatar image

updated 2020-09-17 03:24:08 -0600

Can anybody tell why imread function will fail for this photo?

C:\fakepath\f.gif

Actual file is here: https://drive.google.com/file/d/1qFPK...

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2020-02-20 13:10:31 -0600

berak gravatar image

updated 2020-02-20 13:12:33 -0600

easy one, imread() won't read any .gif there is no codec for this (license problem)

as a workaround (and if you have ffmpeg support builtin), try:

cap = cv2.VideoCapture("f.gif")
ret, image = cap.read()
cap.release()

if ret:
    # safe to work with image !
    ...
edit flag offensive delete link more

Comments

i don't think so. This photo is saved from browser. While most of images working only a few getting this problem. Why only specific photos will have this problem?

raggupta2 gravatar imageraggupta2 ( 2020-02-20 13:20:20 -0600 )edit

gif is animation not image. You will have to used @berak's snippet code.

supra56 gravatar imagesupra56 ( 2020-02-21 04:30:03 -0600 )edit
1

Of course GIF is a still image format, and was very common for pictures before PNG was invented. Today, though, it is mostly used for small silent animations.

mvuori gravatar imagemvuori ( 2020-02-21 05:49:01 -0600 )edit

@mvuori. Thank. I can recalled back in 1984. that I used to build 8086.

supra56 gravatar imagesupra56 ( 2020-02-21 09:01:51 -0600 )edit
2

I just opened this photo in MS-Paint and saved as JPG. Now it works

raggupta2 gravatar imageraggupta2 ( 2020-02-21 09:29:23 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-02-20 12:55:41 -0600

Seen: 14,896 times

Last updated: Feb 21 '20