n00dle
n00dle

Reputation: 6043

OpenCV cvNamedWindow not appearing under Fedora

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!

Upvotes: 0

Views: 3297

Answers (1)

claudi
claudi

Reputation: 36

Simply call cvWaitKey(int milliseconds) within the loop. This function notifies the GUI system to run graphics pending events. Your 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;
}

Upvotes: 2

Related Questions