Quick start
-
update thresholds for faces into config.py
-
update volume paths in docker-compse.yml
-
build project
docker-compose up --build
- send path to video or image to Rebbit queue
import pika
from pathlib import Path
VIDEO_PATH = '~/Desktop/driveData/' # mounted folder with video
connection = pika.BlockingConnection(
pika.ConnectionParameters(host='localhost', port=5672)
)
channel = connection.channel()
channel.queue_declare(queue='face')
for filepath in Path(VIDEO_PATH).glob('**/*.avi'):
channel.basic_publish(exchange='', routing_key='face',
body=str(filepath)[len(VIDEO_PATH):])
connection.close()
- connect to Redis to check progress
import redis
import config
r = redis.Redis(host='localhost', port=6379, db=0)
for key in r.scan_iter("*"):
if r.get(key) != 100:
print(key, r.get(key))
- connect to Mongo to see face data
import cv2
import numpy as np
import pymongo
client = pymongo.MongoClient('mongodb://localhost:27017/')
face_data_0 = list(client.video_db.Faces.find({'_id': '0'}))[0]
# {'_id': 0,
# 'face': encoded image # if config.IMAGE_PATH is None
# 'face_pad': padded encoded image # if config.IMAGE_PATH is None
# 'face_path': path_to_padded_image_folder}
# 'face_pad_path': path_to_face_image_folder,
# 'paths': {'path_to_video_1': [40, 80], # millisec ts
# 'path_to_video_2': [120, 160, 200]}
face_img = cv2.imdecode(np.frombuffer(face_data_0['face_crop'], np.uint8), 1)
- connect to faiss to get similar persons
import faiss
n_closest = 10
faiss_index = faiss.read_index('/path/to/faiss/face_vectors.faiss')
face_2_vecor = faiss_index.reconstruct(2)
product_distance, closest_person_ids = faiss_index.search(face_2_vecor.reshape(1, -1), n_closest)
Openvino Pretrained models