text: 
  import cv2
  import os
  from matplotlib import pyplot as plt
  
  
  # new thread
  cv2.startWindowThread()
  
  def plt_show(image, title=""):
      if len(image.shape) == 3:
          image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
      plt.axis("off")
      plt.title(title)
      plt.imshow(image, cmap="Greys_r")
      plt.show()
  
  
  webcam = cv2.VideoCapture(0)
  _, frame = webcam.read()
  webcam.release()
  plt_show(frame)  
  
  
  # Face-Detection
  detector = cv2.CascadeClassifier("xml/frontal_face.xml")
  
  scale_factor = 1.2
  min_neighbors = 5
  min_size = (50, 50)
  biggest_only = True
  flags = cv2.CASCADE_FIND_BIGGEST_OBJECT |             cv2.CASCADE_DO_ROUGH_SEARCH if biggest_only else             cv2.CASCADE_SCALE_IMAGE
          
  faces_coord = detector.detectMultiScale(frame,
                                          scaleFactor=scale_factor,
                                          minNeighbors=min_neighbors,
                                          minSize=min_size,
                                          flags=flags)
  
  # Video-Camera
  class VideoCamera(object):
      def __init__(self, index=0):
          self.video = cv2.VideoCapture(index)
          self.index = index
          print (self.video.isOpened())
  
      def __del__(self):
          self.video.release()
      
      def get_frame(self, in_grayscale=False):
          _, frame = self.video.read()
          if in_grayscale:
              frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
          return frame
  
  # Face Detection
  class FaceDetector(object):
      def __init__(self, xml_path):
          self.classifier = cv2.CascadeClassifier(xml_path)
      
      def detect(self, image, biggest_only=True):
          scale_factor = 1.2
          min_neighbors = 5
          min_size = (75, 75)
          biggest_only = True
          flags = cv2.CASCADE_FIND_BIGGEST_OBJECT |                     cv2.CASCADE_DO_ROUGH_SEARCH if biggest_only else                     cv2.CASCADE_SCALE_IMAGE
          faces_coord = self.classifier.detectMultiScale(image,
                                                         scaleFactor=scale_factor,
                                                         minNeighbors=min_neighbors,
                                                         minSize=min_size,
                                                         flags=flags)
          return faces_coord
  
  # Live Face Detection
  webcam = VideoCamera(0) # front camera
  detector = FaceDetector("xml/frontal_face.xml")
  
  # crop images
  def cut_faces(image, faces_coord):
      faces = []
        
      for (x, y, w, h) in faces_coord:
          w_rm = int(0.2 * w / 2)
          faces.append(image[y: y + h, x + w_rm: x + w - w_rm])
           
      return faces
  
  # normalize images
  def normalize_intensity(images):
      images_norm = []
      for image in images:
          is_color = len(image.shape) == 3 
          if is_color:
              image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
          images_norm.append(cv2.equalizeHist(image))
      return images_norm
  
  # resize images
  def resize(images, size=(100, 100)):
      images_norm = []
      for image in images:
          if image.shape < size:
              image_norm = cv2.resize(image, size, 
                                      interpolation = cv2.INTER_AREA)
          else:
              image_norm = cv2.resize(image, size, 
                                      interpolation = cv2.INTER_CUBIC)
          images_norm.append(image_norm)
  
      return images_norm 
  
  # normalize face
  def normalize_faces(frame, faces_coord):
      faces = cut_faces(frame, faces_coord)
      faces = normalize_intensity(faces)
      faces = resize(faces)
      return faces
  
  # rectangle line
  def draw_rectangle(image, coords):
      for (x, y, w, h) in coords:
          w_rm = int(0.2 * w / 2) 
          cv2.rectangle(image, (x + w_rm, y), (x + w - w_rm, y + h), 
                                (200, 200, 0), 4)
  
  
  # get and save image        
  folder = "members/" + input('Name: ').lower() # input name
  cv2.namedWindow("Save Image", cv2.WINDOW_AUTOSIZE)
  if not os.path.exists(folder):
      os.mkdir(folder)
      counter = 1
      timer = 0
      while counter < 11 : # take 10 pictures
          frame = webcam.get_frame()
          faces_coord = detector.detect(frame) # detector
          if len(faces_coord) and timer % 700 == 50: # timer
              faces = normalize_faces(frame, faces_coord) # norm pipeline
              cv2.imwrite(folder + '/' + str(counter) + '.jpg', faces[0])
              plt_show(faces[0], "Images Saved:" + str(counter))
              counter += 1
          draw_rectangle(frame, faces_coord) # rectangle around face
          cv2.imshow("Save Image", frame) # show in external
          cv2.waitKey(50)
          timer += 50
      cv2.destroyAllWindows()
  else:
      print ("This name already exists.")
  
  del webcam