Fuzz Fuzz - 2 months ago 10
C Question

OUTDATED - Error modes for OpenCV

I am using OpenCV 1 to do some image processing, and am confused about the cvSetErrMode function (which is part of CxCore).

OpenCV has three error modes.

  • Leaf: The program is terminated after the error handler is called.

  • Parent: The program is not terminated, but the error handler is called.

  • Silent: Similar to Parent mode, but no error handler is called

At the start of my code, I call cvSetErrMode(CV_ErrModeParent) to switch from the default 'leaf' mode to 'parent' mode so my application is not terminated with an exception/assertion pop up.
Unfortunately 'parent' mode doesn't seem to be working. I still get the message dialog pop up, and my application still terminates.

If I call cvSetErrMode(CV_ErrModeSilent) then it actually goes silent, and no longer quits the application or throws up a dialog... but this also means that I dont know that an error has occurred. In this case, I think the mode is being set correctly.

Has anyone else seem this behaviour before and might be able to recommend a solution?



I am going to answer my own question, because after some fiddling around I have worked out what happens.

When you switch to 'parent' mode instead of leaf mode, there is an error handler that gets called cvGuiBoxReport(). cvGuiBoxReport() is the default error handler. It seems that even in parent mode, cvGuiBoxReport() still terminates your application! Oops.

So, to get around that you can write your own error handler, and redirect the error to be handled and NOT terminate the application.

An example error handler:

int MyErrorHandler(int status, const char* func_name, const char* err_msg, const char* file_name, int line, void*)
    std::cerr << "Woohoo, my own custom error handler" << std::endl;
    return 0;

You can set up parent mode and redirect your error with: