>>620
while(1)
{
...
int c = waitKey(1);
if(c == 'q') break;
}