How to disable OpenCV debug logging in a C++ console application?

Viewed 25

I'm coding a small interactive console app with C++ in which you can apply filters on images using opencv. The user can preview the image with the filters using this code:

cv::Mat img; // image is loaded beforehand, filters may be applied

cv::imshow("Preview", img);

The cv::imshow() function triggers some logging in the background which is output to the console. I don't have any use of the logs and they take up a lot of space in the console, with which the user mainly interacts.

I'd rather not have that output at all. What's the best way to disable such console logging?

1 Answers

You can set the OpenCV logging level in the cv::utils::logging namespace:

// First, add this necessary using
#include <opencv2/core/utils/logger.hpp>

// Then you can set the logging level with this function
cv::utils::logging::setLogLevel(cv::utils::logging::LogLevel::LOG_LEVEL_SILENT);

You can of course also set it to any other level, adjusted to your needs.

Related