Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Why is this happening?

imshow() only sets a pointer to the image, the real drawing happens in waitKey()

(the windows internal event-loop is triggered from there)

so, it's just a matter of order:

Mat src = imread("toy.png");
imshow("Source", src);
waitKey(1); // wait only a very short time

scanf_s("%s", in, sizeof in); // get your input 

// some more processing ...

waitKey(); // wait forever now (don't let the prog close the window)

Why is this happening?

imshow() only sets a pointer to the image, the real drawing happens in waitKey()

(the windows window's internal event-loop is triggered from there)

so, it's just a matter of order:

Mat src = imread("toy.png");
imshow("Source", src);
waitKey(1); // wait only a very short time

scanf_s("%s", in, sizeof in); // get your input 

// some more processing ...

waitKey(); // wait forever now (don't let the prog close the window)