Ask Your Question

Why do I get an error from imread when running my program in eclipse CDT, but not when running from terminal.

asked 2012-10-27 20:53:46 -0600

ZachTM gravatar image

Hi guys I have had this problem for a while but I finally want to figure out how to fix it. In eclipse I can have this code:

int main(int argc, char** argv){
    Mat image = imread( argv[1], 0);

If I specify argv[1] in eclipse to be "filename.jpg" I get the following error:

OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /home/refinedcode/Development/OpenCV-2.4.2/modules/core/src/array.cpp, line 2482
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/refinedcode/Development/OpenCV-2.4.2/modules/core/src/array.cpp:2482: error: (-206) Unrecognized or unsupported array type in function cvGetMat

But if I run the executable from the terminal with

./ProgramName filename.jpg

It runs fine. I can change the code to:

int main(int argc, char** argv){
    const string filename "filename.jpg";
    Mat image = imread(filename, 0);

Yet I get the exact same error. The file is in my debug folder, the same folder as the compiled program, but if I write in the full path it still does not work.

I would really appreciate it if anyone could give me insight on why this is happening?

Thanks, Zach

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2012-10-29 04:32:58 -0600

Mahdi gravatar image

That is because it can not find the image address from you project folder!
You shoud address you files from project root folder for eclipse! probably you have your image in the Debug folder so you should change the "filename.jpg" to "Debug/filename.jpg"

edit flag offensive delete link more

answered 2012-10-29 03:22:14 -0600

Kirill Kornyakov gravatar image

May be the working directory (where Eclipse launches your program) differs from the directory you use in terminal? Most likely that a call to the standard fopen() function will also result in failure. So, I think your question is not related to OpenCV, try to fopen() a txt-file, and I believe you'll discover that some paths are not configured in your IDE.

edit flag offensive delete link more

Question Tools


Asked: 2012-10-27 20:53:46 -0600

Seen: 7,498 times

Last updated: Oct 29 '12