def show_frame():
    _, frame = cap.read()
    frame = cv2.flip(frame, 1)
    if frame is not None:
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        face = face_cascade.detectMultiScale(gray, scaleFactor=1.2, minNeighbors=5, minSize=(20, 20))
        rect = bb_to_rect(face)

        if len(face) > 0:
            shape1 = predictor(gray, rect.bb_to_rect_gen())
            shape = face_utils.shape_to_np(shape1)
            text = "{} face(s) found".format(len(face))
            cv2.putText(frame, text, (10, 30), cv2.FONT_HERSHEY_SIMPLEX,
                        0.5, (0, 0, 255), 2)

        for (x, y, w, h) in face:
            cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)

            for (xx, yy) in shape:
                cv2.circle(frame, (xx, yy), 1, (0, 0, 255), 5)

        cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
        img = Image.fromarray(cv2image)
        imgtk = ImageTk.PhotoImage(image=img)
        capturearea.imgtk = imgtk
        capturearea.configure(image=imgtk)
        capturearea.after(10, show_frame)
        parameter_output = get_parameter_output(shape)
        var.set(parameter_output)
def read_image():
    file_path = 'cmp/user.jpg'
    image = cv2.imread(file_path)
    height, width, _ = image.shape
    print(image.shape)
    rect = bb_to_rect([[0, 0, width, height]])
    shape1 = predictor(image, rect.bb_to_rect_gen())
    al_final = preprocess_technique_using_triangle(image, shape1)
    return al_final
def capture_face(frame):
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    face = face_cascade.detectMultiScale(gray, scaleFactor=1.2, minNeighbors=5, minSize=(20, 20))
    rect = bb_to_rect(face)

    shape1 = predictor(gray, rect.bb_to_rect_gen())
    shape = face_utils.shape_to_np(shape1)
    align = alignments(predictor=shape1, predictor_shape_np=shape, image=gray)
    al = align.align()

    cv2.imwrite('cmp/user.jpg', al)
    parameter_output = get_parameter_output(shape)
    text_file = open("cmp/parameter_output.txt", "wt")
    n = text_file.write(parameter_output)
    text_file.close()