Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV imread doesn't work

Tags:

c++

opencv

I have loop in my C++ code to open and process a set of images. One of those is sample inputhttp://i.stack.imgur.com/rUJnp.gif

imread has trouble opening this specific one.imread().data is NULL.

FWIW, I'm on CentOS and using the latest opencv 2.4.8. Is there anyway to fix this? If not what is the easiest way to maybe open it with another C++ image library and convert it to cv::Mat?

like image 631
Mohammad Moghimi Avatar asked Nov 30 '22 11:11

Mohammad Moghimi


2 Answers

From OpenCV documentation regarding imread

The function imread loads an image from the specified file and returns it. If the image cannot be read (because of missing file, improper permissions, unsupported or invalid format), the function returns an empty matrix ( Mat::data==NULL ). Currently, the following file formats are supported:

    Windows bitmaps - *.bmp, *.dib (always supported)
    JPEG files - *.jpeg, *.jpg, *.jpe (see the Notes section)
    JPEG 2000 files - *.jp2 (see the Notes section)
    Portable Network Graphics - *.png (see the Notes section)
    Portable image format - *.pbm, *.pgm, *.ppm (always supported)
    Sun rasters - *.sr, *.ras (always supported)
    TIFF files - *.tiff, *.tif (see the Notes section)

So .gif format is not supported by OpenCV hence imread is returning NULL.

like image 75
Mantosh Kumar Avatar answered Dec 02 '22 00:12

Mantosh Kumar


As I known, OpenCV does not support the gif format that, to read directly in your program, some external libraries are required. Such as http://freeimage.sourceforge.net/.

Good Luck

like image 25
GilbertLee Avatar answered Dec 02 '22 00:12

GilbertLee