Ask Your Question
0

Problem with imread in debug mode [closed]

asked 2014-03-26 02:52:32 -0600

Benny gravatar image

updated 2014-03-26 03:47:09 -0600

Hi

I am trying to use imread() in a very simple manner:

const string ImageName("D:/SomeImage.tif");
Mat Image=imread(ImageName);

the problem is that the returned Mat is empty.

I compiled the opencv sources myself (Ver 2.4.6.0) using VS 2008 SP1 in both debug and release modes.

Have started debugging the code in debug mode where I have used the debug lib files for linker input (i.e., opencv_somemodule246d.lib etc.) and copied the corresponding debug dlls and pdb files to the application directory.

When the debugger hit the imread() line I steped into imread and saw that the actual value passed in the string for the file name was garbage so obviously it returned empty matrix. I also tried to use non const string and const and non const char* for the image name - the results were identical!. I should note that in release mode there isn't any problem and the passed string is the correct one.

Any ideas?

Edit : Changed my typo ImageName("D:\SomeImage.tif") to ImageName("D:/SomeImage.tif"); I have actually tried it with "\\" and with "/" for the file separator - the result were the same: garbage passed string - once again this happens only on debug mode, in release - everything OK!

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by StevenPuttemans
close date 2014-03-26 06:30:03.491860

Comments

I just tested the following configuration

 const string ImageName("C:/data/yoda.jpg");
 Mat Image=imread(ImageName);
 imshow("test", Image); waitKey(0);

which works just perfectly using opencv 2.4.6 and a correctly configured project. Are you sure your path is correct? Always use front slashes, it will make your system work on each operating system!

StevenPuttemans gravatar imageStevenPuttemans ( 2014-03-26 04:51:27 -0600 )edit

Yes, I am sure about the path and I also used "/". Did you tested it in debug mode? Once again, the problem, as reflects when debugging the code, is that the string which actually got passed to imread was different than the one I specified.

Benny gravatar imageBenny ( 2014-03-26 05:17:48 -0600 )edit

I always test in debug mode ... but it works also in release. Edit your question and post your complete configuration with screens? I could take a look!

StevenPuttemans gravatar imageStevenPuttemans ( 2014-03-26 05:25:49 -0600 )edit
1

Just a guess: Do check your "Character Set" setting in the VS Project Settings (Configuration Properties->General) for Debug mode. It should use the same setting as the Release mode and OpenCV lib (i.e. Multi-Byte Character Set).

Christian gravatar imageChristian ( 2014-03-26 05:46:36 -0600 )edit
1

Close enough!!. Problem solved!. Actually, though the "Character Set" wasn't set that wasn't the problem. The problem was "Runtime library" in Project settings->C/C++ -> Code Generation which should be "Multi-threaded Debug DLL" instead of just "Multi-threaded" Thank U!!

Benny gravatar imageBenny ( 2014-03-26 06:12:25 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-03-26 03:23:36 -0600

ThomasB gravatar image

updated 2014-03-26 03:24:13 -0600

You have to escape backslashes in C/C++ and most other languages (no clue which one you use, but looks like C++).

Thus your string should be

const string ImageName("D:\\SomeImage.tif");

Because you state it does not work with Debug-Mode, did it work in "normal" mode?

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-03-26 02:52:32 -0600

Seen: 4,075 times

Last updated: Mar 26 '14