我刚开始尝试使用 OpenCV,并且根据一本书编写了一个非常简单的小程序。问题是当我尝试编译它时,出现此错误。我会告诉你我所有的信息。我使用 Homebrew 软件为 Mac OS X 10.7 安装了 openCV。
#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;
}
我喜欢这样编译:
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
这是我尝试运行它时得到的结果。
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
再次感谢。
最佳答案
那是因为OpenCV不支持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 )
参见 docs .
关于c++ - OpenCV 2.4.2 错误 "OpenCV Error: Bad flag",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11494119/