def classify(self, path_to_img):
        # img = cv2.imread(path_to_img,0)                                        # read as a grayscale image
        img = detect_face(path_to_img)
        if (img is None):
            return -2
        img_col = np.array(img, dtype='float64').flatten()  # flatten the image
        img_col -= self.mean_img_col  # subract the mean column
        img_col = np.reshape(img_col,
                             (self.mn, 1))  # from row vector to col vector

        S = self.evectors.transpose(
        ) * img_col  # projecting the normalized probe onto the
        # Eigenspace, to find out the weights

        diff = self.W - S  # finding the min ||W_j - S||
        norms = np.linalg.norm(diff, axis=0)
        print(np.min(norms))
        closest_face_id = np.argmin(
            norms)  # the id [0..240) of the minerror face to the sample
        #threshold for not detecting any face
        if np.min(norms) >= 6500:
            return -1
        return self.names[(
            closest_face_id //
            self.train_faces_count)]  # return the faceid (1..40)
Beispiel #2
0
def registration_controller():

    error = 0;
    outer_id = '12345678helloAi'
    f = open("/home/pi/Desktop/ProfMate/student_info.txt", mode='r')
    info = f.readlines()
    picture_addr = info[0].strip()
    first_name = info[1].strip()
    last_name = info[2].strip()
    student_id = int(info[3].strip())

    print(first_name)
    print(last_name)
    
    #if multiple, consider for loop
    student_courses = 101
    
    face_tokens = detect.detect_face(picture_addr)
    
    if(len(face_tokens) > 1):
        print("Invalid Picture: Multiple Face Detected")
        #terminate
        error = 1
        return error
    
    
    face_token = face_tokens[0]
    
    newStudent = studentControl(first_name, last_name, student_id, student_courses, outer_id)
    
    newStudent.addStudent(face_token) #Add Student to both Face++ and DB
    return
Beispiel #3
0
    def detect_face_dispaly(self):

        print('\nDetecting Faces...\n')
        face_tokens = detect.detect_face('/home/pi/Desktop/ProfMate/pic.jpg') #use api to check the picture
        
        print('\nFinished\n')
        num = len(face_tokens)
        print('\nFaces find: ' + str(num) + '\n')

        return face_tokens
Beispiel #4
0
 def load_data(self, img_path):
     img_list = []
     face = detect_face(img_path)
     if face is None:
         return None
     else:
         face_img = st.resize(face, (FACE_CROP_SIZE, FACE_CROP_SIZE))
         img_list.append(face_img)
         images = np.stack(img_list)
         return images
def handle_detect():
    """检查人脸"""
    filename = get_filename(offset)
    file_path = os.path.join(image_dir, filename)
    result = detect_face(face_record.id, file_path)

    if result:
        detect_label['text'] = u'检测成功'
        detect_label['fg'] = 'green'
    else:
        detect_label['text'] = u'检测失败'
        detect_label['fg'] = 'red'
Beispiel #6
0
    # with np.load("/training/data.npy") as data:
    # 	in_data = data

    # with np.load("/training/labels.npy") as labels:
    # 	in_labels = labels

    # #Make sure labels and data are same length
    # assert in_data.shape[0] == in_labels.shape[0]

    # #Create a placeholder for current input instead of copying in all training data
    # input_current = tf.placeholder(in_data.dtype, in_data.shape)
    # labels_current = tf.placeholder(in_labels.dtype, in_labels.shape)
    # dataset = tf.data.Dataset.from_tensor_slices((input_current, labels_current))
    # iterator = dataset.make_initializable_iterator()

    in_data, labels = detect_face()

    #Initialize model based on architecture we desire
    NN = Neuron_Network(input_layer, first_hidden, second_hidden, output_layer)

    #Compile model by setting all correct parameters
    NN.model.compile(optimizer="sgd",
                     loss='sparse_categorical_crossentropy',
                     metrics=['accuracy'])

    NN.model.fit(x=in_data, y=labels, epochs=epoch)

    #Call method Fit in order to begin training.
    # NN.model.fit(iterator, epochs=epoch,
    # 	steps_per_epoch=in_data.shape[0],
    # 	validations_split=0.2)