Cannot handle cv::imshow gtk warning

595 views Asked by At

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.

0

There are 0 answers