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

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);
namedWindow("ImageBefore",CV_WINDOW_NORMAL);
imshow("ImageBefore",image);
}


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";
namedWindow("ImageBefore",CV_WINDOW_NORMAL);
imshow("ImageBefore",image);
}


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 close merge delete

Sort by » oldest newest most voted

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"

more

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.

more