6

I'd like to get the logs out of OpenCV, in particular those from CV_LOG_WARNING calls but I haven't been able to find if there is an environment variable I can set or if there is a setting in the CMakeLists file that will enable this is I build OpenCV from source.

Setup: OpenCV 4 Cross compiling on Ubuntu 16.04 for an Arm based hardware platform

How do I enable this?

Rod Burns
  • 1,821
  • 11
  • 23
  • Looking at the [implementation](https://github.com/opencv/opencv/blob/4.0.0/modules/core/src/logger.cpp#L74), on anything other than android, it just writes to standard streams with no means of overriding that. Could definitely use a patch. If you're fine with logging to streams and just want to change the log level, then `setLogLevel` seems to be what you're looking for. – Dan Mašek Feb 22 '19 at 14:22
  • Thanks for the tip. I set the log level using that method but I'm not seeing anything. Are the logs shown in the console or do I need to setup a file or something else to capture them? – Rod Burns Feb 22 '19 at 16:05
  • I think perhaps I need a debug build of OpenCV to get this. – Rod Burns Feb 22 '19 at 16:07
  • If it's logging, it should go to console. | See [here](https://github.com/opencv/opencv/blob/4.0.0/modules/core/include/opencv2/core/utils/logger.hpp#L54) -- looks like you can control it with `CV_LOG_STRIP_LEVEL`, and have logging even in non-debug build. – Dan Mašek Feb 22 '19 at 16:10

2 Answers2

7

First include:

#include <opencv2/core/utils/logger.hpp>

Then in the code, do this as one of the first calls:

cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_VERBOSE);
user2023370
  • 10,027
  • 5
  • 46
  • 77
jdex
  • 1,084
  • 1
  • 11
  • 19
  • Very helpful, thanks. I also came across the other parameters that can be provided to `setLogLevel` [here](https://docs.opencv.org/4.x/da/db0/namespacecv_1_1utils_1_1logging.html). For example: `cv::utils::logging::LOG_LEVEL_SILENT`. – user2023370 Feb 23 '22 at 11:17
2

OpenCV uses environment variables to enable logging. In Bash:

export OPENCV_LOG_LEVEL=DEBUG
export OPENCV_VIDEOIO_DEBUG=1
Cees Timmerman
  • 15,267
  • 10
  • 85
  • 116