1

In OpenCV, if I don't include Cv2.WaitKey(1) line in the display loop for captured images, no image is rendered on the screen. The same happens on C++, phyton, or C#.

What would be the cause for that, and is there another option?

This example is in C# (opencvsharp):

VideoCapture cap = new VideoCapture();

Window w = new Window();    

cap.Open("animation.avi");

while (cap.Read(src)) {
    Cv2.WaitKey(1);
    w.ShowImage(src);
}
Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
Flávio Filho
  • 475
  • 4
  • 14

1 Answers1

1

Technically highgui requires waitkey() to be called in order to get time to update the window.

From OpenCV documentation referring to imshow() function (ShowImage in C#):

This function should be followed by waitKey function which displays the image for specified milliseconds. Otherwise, it won’t display the image. For example, waitKey(0) will display the window infinitely until any keypress (it is suitable for image display). waitKey(25) will display a frame for 25 ms, after which display will be automatically closed. (If you put it in a loop to read videos, it will display the video frame-by-frame)

And about waitKey() function (WaitKey() in C#):

This function is the only method in HighGUI that can fetch and handle events, so it needs to be called periodically for normal event processing unless HighGUI is used within an environment that takes care of event processing.

Luca Angioloni
  • 2,243
  • 2
  • 19
  • 28