Пример #1
0
def find_profile():
    """
    Takes a photo and returns detected names and descriptors.

    Returns
    -------
    Case: no faces --> False
    Case: one unknown face --> numpy array (desc)
    Case: one known face --> string (name)
    Case: multiple unknown faces --> -1
    Case: multiple known faces --> list of strings (names)
    """
    names, descs = Face_Rec.go_friend()
    print(names)
    if len(names) == 0:
        # No faces
        return False
    elif len(names) == 1 and names[0] is None:
        # One unknown face
        return descs[0]
    elif len(names) == 1:
        # One known face
        return names[0]
    else:
        names = np.array(names)
        identified_names = names[names != np.array(None)]  # Filters Nones out of list
        print(identified_names)
        if len(identified_names) == 0:
            # Multiple unknown faces
            return -1
        if len(identified_names) == 1:
            # One known face and other unknown ones
            return identified_names[0]
        # Multiple known faces
        return identified_names.tolist()
Пример #2
0
def add_person(name, img):
    """
    Adds person to Face_Rec database.

    Parameters
    ----------
    name: String
        Name inputted by user.
    img: np.ndarray
        Face descriptor

    Returns
    -------
    String
    """
    Face_Rec.add_image(img, name)
    return name
Пример #3
0
def callback():
    # Получаем кортеж возвращаемых значений
    frame, name = Face_Rec.video()
    # Декодируем изображение и обновляем ImageLabel родителя
    img2 = ImageTk.PhotoImage(image=Image.fromarray(frame))
    Output_Frame.configure(image=img2)
    Output_Frame.image = img2
    # Запускаем функцию каждые 34мс
    Main.after(34, callback)
Пример #4
0
def listbox_update():
    # Получаем кортеж возвращаемых значений
    frame, name = Face_Rec.video()
    l = listbox.size()
    str = "Unknown"
    print(l)
    for i in range(1, l):
        print(listbox.get(i))
        str += listbox.get(i)
    str.lower()
    for i in range(0, len(name)):
        if (str.find(name[i]) < 0):
            listbox.insert(END, name[i])
    Main.after(1500, listbox_update)
Пример #5
0
    for i in range(1, l):
        print(listbox.get(i))
        str += listbox.get(i)
    str.lower()
    for i in range(0, len(name)):
        if (str.find(name[i]) < 0):
            listbox.insert(END, name[i])
    Main.after(1500, listbox_update)


# "Родитель" формы
Main = Tk()
Main.title("Face Recognition")
Main.geometry('800x360')
# Получаем кортеж возвращаемых значений
frame, name = Face_Rec.video()
# Декодируем изображения
im = Image.fromarray(frame)
img = ImageTk.PhotoImage(image=im)
# Создаем ImageLabel для вывода декодированного изображения
Output_Frame = Label(Main, image=img, width=640, height=360)
Output_Frame.pack(side="left", fill="both", expand="yes")
# Создаем кнопку для добавления "обьекта" распознованя
Preview = Button(Main, text="Add new person", width=25, command=FaceSnap)
Preview.pack(side="bottom")
# Создаем список для записи всех идентифицированных "обьектов"
listbox = Listbox(Main)
listbox.pack(side="right", ipady=80)
listbox.insert(END, "Tut?")
# Запуск "Родителя"
Main.after_idle(callback)
Пример #6
0
def photo():
    """
    Triggers when something synonymous to 'yes' is spoken.
    :return: Statement or question
    """
    if add_flag == 0:
        """
        If used at start of program to take photo.
        """
        global descs
        names, img, ul, descs = Face_Rec.go() # Take photo
        with open("test.txt", "w") as f:
            f.write(ul)

        names = np.array(names)
        nones = len(names) - np.count_nonzero(names) # Number of unidentifiable faces
        identified_names = names[names != np.array(None)] # Filters Nones out of list

        # Responses
        if len(names) < 1:
            return statement("I do not see anyone.")
        if len(identified_names) < 1 or identified_names[0] is None:
            if nones > 1:
                return statement("I see " + str(nones) + " unknown faces.")
            return statement("I see one unknown face.")
        if len(identified_names) == 1:
            if nones > 0:
                if nones > 1:
                    msg = identified_names[0] + " and " + str(nones) + "unknown faces."
                else:
                    msg = identified_names[0] + " and one unknown face."
                return statement("I see " + msg) \
                    .standard_card(title="I see...",
                                   text=msg,
                                   small_image_url=ul,
                                   large_image_url=ul)
            else:
                msg = identified_names[0]
                add_flag = 1
                global name
                name = msg
                print(ul)
                return question("I see " + msg + ". Would you like to add this to the database?") \
                    .standard_card(title="I see...",
                                   text=msg,
                                   small_image_url=ul,
                                   large_image_url=ul)
        if nones > 0:
            if nones > 1:
                msg = ", ".join(identified_names) + ", and " + str(nones) + "unknown faces."
            else:
                msg = ", ".join(identified_names) + ", and one unknown face."
        else:
            msg = ", ".join(identified_names[:-1]) + ", and " + identified_names[-1]
        return statement("I see " + msg) \
            .standard_card(title="I see...",
                           text=msg,
                           small_image_url=ul,
                           large_image_url=ul)
        # END RESPONSES
    else:
        """
        If 'yes' is said in response to being asked to be added to the database.
        """
        global add_flag
        add_flag = 0
        Face_Rec.add_image(descs, name=name)
        return statement("Photo added.")
Пример #7
0
            .standard_card(title="I see...",
                           text=msg,
                           small_image_url=ul,
                           large_image_url=ul)
        # END RESPONSES
    else:
        """
        If 'yes' is said in response to being asked to be added to the database.
        """
        global add_flag
        add_flag = 0
        Face_Rec.add_image(descs, name=name)
        return statement("Photo added.")


@ask.intent("NoIntent")
def no():
    """
    Triggered when a word synonymous to "no" is said.
    Resets add_flag.
    :return:
    """
    global add_flag
    add_flag = 0
    return statement("Okay! Maybe next time.")


if __name__ == '__main__':
    add_flag = 0
    Face_Rec.initialize()
    app.run()
Пример #8
0
def initialize():
    """
    Called at start of program to retrieve database and call Face_Rec initialization.
    """
    read_database()
    Face_Rec.initialize()