Error in OpenCV 2.4.2 “OpenCV Error: Bad flag”

拈花ヽ惹草 提交于 2019-12-23 10:37:45

问题


I just started trying to play with OpenCV and I wrote a small program from a book that is pretty simple. The problem is when I try to compile it, I get this error. I will give you all the information I have. I installed openCV using homebrew for Mac OS X 10.7.

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

int main(int argc, char *argv[])
{
cv::Mat image = cv::imread("usf.gif");
cv::namedWindow("My Image");
cv::imshow("My Image", image);
cv::waitKey(5000);

return 1;
}

I compiled liked this:

g++ -o test opencvtest.cc -lopencv_core -lopencv_imgproc -lopencv_calib3d -lopencv_video -lopencv_features2d -lopencv_ml -lopencv_highgui -lopencv_objdetect -lopencv_contrib -lopencv_legacy

And this is what I got back when I tried to run it.

OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /tmp/homebrew-opencv-2.4.2-oQmu/OpenCV-2.4.2/modules/core/src/array.cpp, line 2482
terminate called throwing an exceptionAbort trap: 6

Thanks again.


回答1:


That's because OpenCV doesn't support gif:

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

Windows bitmaps - *.bmp, *.dib (always supported)

JPEG files - *.jpeg, *.jpg, *.jpe (see Note2 )

JPEG 2000 files - *.jp2 (see Note2 )

Portable Network Graphics - *.png (see Note2 )

Portable image format - *.pbm, *.pgm, *.ppm (always supported)

Sun rasters - *.sr, *.ras (always supported)

TIFF files - *.tiff, *.tif (see Note2 )

See docs.




回答2:


I think the "gifs" are not supported



来源:https://stackoverflow.com/questions/11494119/error-in-opencv-2-4-2-opencv-error-bad-flag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!