import cv2

def main():

  cascade_data = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

  # init video device
  cap = cv2.VideoCapture(0)

  # Frame capture loop
  while(True):
     # Capture frame-by-frame
     _, frame = cap.read()

     # Our operations on the frame come here
     gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

     faces = cascade_data.detectMultiScale(gray, 1, 4)

     for (x, y, z, w) in faces:
        cv2.rectangle(img, (x, y), (x + w, y+h), (0, 0, 255))

     # Display the resulting frame
     cv2.imshow('frame',gray)

     if cv2.waitKey(1) & 0xFF == ord('q'):
        break

  # When everything done, release the capture
  cap.release()
  cv2.destroyAllWindows()


if __name__ == "__main__":
      main()