I've got some code that isn't working as intended. I have an application that uses imshow() to display an image, but I also want the program to still work if there is no display. For this reason I am trying to catch the exception from imshow (GTK-Warning: cannot open display) and continue the program without it (the bool 'display' is checked at every imshow() call).
//Display
bool display{false};
try{
std::cout << "Attempting to open display..." << std::endl;
cv::resize(image,modimage1,cv::Size(800,480));
cv::namedWindow("Output", CV_WINDOW_NORMAL);
cv::setWindowProperty("Output", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLS$
cv::imshow("Output", modimage1);
cv::waitKey(1);
display = true;
} catch( cv::Exception& e ){
const char* err_msg = e.what();
std::cout << "exception caught:" << err_msg << std::endl;
std::cout << "Failed to launch display, running without visual..." << s$
}
The catch block is copied right out of the opencv documentation, so I'm surprised that it doesn't catch the exception. The program behaves exactly as it did without the try block. The last output is "Attempting to open display" then I get the "GTK-Warning" and it exits the program.
So, what's missing? Am I catching the wrong error type? Is the exception not actually thrown by openCV but GTK/X/?
Thanks