Answer the question
In order to leave comments, you need to log in
Compare 'biometrics' of two faces with python and face_recognition module using SQL query?
Good evening,
I don’t know how clearly it turned out to reflect the essence of the issue in the title)
There is a Python code that, after recognizing a face in a photo, receives an array of data, comparing / calculating the Euclidean distance with another similar array, we will find out how similar two faces are in the photo.
I took this article as a basis:
article
The only thing I don't understand is how can I correctly save the received 'biometrics/array' into a relational database and then search only using a SQL query?
Example:
#!/usr/bin/env python3
import cv2
import face_recognition
import mysql.connector as mysql
def get_image_hash(image):
# Открытие изображения
img = face_recognition.load_image_file(image)
# Blaсk Livеs Mаttеr
#img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Получаем данные с лица
vector = face_recognition.face_encodings(img)[0]
vector = (str(vector),)
return vector
# Open DB
conn = mysql.connect(
host = '127.0.0.1',
user = 'user',
passwd = 'password'
)
cur = conn.cursor()
cur.execute("SHOW DATABASES")
# Проверка на существование базы
db_found = False
for db in cur:
if 'test' in db:
db_found = True
if not db_found:
cur.execute("CREATE DATABASE IF NOT EXISTS test;")
conn.commit()
cur.execute("USE test;")
cur.execute("""CREATE TABLE IF NOT EXISTS faces(id_face BIGINT PRIMARY KEY NOT NULL AUTO_INCREMENT, face_hash TEXT)""")
new_image = get_image_hash('test.jpg')
# Сохранение в БД
cur.execute('''INSERT INTO faces (face_hash) VALUES(%s)''', new_image)
conn.commit()
# Загрузка фото для поиска
find_me_image = get_image_hash('findme.jpg')
#print('d: ', find_me_image[0])
# Как я здесь должен сравнивать массив полученный с только что загруженного фото с ранее сохраненными образцами в БД?
cur.execute("SELECT * FROM faces WHERE ..... ;")
cur.close()
print('find_me_image: ', str(find_me_image))
print('new_image: ', str(new_image))
pdist([vector1, vector2], 'euclidean')
Answer the question
In order to leave comments, you need to log in
Most recently I came across a description of one specialized DBMS.
https://milvus.io/docs/v2.0.0/overview.md
Try it. Maybe it will.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question