Having problem with opencv_traincascade.exe crashing /w exception [closed]

asked 2016-06-21 03:57:53 -0600

Jinx gravatar image

updated 2017-12-24 10:51:25 -0600

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.

  1. I made an array<string^&gt; 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;
  1. 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";
  1. 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]);
    }
}
  1. 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

edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant by berak
close date 2016-06-22 07:42:42.609178

Comments

could you show your code ?

berak gravatar imageberak ( 2016-06-21 04:07:55 -0600 )edit

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

Jinx gravatar imageJinx ( 2016-06-21 04:29:49 -0600 )edit

well, there's something wrong with your strings, no ? (and how would we know, w/o looking at it ?)

berak gravatar imageberak ( 2016-06-21 04:39:45 -0600 )edit

btw, this is a (managed) c++ problem, not at all an opencv one ...

berak gravatar imageberak ( 2016-06-21 04:41:14 -0600 )edit

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

Jinx gravatar imageJinx ( 2016-06-21 04:46:28 -0600 )edit

just edit your question

berak gravatar imageberak ( 2016-06-21 04:47:42 -0600 )edit

Done, it's at the bottom

Jinx gravatar imageJinx ( 2016-06-21 04:54:13 -0600 )edit
1

this is all off-topic.

berak gravatar imageberak ( 2016-06-21 05:15:50 -0600 )edit

Then I'm not really getting what do you need.

Jinx gravatar imageJinx ( 2016-06-21 05:26:35 -0600 )edit