11

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
  • 2,104
  • 13
  • 24
  • 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

13

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,488
  • 6
  • 50
  • 83
jdex
  • 1,279
  • 1
  • 13
  • 20
  • 2
    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
10

OpenCV uses environment variables to enable logging. In Bash:

export OPENCV_LOG_LEVEL=DEBUG
export OPENCV_VIDEOIO_DEBUG=1
Cees Timmerman
  • 17,623
  • 11
  • 91
  • 124
  • 1
    This is the best answer - simpler and additionally this will also catch logging from CV_CAPTURE_LOG_DEBUG – Yost777 Dec 14 '22 at 16:15