Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不显示python OpenCV错误_Python_Opencv_Error Handling - Fatal编程技术网

不显示python OpenCV错误

不显示python OpenCV错误,python,opencv,error-handling,Python,Opencv,Error Handling,我将OpenCV与python结合使用,更具体地说,是使用cv2的findttransformecc功能来执行图像注册。如果算法不收敛,此函数可能会抛出错误。我用一个简单的尝试来捕捉错误。。。除了指令,我处理错误。但是OpenCV错误消息仍然显示在我的终端中,我想隐藏它。我该怎么办 这里有一个简单的例子 try: cc, warp_matrix = cv2.findTransformECC(img1, img2, warp_matrix) except cv2.error: cc

我将OpenCV与python结合使用,更具体地说,是使用
cv2
findttransformecc
功能来执行图像注册。如果算法不收敛,此函数可能会抛出错误。我用一个简单的
尝试来捕捉错误。。。除了
指令,我处理错误。但是OpenCV错误消息仍然显示在我的终端中,我想隐藏它。我该怎么办

这里有一个简单的例子

try:
    cc, warp_matrix = cv2.findTransformECC(img1, img2, warp_matrix)
except cv2.error:
    cc = 15;
    print("An error occured but it does not matter")

如果
findTrnaformECC
函数抛出am error,我的程序将正确输出我的自定义错误消息(
发生错误,但这并不重要
),但也会输出OpenCV错误(
OpenCV error:迭代不收敛)(算法在收敛之前停止。相关性将最小化。图像可能不相关或不重叠)在FindTransformeC中,file/home/travis/miniconda/conda bld/conda_1485299288502/work/opencv-3.2.0/modules/video/src/ecc.cpp,第530行
)我想阻止这种情况。

重定向
stderr
似乎不起作用,但它让我想到了从命令行重定向它,这在基于Unix的系统上非常有效


但是,这将隐藏应显示在
stderr
上的所有其他错误。这不是我的精确应用程序的问题,但可能是。

错误被写入
stderr
。因此您可以这样做。或者您可以告诉我,但我不知道
cv::redirectError
函数是否有Python绑定这似乎很好但重定向标准错误没有任何作用。。。
python myscript.py 2> /dev/null