Getting started with the SDK

Installing dependencies and the python wheel

# copy wheel url from 
# https://github.com/getchui/offline_sdk/releases
# and run
# pip install [wheel_url]

# for example for Linux:
pip install https://github.com/getchui/offline_sdk/releases/download/0.6/trueface-0.0.6.0-cp27-cp27mu-linux_x86_64.whl

# for a Mac:
pip install https://github.com/getchui/offline_sdk/releases/download/0.6/trueface-0.0.6.0-cp27-cp27m-macosx_10_12_intel.whl


#install pip on Mac
sudo easy_install pip

Installing models

Download and unzip the following two model directories:
https://github.com/getchui/offline_sdk/releases/download/models-latest/fd_model.zip
https://github.com/getchui/offline_sdk/releases/download/models-latest/model-tfv2.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.
Legacy Trueface Server tokens will not work for the local SDK.

Your image collection

Have a directory with the images of the people you would like to recognize
Each 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-tfv2/model.trueface',
                    params_path='./model-tfv2/model.params',
                    license='<your license key>'
                    )

fr.create_collection('collection', 'collection.npz', return_features=False)

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 identity['predicted_label']:
            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(33) == ord('q'):
        break

Run it. Don't forget to smile!

python live_face_recognition.py

# hit "q" to quit the face recognition

Getting started with the SDK


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.