c++ - OpenCV - 禁用打印异常

标签 c++ opencv error-handling

我是 OpenCV 的新手,但现在我需要捕获 cv:Exception。我做了 try 和 catch block :

try{
    //do some opencv things
}
catch (cv::Exception& e){
    cout << "OpenCV error: " << endl << e.what();
    cin.get();
}

效果很好,我可以捕获异常。但是异常消息被写入了两次。一个来自 opencv 库,第二个来 self 。

有什么方法可以禁止从 opencv 向 stderr 发送消息吗?我制作了发布版本 - 将 VS2013 更改为 Release 并从所有库的名称中删除了“d”。但是还是写了两次。

最佳答案

您可以使用 cvRedirectError覆盖 OpenCV 的默认错误处理。

你可以使用它like this :

int myErrorHandler(int status, const char* func_name, const char* err_msg, 
                   const char* file_name, int line, void*)
{
    // Do whatever you want here
    return 0;
}

cvRedirectError(myErrorHandler); ///< Call this once somewhere

这是恢复默认行为的方式:

cv::redirectError(cv::ErrorCallback())

关于c++ - OpenCV - 禁用打印异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28841400/

相关文章:

c# - C#中对象的碰撞检测

c++ - 是否可以将 for(auto i=0;i<n;i++) ... 替换为 for(auto i :<something>) without using a vector?

python - OpenCV 2.4.0 python 绑定(bind)中的 ORB

c++ - "int &&"和 "auto &&"之间的不同行为

android - 使用android的OpenCV构建库在 “not building target XXX because there was no build command for it”上失败

java - 如何在 java 中检查 MatOfKeyPoint?

unit-testing - 从批处理文件设置错误级别

excel - 跳过类型不匹配

c++ - CMakelist.txt 将外部标题和文件包含在文件夹中(boost 中的 odeint)

c++ - 如何在 Visual Studio 中使用有关 header 路径的 C++ 库的依赖项