Jelajahi Sumber

delete unused

kevin 2 tahun lalu
induk
melakukan
dfbe479533
5 mengubah file dengan 0 tambahan dan 344 penghapusan
  1. 0 92
      face_align.py
  2. 0 47
      take_picture.py
  3. 0 52
      take_picture_snn.py
  4. 0 99
      verify_face.py
  5. 0 54
      verify_face_2.py

+ 0 - 92
face_align.py

@@ -1,92 +0,0 @@
-import face_alignment
-from skimage import io
-import joblib
-import os
-from sklearn import svm
-import concurrent.futures
-import numpy as np
-import time
-
-fa = face_alignment.FaceAlignment(face_alignment.LandmarksType._2D, flip_input=False)
-
-# Training the SVC classifier
-
-# The training data would be all the face encodings from all the known images and the labels are their names
-encodings = []
-names = []
-tuples = []
-train_list = []
-lock = None
-
-is_train = False
-
-if not is_train:
-    try:
-        clf = joblib.load('saved_model_fa.pkl')
-    except:
-        clf = None
-    if clf is None:
-        is_train = True
-
-def train_image(image, person):
-    img = io.imread(image)
-    preds = fa.get_landmarks(img)
-
-    # If training image contains exactly one face
-    if len(preds) == 1:
-        tuples.append((preds[0].reshape(136), person))
-    else:
-        print(image + " was skipped and can't be used for training")
-
-if is_train:
-    # Training directory
-    train_str = os.path.join('data', 'peeps', 'anchor')
-    train_dir = os.listdir(os.path.join('data', 'peeps', 'anchor'))
-
-    # Loop through each person in the training directory
-    with concurrent.futures.ThreadPoolExecutor() as executor:
-        for person in train_dir:
-            pix_str = os.path.join(train_str, person)
-            pix = os.listdir(os.path.join(train_str, person))
-
-            # Loop through each training image for the current person
-            for person_img in pix:
-                # Get the face encodings for the face in each image file
-                image = os.path.join(pix_str, person_img)
-                executor.submit(train_image, image, person)
-
-    # Create and train the SVC classifier
-
-    encodings = [x for x, _ in tuples]
-    names = [y for _, y in tuples]
-
-    clf = svm.SVC(gamma='scale', probability=True)
-    clf.fit(encodings, names)
-    joblib.dump(clf, 'saved_model_fa.pkl')
-
-# Load the test image with unknown faces into a numpy array
-test_image = io.imread(os.path.join('application_data', 'input_image', 'input_image4.jpg'))
-
-# Find all the faces in the test image using the default HOG-based model
-face_locations = fa.get_landmarks(test_image)
-no = len(face_locations)
-print("Number of faces detected: ", no)
-
-# Predict all the faces in the test image using the trained classifier
-print("Found:")
-for i in range(no):
-    test_image_enc = face_locations[i].reshape(136)
-    start_time = time.perf_counter_ns()
-    proba = clf.predict_proba([test_image_enc])
-    end_time = time.perf_counter_ns()
-    process_time = end_time - start_time
-    classes = clf.classes_
-    print(classes)
-    i = np.argmax(proba)
-    proba = list(*proba)
-    name = classes[i]
-    print(name, "{:.2f}".format(proba[i]), proba, process_time)
-
-# input = io.imread(os.path.join('application_data','input_image','input_image.jpg'))
-# preds = fa.get_landmarks(input)
-# print(preds)

+ 0 - 47
take_picture.py

@@ -1,47 +0,0 @@
-import cv2
-import time
-
-key = cv2.waitKey(1)
-webcam = cv2.VideoCapture(0)
-while True:
-    try:
-        check, frame = webcam.read()
-        # print(check)  # prints true as long as the webcam is running
-        # print(frame)  # prints matrix values of each framecd
-        cv2.imshow("Capturing", frame)
-        key = cv2.waitKey(1)
-        if key == ord('s'):
-            ts = time.time()
-            cv2.imwrite(filename='saved_img-{}.jpg'.format(ts), img=frame)
-            # webcam.release()
-            # img_new = cv2.imread('saved_img.jpg', cv2.IMREAD_GRAYSCALE)
-            # img_new = cv2.imshow("Captured Image", img_new)
-            cv2.waitKey(500)
-            # cv2.destroyAllWindows()
-            # print("Processing image...")
-            # img_ = cv2.imread('saved_img.jpg', cv2.IMREAD_ANYCOLOR)
-            # print("Converting RGB image to grayscale...")
-            # gray = cv2.cvtColor(img_, cv2.COLOR_BGR2GRAY)
-            # print("Converted RGB image to grayscale...")
-            # print("Resizing image to 28x28 scale...")
-            # img_ = cv2.resize(gray, (28, 28))
-            # print("Resized...")
-            # img_resized = cv2.imwrite(filename='saved_img-final.jpg', img=img_)
-            print("Image saved!")
-
-            # break
-        elif key == ord('q'):
-            print("Turning off camera.")
-            webcam.release()
-            print("Camera off.")
-            print("Program ended.")
-            cv2.destroyAllWindows()
-            break
-
-    except(KeyboardInterrupt):
-        print("Turning off camera.")
-        webcam.release()
-        print("Camera off.")
-        print("Program ended.")
-        cv2.destroyAllWindows()
-        break

+ 0 - 52
take_picture_snn.py

