How to suppress OpenCV error message

PaulYang

I am writing an OpenCV project using g++ and opencv 2.4.6

I have some code like this:

try 
{
    H = findHomography( obj, scene, CV_RANSAC );
}
catch (Exception &e)
{
    if (showOutput)
        cout<< "Error throwed when finding homography"<<endl;
    errorCount++;
    if (errorCount >=10)
    {
        errorCount = 0;
        selected_temp = -99;
        foundBB = false;
        bb_x1 = 0;
        bb_x2 = 0;
        bb_y1 = 0;
        bb_y2 = 0;
    }
    return -1;
}

Error will be thrown when the findHomography failed to find things. The error message includes:

OpenCV Error: Assertion failed (npoints >= 0 && points2.checkVector(2) 
== npoints && points1.type() == points2.type()) in findHomography, 
file /Users/dji-mini/Downloads/opencv- 2.4.6/modules/calib3d/src/fundam.cpp, 
line 1074
OpenCV Error: Assertion failed (count >= 4) in cvFindHomography, 
file /Users/dji-mini/Downloads/opencv-2.4.6/modules/calib3d/src/fundam.cpp, line 235

Since I know under what conditions the message would appear, I want to suppress these error messages. But I don't know how to do it.

In old version of OpenCV, there seems to have a "cvSetErrMode", which, according to other articles, is depreciated in OpenCV 2.X. So what function can I use to suppress OpenCV error messages?

Aurelius

cv::error() is called on every occurrence of an assertion failure. The default behavior is to print the assertion statement to std::cerr.

You can use the undocumented cv::redirectError() function to set a custom error-handling callback. This will override the default behavior of cv::error(). You first need to define a custom error-handling function:

int handleError( int status, const char* func_name,
            const char* err_msg, const char* file_name,
            int line, void* userdata )
{
    //Do nothing -- will suppress console output
    return 0;   //Return value is not used
}

And then set the callback before the code which throw:

    cv::redirectError(handleError);

try {
    // Etc...

If at any point you wish to restore the default behavior, you can do so:

cv::redirectError(nullptr);    //Restore default behavior; pass NULL if no C++11

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to suppress error message of a command?

From Dev

How to suppress certain error message in 'find' command?

From Dev

tryCatch suppress error message

From Dev

Suppress error message in R

From Dev

Suppress error message in R

From Dev

How to suppress PowerShell error message during variable assignment

From Dev

matlab - suppress error message backtrace

From Dev

How to suppress R startup message?

From Dev

Suppress supplementary error message from unit test

From Dev

JAX-RS : Suppress Error Message

From Dev

Not able to suppress the error message using /dev/null

From Dev

How to suppress the error message when dividing 0 by 0 using np.divide (alongside other floats)?

From Dev

How to suppress [no test files] message on go test

From Dev

PostgreSQL - How to suppress query statement message

From Dev

How to suppress File in use alert message

From Dev

How to suppress Undefined index error?

From Dev

How to suppress QXcbConnection: XCB error

From Dev

How to suppress error messages in zsh?

From Dev

How to stop OpenCV error message from printing in Python

From Dev

Forms Suppress Error Message And Catch frm-40350

From Dev

Numpy / Polyfit - Suppress printing of Intel MKL Error message

From Dev

Forms Suppress Error Message And Catch frm-40350

From Dev

Numpy / Polyfit - Suppress printing of Intel MKL Error message

From Dev

Can i suppress error message from fetch.pm in Perl

From Dev

Suppress "Error during loading" message in standalone Jasmine 3.1 browser report

From Dev

How to suppress "Unsupported parameters" error in Ansible?

From Dev

how to suppress error from .vim plugin vimIM

From Dev

How can I suppress these error messages?

From Dev

How to suppress tar error messages in when piping

Related Related

  1. 1

    How to suppress error message of a command?

  2. 2

    How to suppress certain error message in 'find' command?

  3. 3

    tryCatch suppress error message

  4. 4

    Suppress error message in R

  5. 5

    Suppress error message in R

  6. 6

    How to suppress PowerShell error message during variable assignment

  7. 7

    matlab - suppress error message backtrace

  8. 8

    How to suppress R startup message?

  9. 9

    Suppress supplementary error message from unit test

  10. 10

    JAX-RS : Suppress Error Message

  11. 11

    Not able to suppress the error message using /dev/null

  12. 12

    How to suppress the error message when dividing 0 by 0 using np.divide (alongside other floats)?

  13. 13

    How to suppress [no test files] message on go test

  14. 14

    PostgreSQL - How to suppress query statement message

  15. 15

    How to suppress File in use alert message

  16. 16

    How to suppress Undefined index error?

  17. 17

    How to suppress QXcbConnection: XCB error

  18. 18

    How to suppress error messages in zsh?

  19. 19

    How to stop OpenCV error message from printing in Python

  20. 20

    Forms Suppress Error Message And Catch frm-40350

  21. 21

    Numpy / Polyfit - Suppress printing of Intel MKL Error message

  22. 22

    Forms Suppress Error Message And Catch frm-40350

  23. 23

    Numpy / Polyfit - Suppress printing of Intel MKL Error message

  24. 24

    Can i suppress error message from fetch.pm in Perl

  25. 25

    Suppress "Error during loading" message in standalone Jasmine 3.1 browser report

  26. 26

    How to suppress "Unsupported parameters" error in Ansible?

  27. 27

    how to suppress error from .vim plugin vimIM

  28. 28

    How can I suppress these error messages?

  29. 29

    How to suppress tar error messages in when piping

HotTag

Archive