From caa2c06e504eacae36fdbe23b9c09890148e5a67 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Wed, 23 Jan 2013 12:27:30 +0400 Subject: [PATCH] Quiet output of cv::error in Java tests Introduced new Java API void org.opencv.core.Core.setErrorVerbosity(boolean verbose) used to suppress output to stderr from OpenCV's asserts --- modules/core/src/system.cpp | 2 +- modules/java/generator/src/cpp/common.h | 4 ++ modules/java/generator/src/cpp/core_manual.cpp | 15 +++++++ modules/java/generator/src/cpp/core_manual.hpp | 7 +++ .../test/src/org/opencv/test/OpenCVTestCase.java | 52 +++++++++++----------- 5 files changed, 54 insertions(+), 26 deletions(-) create mode 100644 modules/java/generator/src/cpp/core_manual.cpp diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index b3a136b..a891e94 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -439,7 +439,7 @@ void error( const Exception& exc ) exc.func.c_str() : "unknown function", exc.file.c_str(), exc.line ); fprintf( stderr, "%s\n", buf ); fflush( stderr ); -# ifdef ANDROID +# ifdef __ANDROID__ __android_log_print(ANDROID_LOG_ERROR, "cv::error()", "%s", buf); # endif } diff --git a/modules/java/generator/src/cpp/common.h b/modules/java/generator/src/cpp/common.h index 56217e4..b67f633 100644 --- a/modules/java/generator/src/cpp/common.h +++ b/modules/java/generator/src/cpp/common.h @@ -22,6 +22,10 @@ #include "converters.h" +#include "core_manual.hpp" +#include "features2d_manual.hpp" + + #ifdef _MSC_VER # pragma warning(disable:4800 4244) #endif diff --git a/modules/java/generator/src/cpp/core_manual.cpp b/modules/java/generator/src/cpp/core_manual.cpp new file mode 100644 index 0000000..d7ba5b9 --- /dev/null +++ b/modules/java/generator/src/cpp/core_manual.cpp @@ -0,0 +1,15 @@ +#define LOG_TAG "org.opencv.core.Core" +#include "common.h" + +static int quietCallback( int, const char*, const char*, const char*, int, void* ) +{ + return 0; +} + +void cv::setErrorVerbosity(bool verbose) +{ + if(verbose) + cv::redirectError(0); + else + cv::redirectError((cv::ErrorCallback)quietCallback); +} \ No newline at end of file diff --git a/modules/java/generator/src/cpp/core_manual.hpp b/modules/java/generator/src/cpp/core_manual.hpp index 28d29e0..a2fc627 100644 --- a/modules/java/generator/src/cpp/core_manual.hpp +++ b/modules/java/generator/src/cpp/core_manual.hpp @@ -2,6 +2,13 @@ #include "opencv2/core/core.hpp" +namespace cv +{ + +CV_EXPORTS_W void setErrorVerbosity(bool verbose); + +} + #if 0 namespace cv diff --git a/modules/java/test/src/org/opencv/test/OpenCVTestCase.java b/modules/java/test/src/org/opencv/test/OpenCVTestCase.java index 15ff735..ac1bf86 100644 --- a/modules/java/test/src/org/opencv/test/OpenCVTestCase.java +++ b/modules/java/test/src/org/opencv/test/OpenCVTestCase.java @@ -96,31 +96,33 @@ public class OpenCVTestCase extends TestCase { protected void setUp() throws Exception { super.setUp(); - try { - System.loadLibrary("opencv_java"); - } catch (SecurityException e) { - System.out.println(e.toString()); - System.exit(-1); - } catch (UnsatisfiedLinkError e) { - System.out.println(e.toString()); - System.exit(-1); - } - - String pwd; - try { - pwd = new File(".").getCanonicalPath() + File.separator; - } catch (IOException e) { - System.out.println(e); - return; - } - - OpenCVTestRunner.LENA_PATH = pwd + "res/drawable/lena.jpg"; - OpenCVTestRunner.CHESS_PATH = pwd + "res/drawable/chessboard.jpg"; - OpenCVTestRunner.LBPCASCADE_FRONTALFACE_PATH = pwd + "res/raw/lbpcascade_frontalface.xml"; - - assert(new File(OpenCVTestRunner.LENA_PATH).exists()); - assert(new File(OpenCVTestRunner.CHESS_PATH).exists()); - assert(new File(OpenCVTestRunner.LBPCASCADE_FRONTALFACE_PATH).exists()); + try { + System.loadLibrary("opencv_java"); + } catch (SecurityException e) { + System.out.println(e.toString()); + System.exit(-1); + } catch (UnsatisfiedLinkError e) { + System.out.println(e.toString()); + System.exit(-1); + } + + Core.setErrorVerbosity(false); + + String pwd; + try { + pwd = new File(".").getCanonicalPath() + File.separator; + } catch (IOException e) { + System.out.println(e); + return; + } + + OpenCVTestRunner.LENA_PATH = pwd + "res/drawable/lena.jpg"; + OpenCVTestRunner.CHESS_PATH = pwd + "res/drawable/chessboard.jpg"; + OpenCVTestRunner.LBPCASCADE_FRONTALFACE_PATH = pwd + "res/raw/lbpcascade_frontalface.xml"; + + assert(new File(OpenCVTestRunner.LENA_PATH).exists()); + assert(new File(OpenCVTestRunner.CHESS_PATH).exists()); + assert(new File(OpenCVTestRunner.LBPCASCADE_FRONTALFACE_PATH).exists()); dst = new Mat(); assertTrue(dst.empty()); -- 2.7.4