How to suppress OpenCV warnings

I am trying to run the following code:

int main(int argc, char** argv )
{
    cv::redirectError(cvNulDevReport);
    std::string address(argv[1]);
    cv::VideoCapture cap(address); // open the camera
    if(!cap.isOpened())  // check if we succeeded
    {
        std::cerr<<"Error: Could not connect to camera.";
        return 0;
    }
    ...
}

      

Now I know that whenever the resource referenced by argv [1] does not exist, I get a warning like

warning: Error opening file (../../modules/highgui/src/cap_ffmpeg_impl.hpp:545)

      

I want this and any other warning or error to be output to the console because I want to provide a simpler, more understandable error. As I understand it, calling cv :: redirectError should work. I also tried to make a dummy error handler function and call cv :: redirectError with a pointer to that function, but I still get the same warning.

Looking at the source code of the file pointed to by the warning, I see that it is the CV_WARN macro, which is overridden, which, looking from the same source file, is either a call to fprintf or nothing.

Any help is appreciated.

+3


source to share





All Articles