2

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


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).

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
NotNamedDwayne
  • 585
  • 1
  • 6
  • 10
  • 2
    Are you using Visual C++? If so, check the hex value of `Ì`. It's either `0xcc` or `0xcd` (I've forgotten which). Either way, it means that the memory pointed to is uninitialized (`0xcc` is a flag used to indicate uninitialized memory on the stack; `0xcd` is for uninitialized memory on the heap). – James McNellis Jul 22 '10 at 20:19
  • 2
    Are you mixing debug and release binaries (accidentally or otherwise) as mentioned in the solution to the post you linked to? – Brook Miles Jul 22 '10 at 20:21

3 Answers3

8

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.

Community
  • 1
  • 1
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
  • 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 Jul 22 '10 at 20:37
  • @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 Jul 22 '10 at 20:41
  • string name = "CBImage"; namedWindow(name, 1); . . . imshow(name,Frame); runs, but it still tags the characters onto the beginning of the string. – NotNamedDwayne Jul 22 '10 at 21:01
  • Thank you again for your help. Once I built the debug libraries and added them into my project the problem went away!. – NotNamedDwayne Jul 22 '10 at 21:27
1

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:

Community
  • 1
  • 1
Michael Burr
  • 333,147
  • 50
  • 533
  • 760
0

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
  • 277,958
  • 43
  • 419
  • 720
  • But both functions take a `const string&`. http://opencv.willowgarage.com/documentation/cpp/user_interface.html#imshow. – kennytm Jul 22 '10 at 20:39