0

The issue of this question has already been discussed e.g. for

The OpenCV documentation describes

ErrorCallback cv::redirectError     (   ErrorCallback   errCallback,
        void *      userdata = 0,
        void **     prevUserdata = 0 
    )   

How can this be made to use to e.g. filter out annoying messages?

An example is

[mjpeg @ 0x7fe5a696ea00] unable to decode APP fields: Invalid data found when processing input

from a Logitech USB Webcam mjpeg stream which is created on every single frame and is superflous and not needed.

There is also a loglevel available. Unfortunately the import org.opencv.utils only contains "Converters" but no logging as of OpenCV 3.4.8

How could the loglevel be set from Java?

enum    LogLevel {
  LOG_LEVEL_SILENT = 0,
  LOG_LEVEL_FATAL = 1,
  LOG_LEVEL_ERROR = 2,
  LOG_LEVEL_WARNING = 3,
  LOG_LEVEL_INFO = 4,
  LOG_LEVEL_DEBUG = 5,
  LOG_LEVEL_VERBOSE = 6
}

Would Redirect System.out and System.err to slf4j help?

Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186
  • IIRC, the message you provide as an example is not from OpenCV, it's from ffmpeg, which just writes it to standard error stream. – Dan Mašek Jan 25 '20 at 15:48
  • @DanMašek thx it would see https://stackoverflow.com/a/35215447/1497139 points in the right direction then. But how can this be achieved in the OpenCV scenario where ffmpeg is embedded as a library? – Wolfgang Fahl Jan 26 '20 at 07:35
  • 1
    see https://github.com/opencv/opencv/issues/12780 – Wolfgang Fahl Jan 27 '20 at 09:25

1 Answers1

0

How can this be made to use to e.g. filter out annoying messages? How could the loglevel be set from Java?

At this time (2020-01) it can't. Even if the API would be accessible from Java the bug https://github.com/opencv/opencv/issues/12780 would prevent it.

Would [Redirect System.out and System.err to slf4j][5] help?

No - see Junit test case below. The result is:

11:05:56.407 [main] DEBUG u.o.l.s.c.SysOutOverSLF4JInitialiser - Your logging framework class ch.qos.logback.classic.Logger should not need access to the standard println methods on the console, so you should not need to register a logging system package.
11:05:56.417 [main] INFO  u.o.l.s.context.SysOutOverSLF4J - Replaced standard System.out and System.err PrintStreams with SLF4JPrintStreams
11:05:56.420 [main] INFO  u.o.l.s.context.SysOutOverSLF4J - Redirected System.out and System.err to SLF4J for this context
11:05:56.421 [main] ERROR org.rcdukes.roi.TestROI - testing stderr via slf4j
[mjpeg @ 0x7f958b1b0400] unable to decode APP fields: Invalid data found when processing input
[mjpeg @ 0x7f958b027a00] unable to decode APP fields: Invalid data found when processing input

where the decode APP field part is still showing up via some stderr magic.

  @Test
  public void testLogStderr() throws Exception {
    NativeLibrary.logStdErr();
    System.err.println("testing stderr via slf4j");
    NativeLibrary.load();
    VideoCapture capture = new VideoCapture();
    // Dorf Appenzell
    //String url="http://213.193.89.202/axis-cgi/mjpg/video.cgi";
    // Logitech Cam on test car
    // url="http://picarford:8080/?action=stream";
    File imgRoot = new File(testPath);
    File testStream=new File(imgRoot,"logitech_test_stream.mjpg");
    assertTrue(testStream.canRead());
    capture.open(testStream.getPath());
    Mat image=new Mat();
    capture.read(image);
    assertEquals(640,image.width());
    assertEquals(480,image.height());
    capture.release();
  }

Funny side fact

According to the ffmpeg documentation Log coloring can be disabled setting the environment variable AV_LOG_FORCE_NOCOLOR or NO_COLOR, or can be forced setting the environment variable AV_LOG_FORCE_COLOR. The use of the environment variable NO_COLOR is deprecated and will be dropped in a future FFmpeg version

But there seems to be no option to change the Logging level from an environment variable ...

Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186