0

On a headless test machine (Travis CI), while using cv::imshow I get a program crash and display:

Gtk-WARNING **: cannot open display: 

The message seems normal. But I can not succeed in catching the error!

I tried with that code:

    try
    {
        // create a window for display.
        cv::namedWindow( name, CV_WINDOW_AUTOSIZE );
        // Show our image inside it.
        cv::imshow( name, img );

        // take time to effectively display the image
        cv::waitKey(1000);
    }
    catch (cv::Exception& e)
    {
        std::cout << "OpenCV GUI not able to pop up: " << e.what() << 
                "\nProbably executing on a headless test machine? " << std::endl;
    }

... and even with

catch (...)

without success.

Any help would... help!

Thank you


Edit: I found a workaround here: https://github.com/itseez-academy/itseez-ws-2016-practice/blob/master/.travis.yml using xvfb in order to not let cv::imshow (or cv::namedWindow) raise the "no display" error... In fact, it does not really solve the issue that I have not being able to catch the gtk error.

Grumot
  • 81
  • 1
  • 7
  • GTK+ does not throw C++ exceptions. We will need to see more code. – andlabs Jan 09 '17 at 11:59
  • Thank you @andlabs. OK, then it seems that it is the way that openCV highGui uses gtk+ that would not allow to catch errors. My code is encapsulated in some poco (pocoproject.org) threading tools. I get the error from some poco reporting, but I do not know really when, and how since threads are also probably created by openCV or gtk+ themselves(?) – Grumot Jan 09 '17 at 12:13
  • If you are interested in catching GTK+ logger messages, you can set a breakpoint on the `g_logv()` function, which is the entry point to the GLib logging system. In some cases, like `gtk_init()` (which is where that particular message comes from), there is an alternate version of the function that OpenCV could call if it wanted to get an error object back and throw *that*; I guess it chooses not to. As for "cannot open display", GTK+ is trying to connect to X11 but can't (because your test environment is headless). Not sure what to do about that... – andlabs Jan 09 '17 at 13:36
  • Ok, thank you very much for those precisions. Great. – Grumot Jan 09 '17 at 14:35

0 Answers0