55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
|
|
import functools
|
|
|
|
from ketrface.util import *
|
|
from ketrface.dbscan import *
|
|
from ketrface.db import *
|
|
from ketrface.config import *
|
|
|
|
config = read_config()
|
|
|
|
html_path = merge_config_path(config['path'], 'frontend')
|
|
pictures_path = merge_config_path(config['path'], config['picturesPath'])
|
|
faces_path = merge_config_path(config['path'], config['facesPath'])
|
|
db_path = merge_config_path(config['path'], config["db"]["photos"]["host"])
|
|
html_base = config['basePath']
|
|
if html_base == "/":
|
|
html_base = "."
|
|
|
|
print(f'Connecting to database: {db_path}')
|
|
conn = create_connection(db_path)
|
|
with conn:
|
|
cur = conn.cursor()
|
|
res = cur.execute('''
|
|
SELECT identities.descriptors,
|
|
GROUP_CONCAT(faces.id) AS relatedFaceIds,
|
|
GROUP_CONCAT(faces.descriptorId) AS relatedFaceDescriptorIds,
|
|
GROUP_CONCAT(faces.photoId) AS relatedFacePhotoIds
|
|
FROM identities
|
|
INNER JOIN faces ON identities.id=faces.identityId
|
|
WHERE identities.id=7
|
|
GROUP BY identities.id
|
|
''')
|
|
for identity in res.fetchall():
|
|
relatedFaceDescriptorIds = identity[2].split(',')
|
|
|
|
res2 = cur.execute(
|
|
'SELECT descriptors FROM facedescriptors WHERE id IN (%s)' %
|
|
','.join('?'*len(relatedFaceDescriptorIds)), relatedFaceDescriptorIds)
|
|
|
|
descriptors = []
|
|
for row2 in res2.fetchall():
|
|
descriptors.append(np.frombuffer(row2[0]))
|
|
|
|
distances = []
|
|
|
|
relatedFaceIds = identity[2].split(',')
|
|
for i, face in enumerate(relatedFaceIds):
|
|
distance = findEuclideanDistance(
|
|
descriptors[i],
|
|
np.frombuffer(identity[0])
|
|
)
|
|
distances.append(distance)
|
|
|
|
distances.sort()
|
|
print(distances) |