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


Runtime Environment:

  • Windows10 2004
  • python3.7
  • opencv-python

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!