@@ -1,52 +0,0 @@
-# Establish a connection to the webcam
-import uuid
-import cv2
-import os
-
-# Setup paths
-POS_PATH = os.path.join('data', 'positive')
-NEG_PATH = os.path.join('data', 'negative')
-ANC_PATH = os.path.join('data', 'anchor')
-
-cap = cv2.VideoCapture(0)
-CAMERA_OFFSET_X = 750
-CAMERA_OFFSET_Y = 250
-CAMERA_SIZE = 500
-FEED_SIZE = 250
-
-NAME = "kevin"
-while cap.isOpened():
-    ret, frame = cap.read()
-
-    # Cut down frame to 250x250px
-    frame = frame[CAMERA_OFFSET_Y:CAMERA_OFFSET_Y + CAMERA_SIZE, CAMERA_OFFSET_X:CAMERA_OFFSET_X + CAMERA_SIZE, :]
-
-    # Collect anchors
-    if cv2.waitKey(1) & 0XFF == ord('a'):
-        # Create the unique file path
-        imgname = os.path.join(ANC_PATH, '{}-{}.jpg'.format(NAME,uuid.uuid1()))
-        # Resize image
-        resized = cv2.resize(frame, (FEED_SIZE, FEED_SIZE))
-        # Write out anchor image
-        cv2.imwrite(imgname, resized)
-
-    # Collect positives
-    if cv2.waitKey(1) & 0XFF == ord('p'):
-        # Create the unique file path
-        imgname = os.path.join(POS_PATH, '{}-{}.jpg'.format(NAME,uuid.uuid1()))
-        # Resize image
-        resized = cv2.resize(frame, (FEED_SIZE, FEED_SIZE))
-        # Write out positive image
-        cv2.imwrite(imgname, resized)
-
-    # Show image back to screen
-    cv2.imshow('Image Collection', frame)
-
-    # Breaking gracefully
-    if cv2.waitKey(1) & 0XFF == ord('q'):
-        break
-
-# Release the webcam
-cap.release()
-# Close the image show frame
-cv2.destroyAllWindows()

+ 0 - 99
verify_face.py

@@ -1,99 +0,0 @@
-import face_recognition
-import cv2
-import numpy as np
-import joblib
-import time
-
-# 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 complicatedq 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)
-
-clf = joblib.load('saved_model_2.pkl')
-classes = clf.classes_
-
-threshold = 0.9
-
-dummy_data = [
-    {
-        "name": "Bayu",
-        "address": "299 St Louis Road Oak Forest, IL 60452",
-        "nik": "1000076456784631"
-    },
-    {
-        "name": "Dio",
-        "address": "22 Whitemarsh St. Mansfield, MA 02048",
-        "nik": "1000024792887549"
-    },
-    {
-        "name": "Hadi",
-        "address": "643 Honey Creek Dr. Milledgeville, GA 31061",
-        "nik": "1000038502830420"
-    },
-    {
-        "name": "Kevin",
-        "address": "881 Cooper Ave. Hummelstown, PA 17036",
-        "nik": "1000045356476664"
-    },
-    {
-        "name": "Matrix",
-        "address": "580 Glenwood Dr. Garner, NC 27529",
-        "nik": "1000023452134598"
-    },
-    {
-        "name": "Surya",
-        "address": "909 South St Paul Street Hopewell, VA 23860",
-        "nik": "1000075656784734"
-    },
-]
-
-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)
-    print(face_locations)
-    no = len(face_locations)
-    print("Number of faces detected: ", no)
-    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):
-        start_time = time.perf_counter_ns()
-        proba_list = clf.predict_proba([face_encoding])
-        end_time = time.perf_counter_ns()
-        process_time = end_time - start_time
-        i = np.argmax(proba_list)
-        proba = list(*proba_list)[i]
-        name = dummy_data[i]["name"]
-        print(name, "{:.2f}".format(proba), proba_list, process_time)
-
-        # 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)
-        if proba > threshold:
-            font = cv2.FONT_HERSHEY_DUPLEX
-            cv2.putText(frame, "{} {:.2f}".format(name, proba), (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()

+ 0 - 54
verify_face_2.py

@@ -1,54 +0,0 @@
-import face_recognition
-import cv2
-import numpy as np
-import joblib
-import time
-import os
-
-clf = joblib.load('saved_model.pkl')
-classes = clf.classes_
-
-threshold = 0.65
-
-test_image = face_recognition.load_image_file(os.path.join('application_data', 'input_image', 'input_image2.jpg'))
-
-while True:
-
-    rgb_frame = test_image[:, :, ::-1]
-
-    # Find all the faces and face enqcodings in the frame of video
-    face_locations = face_recognition.face_locations(rgb_frame)
-    no = len(face_locations)
-    print("Number of faces detected: ", no)
-    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):
-        start_time = time.perf_counter_ns()
-        proba_list = clf.predict_proba([face_encoding])
-        end_time = time.perf_counter_ns()
-        process_time = end_time - start_time
-        i = np.argmax(proba_list)
-        proba = list(*proba_list)[i]
-        name = classes[i]
-        print(name, "{:.2f}".format(proba), proba_list, process_time)
-
-        # Draw a box around the face
-        cv2.rectangle(test_image, (left, top), (right, bottom), (0, 0, 255), 2)
-
-        # Draw a label with a name below the face
-        cv2.rectangle(test_image, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
-        if(proba > threshold):
-            font = cv2.FONT_HERSHEY_DUPLEX
-            cv2.putText(test_image, "{} {:.2f}".format(name, proba), (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1)
-
-
-    # Display the resulting image
-    cv2.imshow('Video', test_image)
-
-    # Hit 'q' on the keyboard to quit!
-    if cv2.waitKey(1) & 0xFF == ord('q'):
-        break
-
-# Release handle to the webcam
-cv2.destroyAllWindows()