Can OpenCV be made to work with the following code, modified from here:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <thread>
using namespace cv;
using namespace std;
void showWindow(std::string const &name, cv::Mat const &img)
{
cv::namedWindow(name, cv::WINDOW_AUTOSIZE);
cv::imshow(name, img);
}
int main( int argc, char** argv )
{
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR);
if(! image.data )
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
std::thread t1(showWindow, "Display window", image);
t1.join();
waitKey(0);
return 0;
}
Compiled with g++ -std=c++11 -g opencv.cpp -o app `pkg-config --cflags --libs opencv`
. My actual example is much more complex, but this is a MCVE.
The program hangs, and pressing CTRL+C
in gdb
gives me:
Program received signal SIGINT, Interrupt.
0x00007ffff6a7dd4d in nanosleep () at ../sysdeps/unix/syscall-template.S:81
81 ../sysdeps/unix/syscall-template.S: No such file or directory.
(gdb) bt
#0 0x00007ffff6a7dd4d in nanosleep () at ../sysdeps/unix/syscall-template.S:81
#1 0x00007ffff6aaefd4 in usleep (useconds=<optimised out>) at ../sysdeps/unix/sysv/linux/usleep.c:32
#2 0x00007ffff7bafe1e in cvWaitKey () from /usr/local/lib/libopencv_highgui.so.3.2
#3 0x00007ffff7baa2c6 in cv::waitKey(int) () from /usr/local/lib/libopencv_highgui.so.3.2
#4 0x0000000000401970 in main (argc=3, argv=0x7fffffffd418) at opencv.cpp:31
I tried rebuilding with WITH_TBB=ON
but it made no difference.