views:

124

answers:

4

Hello I have been developing some computer vision tools with openCV, but every time that I pass a string into an openCV function, the characters ÌÌÌÌ get tagged onto the beginning. At first this was just annoying, but now I am trying to use openCV's fileStorage tools and the ÌÌÌÌ characters are making my file names unreadable.

Note: the characters only get added when I pass strings into the new c++ style openCV functions. If I use the old C style functions the strings come out fine.

example: I enter this:

namedWindow("CBImage", 1);
.
.
.
imshow("CBImage", Frame);

But the window title reads ÌÌÌÌCBImage

I don't think that the problem is necessarily specific to openCV; I think it has to do with string use in general. check this link out the coder seems to be experiencing a similar problem. http://www.sfml-dev.org/forum/viewtopic.php?t=1257&sid=5cfa50b780e47685d1c03296adffa8ed

any thoughts? thanks

+6  A: 

Given that ÌÌÌÌ = 0xCCCCCCCC, it seems the library does not expect a 4-byte member before the string member, e.g.

// Provided.
struct something {
   ...
   void* some_pointer; // uninitialized variables are filled with 0xCC in debug mode.
   char the_actual_content[1234];
   ...
}

// But the library wants
struct something {
   ...
   char the_actual_content[1234]; // now the 0xCCCCCCC is shifted into this string.
   ...
}

Have you tried the advice in the link?

Don't mix debug and release configurations If you're in debug mode, link to the libraries with the "-d" suffix.

KennyTM
Thanks for your help. I did try linking to the debug libraries, but that didn't work. However, I think I know why.quote from http://opencv.willowgarage.com/wiki/VisualC%2B%2B_VS2008"The debug versions are available only when you Build the Visual C++ .NET solution provided with the OpenCV installation."for other openCV users: you do need the debug versions of the linker files (if you are in debug mode)
NotNamedDwayne
@Not: Hm. Assuming [@Ben](http://stackoverflow.com/questions/3313023/why-do-the-characters-iiii-get-stuck-onto-the-begining-of-my-strings/3313147#3313147) is correct, could you try `string name = "CBImage";` and call the two functions with `name`?
KennyTM
string name = "CBImage"; namedWindow(name, 1); . . . imshow(name,Frame);runs, but it still tags the characters onto the beginning of the string.
NotNamedDwayne
Thank you again for your help. Once I built the debug libraries and added them into my project the problem went away!.
NotNamedDwayne
+1  A: 

Something is reading memory that hasn't been initialized. See the following answer for details of what debug builds of MSVC might set uninitialized or unusable memory to:

Michael Burr
A: 

You may be passing the address of a std::string to a function that expects a reference (not pointer) to a std::string and also has a version that accepts void*.

Ben Voigt
KennyTM
A: 

Thank you all for your help. KennyTM's origional suggestion did fix the problem. I had to replace my cv cvaux cvcore and highgui libraries with the debug versions (they may have to be built depending on which version of openCV you are running check your lib folder in your openCV directory).

NotNamedDwayne