Cv2.imread does not read jpg files (the path is right)

19579

Runtime Environment:

  • Windows10 2004
  • python3.7
  • opencv-python 4.5.2.52

Problem description:

When I try to use cv2.imread to load above image, the cv2.imread just return a nonetype object. But when I use plt.imread to load above image, plt.imread can return np.ndarray object correctly.

I see that it’s a GIF… that can be troublesome.

you can try loading it using VideoCapture. yes, that makes sense for animated gifs. I guess it’s also required for regular GIFs.

(success, img) = cv.VideoCapture("6a29955cd6f47442fa9fa5ba6230616064767c52.gif").read()

So, this file has a .jpg suffix. But it is a gif actually?

Alright, the .jpg suffix cheat me. The actual format of this image is .gif. This is an image from ImageClef dataset. It cost me large time to get clean on this bug. Thank you!