Hi i am trying to make a GUI for image compare software. The idea is to choose a picture with OPENFILENAME, then get its address with ofn.lpstrFile then make a histogram for that image. So i use:
return(ofn.lpstrFile);
I can cout the address or write it to an .xml file and the address is correct, but when i am trying to do the histogram it gives me all zeros. Behaves like the address was invalid.
Any ideas ?
my code :
string path=browse(); //getting the string from ofn.lpstrFile
path.c_str();
replace(path.begin(), path.end(), '\\', '/'); //converting backslash to slash also may be the problem
HistCreation(path,root_dir);
and
void HistCreation(string path,string root_dir) {
Mat img;
img = imread(path); // here if i manually enter the address everything works fine, if I insert the path then loads empty image
.
.
.
I also tried
char * cstr = new char[path.length() + 1];
std::strcpy(cstr, path.c_str());
Did not work either
std::string
returns the string and that's all you need. This is example to open a bitmap file.(Edit)
Note, Windows uses NUL-terminated C-strings. It knows the length of the string by looking for the zero at the end.
std::string::size()
is not always the same thing. We can call resize to make sure they are the same thing.You shouldn't need to replace
\\
with/
. If your library complains about\\
then replace as follows:Example:
Use
std::cout
to examine the output instead of guessing if it worked or not. In Windows program you can useOutputDebugString
orMessageBox
to see what the string is.I don't know what
root_dir
is supposed to be. IfHistCreation
fails or it has the wrong parameter then you have a different problem.