Ask Your Question

zestysauce's profile - activity

2017-08-01 19:43:06 -0600 received badge  Nice Question (source)
2014-08-02 17:53:53 -0600 received badge  Student (source)
2014-08-02 17:53:45 -0600 received badge  Self-Learner (source)
2013-11-17 07:36:33 -0600 answered a question cvShowImage and pthreads

just moving "cvNamedWindow" into main() solved the problem...

2013-11-14 03:47:03 -0600 asked a question cvShowImage and pthreads

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;
}