Search code examples
opencvimread

using imread of OpenCV failed when the image is Ok


I encountered a problem when I want to read an image using the OpenCV function imread(). The image is Ok and I can show it in the image display software. But when I use the imdecode() to get the image data, the data returns NULL. I will upload the image and the code and hope some one could help me

Mat img = imread(image_name);
if(!img.data) return -1;

The image's link is here: http://img3.douban.com/view/photo/raw/public/p2198361185.jpg

PS: The image_name is all right. I guess OpenCV cannot decode this image. So is there any way to decode this image using OpenCV?, like add new decode library. By the way, I can read this image using other image library such as freeImage.


Solution

  • Your image is in .gif and it is not supported by OpenCV as of now.

    Note OpenCV offers support for the image formats Windows bitmap (bmp), portable image formats (pbm, pgm, ppm) and Sun raster (sr, ras). With help of plugins (you need to specify to use them if you build yourself the library, nevertheless in the packages we ship present by default) you may also load image formats like JPEG (jpeg, jpg, jpe), JPEG 2000 (jp2 - codenamed in the CMake as Jasper), TIFF files (tiff, tif) and portable network graphics (png). Furthermore, OpenEXR is also a possibility.

    Source - Click here

    You can use something like this, to perform the conversion.

    I was able to load your image using imread using this. Also, you can check out FreeImage.