I'm writing a multithreaded program using pthreads and opencv, and I'm having a problem where cvShowImage just appears as a blank gray rectangle (not even any window borders, completely blank).
To troubleshoot, I wrote two programs which should have identical results. one uses pthread, creates a single thread, and then displays an image, and closes. It produces the same problem, where just a gray rectangle appears.
The second program operates without pthread, with everything in main(), and works just fine. The two sample programs are below.
The operating system is OS X 10.8, and the opencv version is 2.4.6.1.
// first program: uses pthreads, cvShowImage produces only a blank rectangle
#include <stdio.h>
#include <pthread.h>
#include <highgui.h>
#include <cv.h>
int main()
{
pthread_t display_thread;
void *display_image();
pthread_create(&display_thread, NULL, display_image, NULL);
pthread_join(display_thread, NULL);
return 0;
}
void *display_image()
{
IplImage* image = cvLoadImage("map.png", CV_LOAD_IMAGE_COLOR);
cvNamedWindow("window", 0);
cvShowImage("window", image);
sleep(1);
cvDestroyAllWindows();
cvReleaseImage(&image);
pthread_exit(0);
}
// second program: works fine...
#include <stdio.h>
#include <highgui.h>
#include <cv.h>
int main()
{
IplImage* image = cvLoadImage("map.png", CV_LOAD_IMAGE_COLOR);
cvNamedWindow("window", 0);
cvShowImage("window", image);
sleep(1);
cvDestroyAllWindows();
cvReleaseImage(&image);
return 0;
}