Reputation: 21
When a camera is attached AND you supply VideoCapture
with an unmapped int DeviceID
, OpenCV outputs (to std::cout
, mind you) Unable to stop the stream: Invalid argument
.
How can I catch/suppress this?
Upvotes: 2
Views: 861
Reputation: 19041
You can use the cv::redirectError
function to handle any messages (such as asserts) yourself. For example, to simply silence the output, you could use the following piece of code:
#include <opencv2/opencv.hpp>
int dummy_error_handler(int status
, char const* func_name
, char const* err_msg
, char const* file_name
, int line
, void* userdata)
{
//Do nothing -- will suppress console output
return 0; //Return value is not used
}
void set_dummy_error_handler()
{
cv::redirectError(dummy_error_handler);
}
void reset_error_handler()
{
cv::redirectError(nullptr);
}
Note: If the actual message comes from another source, such as a third party library that OpenCV uses, a different approach will be necessary.
Upvotes: 2