text: import click
  import os
  import re
  import face_recognition.api as face_recognition
  import multiprocessing
  import itertools
  import sys
  import PIL.Image
  import numpy as np
  import face_recognition
  import cv2
  
  # This is a super simple (but slow) example of running face recognition on live video from your webcam.
  # There's a second example that's a little more complicated but runs faster.
  
  # PLEASE NOTE: This example requires OpenCV (the `cv2` library) to be installed only to read from your webcam.
  # OpenCV is *not* required to use the face_recognition library. It's only required if you want to run this
  # specific demo. If you have trouble installing it, try any of the other demos that don't require it instead.
  
  # Get a reference to webcam #0 (the default one)
  video_capture = cv2.VideoCapture(0)
  print('test')
  '''
  # Load a sample picture and learn how to recognize it.
  obama_image = face_recognition.load_image_file("obama.jpg")
  obama_face_encoding = face_recognition.face_encodings(obama_image)[0]
  
  # Load a second sample picture and learn how to recognize it.
  biden_image = face_recognition.load_image_file("biden.jpg")
  biden_face_encoding = face_recognition.face_encodings(biden_image)[0]
  
  # Load a second sample picture and learn how to recognize it.
  songzibo_image = face_recognition.load_image_file("songzibo.jpg")
  songzibo_face_encoding = face_recognition.face_encodings(songzibo_image)[0]
  
  # Create arrays of known face encodings and their names
  known_face_encodings = [
      obama_face_encoding,
      biden_face_encoding,
      songzibo_face_encoding
  ]
  known_face_names = [
      "Barack Obama",
      "Joe Biden",
      "songzibo"
  ]
  '''
  def scan_known_people(known_people_folder):
      known_names = []
      known_face_encodings = []
  
      for file in image_files_in_folder(known_people_folder):
          basename = os.path.splitext(os.path.basename(file))[0]
          img = face_recognition.load_image_file(file)
          encodings = face_recognition.face_encodings(img)
  
          if len(encodings) > 1:
              click.echo("WARNING: More than one face found in {}. Only considering the first face.".format(file))
  
          if len(encodings) == 0:
              click.echo("WARNING: No faces found in {}. Ignoring file.".format(file))
          else:
              known_names.append(basename)
              known_face_encodings.append(encodings[0])
  
      return known_names, known_face_encodings
  
  
  def print_result(filename, name, distance, show_distance=False):
      if show_distance:
          print("{},{},{}".format(filename, name, distance))
      else:
          print("{},{}".format(filename, name))
  
  
  def test_image(image_to_check, known_names, known_face_encodings, tolerance=0.6, show_distance=False):
      unknown_image = face_recognition.load_image_file(image_to_check)
  
      # Scale down image if it's giant so things run a little faster
      if max(unknown_image.shape) > 1600:
          pil_img = PIL.Image.fromarray(unknown_image)
          pil_img.thumbnail((1600, 1600), PIL.Image.LANCZOS)
          unknown_image = np.array(pil_img)
  
      unknown_encodings = face_recognition.face_encodings(unknown_image)
  
      for unknown_encoding in unknown_encodings:
          distances = face_recognition.face_distance(known_face_encodings, unknown_encoding)
          result = list(distances <= tolerance)
  
          if True in result:
              [print_result(image_to_check, name, distance, show_distance) for is_match, name, distance in zip(result, known_names, distances) if is_match]
          else:
              print_result(image_to_check, "unknown_person", None, show_distance)
  
  
  def image_files_in_folder(folder):
      return [os.path.join(folder, f) for f in os.listdir(folder) if re.match(r'.*\.(jpg|jpeg|png)', f, flags=re.I)]
  
  
  def process_images_in_process_pool(images_to_check, known_names, known_face_encodings, number_of_cpus, tolerance, show_distance):
      if number_of_cpus == -1:
          processes = None
      else:
          processes = number_of_cpus
  
      # macOS will crash due to a bug in libdispatch if you don't use 'forkserver'
      context = multiprocessing
      if "forkserver" in multiprocessing.get_all_start_methods():
          context = multiprocessing.get_context("forkserver")
  
      pool = context.Pool(processes=processes)
  
      function_parameters = zip(
          images_to_check,
          itertools.repeat(known_names),
          itertools.repeat(known_face_encodings),
          itertools.repeat(tolerance),
          itertools.repeat(show_distance)
      )
  
      pool.starmap(test_image, function_parameters)
  
  
  
  known_face_names, known_face_encodings = scan_known_people('./knownmans')
  face_count = 0
  
  while True:
      # Grab a single frame of video
      ret, frame = video_capture.read()
      
      # Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses)
      rgb_frame = frame[:, :, ::-1]
  
      # Find all the faces and face enqcodings in the frame of video
      face_locations = face_recognition.face_locations(rgb_frame, model="cnn")
      face_encodings = face_recognition.face_encodings(rgb_frame, face_locations)
  
      # Loop through each face in this frame of video
      for (top, right, bottom, left), face_encoding in zip(face_locations, face_encodings):
          # See if the face is a match for the known face(s)
          matches = face_recognition.compare_faces(known_face_encodings, face_encoding, tolerance=0.30)
  
          name = "Unknown"
          
          
          # If a match was found in known_face_encodings, just use the first one.
          if True in matches:
              first_match_index = matches.index(True)
              name = known_face_names[first_match_index]
              print(name)
              picture_save_dir = os.path.join(os.path.abspath(os.getcwd()), str(name))
          else:
              picture_save_dir = os.path.join(os.path.abspath(os.getcwd()), 'unkonwn')
          
  #        print(picture_save_dir)
  #        if os.path.exists(picture_save_dir):
  #            print('save dir exist')
  #        else:
  #            print('make picture save dir = ', picture_save_dir)
  #            os.makedirs(picture_save_dir)
          
          if not os.path.exists(picture_save_dir):
              os.makedirs(picture_save_dir)
          
          print("save to ", picture_save_dir)
          
          face_count = face_count + 1
          picture_file_name = name + str(face_count) + '.jpg'
          picture_file_dir = os.path.join(picture_save_dir, picture_file_name)
          print("file is ", picture_file_dir)
          image = frame[top: bottom, left: right]
          cv2.imwrite(picture_file_dir, image, [int(cv2.IMWRITE_JPEG_QUALITY), 80])
          
          # Draw a box around the face
          cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)
  
          # Draw a label with a name below the face
          cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
          font = cv2.FONT_HERSHEY_DUPLEX
          cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1)
  
      # Display the resulting image
      cv2.imshow('Video', frame)
  
      # Hit 'q' on the keyboard to quit!
      if cv2.waitKey(1) & 0xFF == ord('q'):
          break
  
  # Release handle to the webcam
  video_capture.release()
  cv2.destroyAllWindows()
  