Note: This happens even when you don't use OpenCV but since the below sketch uses it, I figured I'd post it here.
In my code, I have it so when a face is detected (line 74), it should display a gray rectangle and then wait for three seconds using a while loop (I'm testing using cues for a face-recognition based application). However, what happens is that the gray rectangle is not displayed until AFTER the while loop terminates.
Without even looking at your code I know what is wrong, looking at the sentence "wait for three seconds using a while loop" ! This error is so common that it is addressed in the Technical FAQ: see the articles in Sequencing and Timing.