I
I
Ivanzolo20012021-10-03 16:21:52
Python
Ivanzolo2001, 2021-10-03 16:21:52

A question for the facial recognition experts?

I am trying to compare two faces. I saved MY face in images/to_recog/Practice/0.jpg. In the program, I connect to my webcam and just look at it. But nevertheless the program says that it's not me? Where is the mistake. The code:

import cv2
import face_recognition
import os
from threading import Thread
import telebot
import time

keys = []
bot = telebot.TeleBot(тут мой токен)
def tg():
    @bot.message_handler(commands=['start'])
    def start(message):
        bot.send_message(message.from_user.id, "Стартую!")
        keys.append(message.from_user.id)

    bot.polling(none_stop=True, interval=0)

def tg_send(condition, image):
    bot.send_message(keys[0], condition)
    return

def recognizing():
    cap = cv2.VideoCapture(0)
    image_to_recognition = face_recognition.load_image_file('images/to_recog/practice/0.jpg')
    image_enc = face_recognition.face_encodings(image_to_recognition)[0]
    recognizer_cc = cv2.CascadeClassifier('faces.xml')

    while True:
        success,img = cap.read()

        recognize = recognizer_cc.detectMultiScale(img, scaleFactor=2, minNeighbors=3)
        if len(recognize) != 0:
            print("Лицо найдено")
            unknown_face = face_recognition.face_encodings(img)[0]
            compare = face_recognition.compare_faces([unknown_face], image_enc)

            if compare == True:
                tg_send("Это вы!", img)

            else:
                tg_send("Это не вы!", img)

if __name__ == '__main__':
    tg_thr = Thread(target=tg)
    tg_thr.start()
    recognizing()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolay Savelyev, 2021-10-03
@AgentSmith

compare == true

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question