title: cv2 face detection problem when no face was detected
body: <p>I have an application where I try to detect faces and print Hi! when face is detected. My problem is that even if the face (human) moves away from visible area, the message doesn't change. I want to print &quot;no faces found&quot; in that case.</p>
  <p>How can I make an action when no face is detected, whether print something or other kind of notification as sound.</p>
  <p>The code I have made so far:</p>
  <pre><code>import cv2
  cascPath = &quot;haarcascade_frontalface_default.xml&quot;
  faceCascade = cv2.CascadeClassifier(cascPath)
  cap = cv2.VideoCapture(0)
  
  while 1:
  
      ret, img = cap.read()
      gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
      faces = faceCascade.detectMultiScale(gray, 1.3, 5)
      if len(faces) == 0:
          print
          &quot;No faces found&quot;
      for (x,y,w,h) in faces:
          re = cv2.rectangle(img,(x,y),(x+w,y+h),(200,200,0),2)
          if 're' in locals():
              print('Hi')
          else:
              print('No faces found')
          roi_gray = gray[y:y+h, x:x+w]
          roi_color = img[y:y+h, x:x+w]
      cv2.imshow('Hi',img)
  
      # Wait for Esc key to stop
      k = cv2.waitKey(30)
      if k == 13:
          break
  cap.release()
  cv2.destroyAllWindows()
  </code></pre>