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="">
p="">
array<string^, 1=""> ^cmd_args = gcnew array<string^>(0); array="" for="" arguments,="" delegating="" memory="" int="" i="0;</p">
i="0;</p"> - 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);
Exec_Cmd(glob_tmp_char);
(called in next function)
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)
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.
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...");
}
}
}