The link is the way I use setMouseCallBack in my class. Before this, I show only images without problem. Showing image no longer work after I added waitKey(0) into the code, see the one behind setMouseCallBack. Mouse action was not captured without using this waitkey(0).
cv::namedWindow("L");
cv::setMouseCallback("L", onMouse, this);
cv::waitKey(0);
for (size_t i = 0; i < corners.size(); i++)
{
circle(copy, corners[i], radius, cv::Scalar(moRNG.uniform(0, 255), moRNG.uniform(0, 256), moRNG.uniform(0, 256)), cv::FILLED);
cv::imshow("L", copy);
cv::waitKey(1);
} // end for
imshow windows only work while waitKey is executing.
waitKey(0) waits (forever) until a key is pressed.
waitKey(1) waits at most a millisecond or so, then it’s done and returning.
there must not be any waitKey calls inside of event handlers. they don’t belong there. they belong in a single thread, the main thread (other threads sometimes allowed, but always exactly one).
please post complete but minimal code to reproduce your issue. the code you posted here lacks the mouse callback function. the code on stackoverflow contains a bunch of stuff that is clearly irrelevant to the issue, hence a distraction.