I would like to show an image in opencv. I create a window using "namedWindow" and show the image using "imshow". at the end of the code I use "cin" so the program does not quit automatically. part of my code looks like this:
namedWindow("image");
imshow("image",aa);
waitKey(500);
cin >> aaa;
return 0;
If I eliminate the waitKey statement, I cannot see the image. Why is it like that ? the next statement (cin >> aaa) is not executed after imshow is done ? why is a delay essential?
it's not so much the delay, that's essential, but more the hidden functionality inside waitkey.
imshow will just copy the image, but waitkey will finally blit it ( or , send out the messages to your os nessecary for doing so )
so you need to call waitkey in any case, if you use imshow. 1(millisecond) is the smallest value you can put here for continuous rendering, 0 or -1 will block until you press a key.
besides, waitkey listens to keypresses in that img-window, cin listens to input from the console window.
cv::WaitKEy(0) the image will stay there
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With