7

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 referred to by argv[1] is not there, I will get a warning like

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

What I want is to suppress this and any other warning or error from console output, because I want to supply a simple, more comprehensible error myself. As I understand, the call to cv::redirectError should have worked. I have also tried making a dummy error handler function and calling 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 warning, I see that it is CV_WARN macro that is substitued, which, looking from the same source file, is either a call to fprintf or nothing.

Any help is appreciated.

oczkoisse
  • 1,561
  • 3
  • 17
  • 31
  • Possible duplicate of [How to suppress OpenCV error message](https://stackoverflow.com/questions/17567808/how-to-suppress-opencv-error-message) – cbuchart May 25 '17 at 16:12

0 Answers0