openface/docs/usage.md

28 lines
846 B
Markdown
Raw Normal View History

2015-11-01 20:52:46 +08:00
# Usage
2015-12-25 02:52:39 +08:00
## [API Documentation](http://openface-api.readthedocs.org/en/latest/index.html)
## Example
2015-11-01 21:09:21 +08:00
See [the image comparison demo](https://github.com/cmusatyalab/openface/blob/master/demos/compare.py) for a complete example
2015-11-01 20:52:46 +08:00
written in Python using a naive Torch subprocess to process the faces.
```Python
import openface
# `args` are parsed command-line arguments.
2015-12-30 08:57:29 +08:00
align = openface.AlignDlib(args.dlibFacePredictor)
net = openface.TorchNeuralNet(args.networkModel, args.imgDim, cuda=args.cuda)
2015-11-01 20:52:46 +08:00
# `img` is a numpy matrix containing the RGB pixels of the image.
2015-12-31 02:17:59 +08:00
bb = align.getLargestFaceBoundingBox(img)
2016-01-08 07:28:05 +08:00
alignedFace = align.align(args.imgDim, img, bb,
landmarkIndices=openface.AlignDlib.OUTER_EYES_AND_NOSE)
2015-12-31 02:17:59 +08:00
rep1 = net.forward(alignedFace)
2015-11-01 20:52:46 +08:00
# `rep2` obtained similarly.
d = rep1 - rep2
distance = np.dot(d, d)
```