tags:

views:

329

answers:

1

Hello, As the title suggests I'm simply trying to get a named window to come up. I've been working with OpenCV for over a year now, and never had this problem before. For some reason, the window never opens. I've tried running some of my old scripts and everything works fine.

As a very cut down example, see below

#include "cv.h"
#include "highgui.h"

int main(int argc, char** argv) {

    cvNamedWindow( "video", 0 );
    IplImage *im = cvCreateImage( cvSize(200,200), 8, 3 );
    while(1) {
     cvShowImage( "video", im );
    }

    return 0;
}

I can see no reason why that wouldn't work, but for some reason the window never appears. Has anyone else experienced this? It's doing my head in!

+1  A: 

Simply call cvWaitKey() within the loop. This function notifies the GUI system to run graphics pending events. Yout code should be something like:

int main(int argc, char** argv) {

cvNamedWindow( "video", 0 );
IplImage *im = cvCreateImage( cvSize(200,200), 8, 3 );
while(1) {
    cvShowImage( "video", im );
    cvWaitKey(100); //wait for 100 ms for user to hit some key in the window
}

return 0;

}

claudi