Created
Jul 2, 2020 11:53 PM
Tags
Python SDK
Install dependencies and the python wheel
# copy wheel url from
# https://github.com/getchui/offline_sdk/releases/latest
# and run
# pip install [wheel_url]
# for example for Linux:
pip install https://github.com/getchui/offline_sdk/releases/download/0.6.6/trueface-0.6.6-cp36-cp36m-linux_x86_64.whl
# for a Mac:
pip install https://github.com/getchui/offline_sdk/releases/download/0.6.6/trueface-0.6.6-cp36-cp36m-macosx_10_14_x86_64.whl
#install pip on Mac
sudo easy_install pip
Download models
Download and unzip the following two model directories:https://github.com/getchui/offline_sdk/releases/download/models-latest/fd_model.ziphttps://github.com/getchui/offline_sdk/releases/download/models-latest/model-tfv4.zip
More SDK downloads can be found here:
https://github.com/getchui/offline_sdk/releases
Getting your credentials
Request a credentials file fromΒ the Trueface team.
Your image collection
Have a directory with the images of the people you would like to recognizeEach subfolder should be named after the person and contain their images.
Your directory structure would look like this:
collection
βββ Manuel
β βββ profile2015.png
β βββ profile.png
βββ Nezare
βββ 10.jpg
βββ 11.jpg
Write your first example:
from trueface.recognition import FaceRecognizer
from trueface.video import VideoStream
import cv2
fr = FaceRecognizer(ctx='cpu',
fd_model_path='./fd_model',
fr_model_path='./model-tfv4/model.trueface',
params_path='./model-tfv4/model.params',
license='<your license key>'
)
fr.create_collection(folder='collection', name='collection.npz', return_features=False)
# src=0 is your usb device 0 which is the first connected usb camera
# if you are using an IP camera you would enter the URL here:
# example for an Amcrest IP camera:
# src="rtsp://username:password@192.168.0.27:554/cam/realmonitor?channel=1&subtype=2"
vcap = VideoStream(src=0).start()
while(True):
frame = vcap.read()
frame = cv2.resize(frame, (640, 480))
bounding_boxes, points, chips = fr.find_faces(frame,
return_chips=True,
return_binary=True)
if bounding_boxes is None:
continue
for i, chip in enumerate(chips):
identity = fr.identify(chip,
threshold=0.3,
collection='./collection.npz')
print(identity)
if 'predicted_label' in identity:
fr.draw_label(
frame,
(int(bounding_boxes[i][0]),
int(bounding_boxes[i][1])),
identity['predicted_label'])
fr.draw_box(frame, bounding_boxes[i])
cv2.imshow('Trueface.ai', frame)
if cv2.waitKey(3
Run it. Don't forget to smile!
# hit "q" to quit the face recognition
python live_face_recognition.py