Having problem with opencv_traincascade.exe crashing /w exception [closed]
Good day,
I've got some project in University running wild with this problem. What I'm trying to do is to get these console-called functions like opencv_createsamples and opencv_traincascade executing from my app where user can just specify some info in Windows Form app. I made it through with opencv_createsamples which makes me a good .vec file from specified folders with negs and pos but when it comes to opencv_traincascade it just crashes. On debug I've got this:
xstring
line: 832
basic_string(const _Elem *_Ptr)
: _Mybase()
{ // construct from [_Ptr, <null>)
_Tidy();
> assign(_Ptr);
}
The thread 0x3230 has exited with code 0 (0x0). Unhandled exception thrown: read access violation. _Ptr was nullptr.
What can actually be wrong with this stuff? Many thanks in advance!
REDACTED:
Adding some code examples on how it was done.
- I made an array<string^> to="" collect="" the="" data="" from="" boxes\editos="" on="" the="" form<="" li="">
array<String^, 1> ^cmd_args = gcnew array<String^>(0); // Array for arguments, delegating memory
int i = 0;
- Then I was adding elements to it with simple lines of code like this:
cmd_args->Resize<String ^>(cmd_args, cmd_args->Length + 1);
md_args[i++] = Application::StartupPath + "\\Classifier\\" + this->txtBoxName->Text->ToString() +".info";
- Then, when it took all the necessary info I converted it into single std::wstring
msclr::interop::marshal_context context;
for (int i = 0; i < cmd_args->Length; i++) // form the string
{
std::string standardString = context.marshal_as<std::string>(ptr_cmd_args[i]->ToString());
for (int j = 0; j < standardString.size(); j++)
{
glob_tmp_char.push_back(standardString[j]);
}
}
- Senting the wstring to cmd_exec function
Exec_Cmd(glob_tmp_char);
(called in next function)
LPWSTR ConvertToLPWSTR(const std::wstring& s) // converts my wstring to lpwstr
{
LPWSTR ws = new wchar_t[s.size() + 1];
copy(s.begin(), s.end(), ws);
ws[s.size()] = 0;
return ws;
}
(actual execute funcion)
void Exec_Cmd(std::wstring cmd) // std::string
{
/* Summary
This script executes command line from the application
Necessary to call two opencv cmd functions to build
.vec file and then to build actual trained cascade.
this is going to be called from another function when
will build cmd line param basing on user inputs.
*/
STARTUPINFO info = { sizeof(info) };
PROCESS_INFORMATION processInfo;
LPWSTR cmd_args = ConvertToLPWSTR(cmd);
if (CreateProcess(NULL, cmd_args, NULL, NULL, false, NORMAL_PRIORITY_CLASS, NULL, NULL, &info, &processInfo))
{
WaitForSingleObject(processInfo.hProcess, INFINITE);
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
}
else
{
System::Windows::Forms::MessageBox::Show("The process could not be started...");
}
}
As I said it works well when it about making .vec file, but crashes on attempt to do the same on traincascade
could you show your code ?
Yea, I can do that - but what part is interesting to you exactly? I mean, there is a long part where I take params from various combo boxes etc and form a string then I send a string to function that call CreateProcess with that string going as command line
well, there's something wrong with your strings, no ? (and how would we know, w/o looking at it ?)
btw, this is a (managed) c++ problem, not at all an opencv one ...
Damn, I wrote a post and It says I need to wait 2 days, there was the code.. Well, let me write it down again as a comment on the comment...
just edit your question
Done, it's at the bottom
this is all off-topic.
Then I'm not really getting what do you need.