Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to SkyBiometry Face Detection and Recognition API #1

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d2205b2
Added support for file-like objects to faces_detect() and faces_recog…
snoack Dec 17, 2011
2aecae1
'files' is a list of string values not a dictionary or a list of tupl…
Kami Dec 17, 2011
c1aa360
Update changes.
Kami Dec 17, 2011
7599bfd
Remove unused 'os' import.
Kami Dec 17, 2011
42a66c7
Used consecutive instead of random filenames for anonymous files.
snoack Dec 19, 2011
970457f
Convert headers to str. Otherwise if some headers are given as unicod…
snoack Dec 19, 2011
da79177
Added .gitignore file.
snoack Dec 19, 2011
5ff153b
Merge pull request #10 from wallunit/master
Kami Dec 20, 2011
984d590
Replaced endpoint to api.skybiometry.com/fc.
Liuftvafas Feb 2, 2013
e824e51
Changed links to documentation and account.
Liuftvafas Feb 2, 2013
011d4da
Updated links.
Liuftvafas Feb 2, 2013
4f359d1
Switch EOLs to UNIX/OSX.
Liuftvafas Feb 2, 2013
44b7846
Updated changes and moved examples to readme.
Liuftvafas Feb 23, 2013
d66115d
Added real response from SkyBiometry service.
Liuftvafas Feb 23, 2013
8589ecf
Bold on uids list.
Liuftvafas Feb 23, 2013
2a3ce1c
Added real responses from SkyBiometry service. Fixed tags_get() argum…
Liuftvafas Feb 23, 2013
2bfb9cd
Fixed namespace name in responses.
Liuftvafas Feb 23, 2013
0e271bc
Minor changes.
Liuftvafas Feb 23, 2013
2334399
Changes tabs to spaces.
Liuftvafas Feb 23, 2013
1e7c9b8
Minor changes.
Liuftvafas Feb 23, 2013
c766e4b
Minor changes.
Liuftvafas Feb 23, 2013
3e7d4b8
Update face_client.py
JimJty Feb 28, 2013
062fcb4
Merge pull request #1 from JimJty/patch-1
Liuftvafas Feb 28, 2013
1256cf0
Fixed whitespace and links to documentation.
Liuftvafas Mar 4, 2013
48aa50f
Added reading of response in case of HTTPError.
Liuftvafas Mar 5, 2013
fd3fbd5
Added Python 3 support
Dec 27, 2017
c65139e
Merge pull request #3 from jsutas999/master
Liuftvafas Jan 11, 2018
193d23a
UPD: Multipart request Python 3.X compatibility.
Matas-NT Nov 12, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build
dist
face_client.egg-info
13 changes: 13 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
1.4 - 12.11.2021:

- Added Multipart request Python 3.X compatibility

1.3 - 02.02.2013:

- Allow user to pass file-like object for the 'file' argument to the
faces_detect and faces_recognize function.
[Sebastian Noack]
- Switched to SkyBiometry Face Detection and Recognition API.
- Added possibility to pass image file content for the 'buffer'
argument to faces_detect and faces_recognize function.

1.2 - 25.09.2011:

- Remove deprecated Twiter username and password based auth
Expand Down
106 changes: 0 additions & 106 deletions EXAMPLE.rst

This file was deleted.

174 changes: 160 additions & 14 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,24 +1,170 @@
face.com Python API client library
==================================
SkyBiometry Face Detection and Recognition API client library
=============================================================

face.com_ REST API Python client library.

For a demonstration how to use this library, see EXAMPLE.RST.
SkyBiometry Face Detection and Recognition REST API client library.

For more information about the API and the return values, visit the `official documentation`_.

Performing actions involving Facebook or Twitter users
======================================================
Example
-------

Here is a short example demonstrating how you can use this client.

Lets say that we want to create our own private namespace and train it to recognize Guido Van Rossum.

Here are the images which we will use for training our namespace index:

| http://savasplace.com/wp-content/uploads/2009/04/guido-van-rossum.jpg
| http://farm1.static.flickr.com/43/104506247_c748f20b83.jpg
| http://farm1.static.flickr.com/67/200126290_2798330e61.jpg

And here is the image which hopefully, after training our index will be recognized as "Guido Van Rossum":

http://farm1.static.flickr.com/41/104498903_bad315cee0.jpg

#. First we create our private namespace named **testns** (this can be done on the `SkyBiometry page`_).

#. Now we import the module and instantiate the class with our SkyBiometry **API_KEY** and **API_SECRET** (you can get them by registering your application on `SkyBiometry page`_)::

>> from face_client import FaceClient
>> client = FaceClient('API_KEY', 'API_SECRET')

#. Before training our namespace index I just want to show you that the image is not already recognized::

>> client.faces_recognize('guido', 'http://farm1.static.flickr.com/41/104498903_bad315cee0.jpg', namespace = 'testns')

{
u'status': u'success',
u'photos': [{
u'url': u'http://farm1.static.flickr.com/41/104498903_bad315cee0.jpg',
u'width': 500,
u'tags': [{
u'eye_left': {u'y': 31.2, u'x': 55.6},
u'confirmed': False,
u'uids': [],
u'yaw': -45,
u'manual': False,
u'height': 18.13,
u'width': 13.6,
u'mouth_center': {u'y': 43.47, u'x': 52.6},
u'nose': {u'y': 36.53, u'x': 53.4},
u'eye_right': {u'y': 30.93, u'x': 48.0},
u'pitch': 0,
u'tid': u'TEMP_F@08e31221350a43d267be01d500f10086_1d12ece6a6ea2_48.20_35.73_0_1',
u'attributes': {
u'gender': {u'confidence': 47, u'value': u'male'},
u'smiling': {u'confidence': 85, u'value': u'false'},
u'glasses': {u'confidence': 27, u'value': u'false'},
u'dark_glasses': {u'confidence': 89, u'value': u'false'},
u'face': {u'confidence': 71, u'value': u'true'}
},
u'recognizable': True,
u'roll': 3,
u'center': {u'y': 35.73, u'x': 48.2}
}],
u'pid': u'F@08e31221350a43d267be01d572dc824b_1d12ece6a6ea2',
u'height': 375
}],
u'usage': {...omitted for clarity...}
}

As you can see, the "uids" list is empty, meaning that Guido Van Rossum is not yet recognized in our **testns** namespace.

#. Saving the tags and training our index. For saving the tags, we need to provide the **tags_save** method with the tag ids, which we are obtained by using the **faces_detect** or **faces_recognize** method. In this example, I will use **faces_detect**::

>> response = client.faces_detect('http://savasplace.com/wp-content/uploads/2009/04/guido-van-rossum.jpg,http://farm1.static.flickr.com/43/104506247_c748f20b83.jpg,http://farm1.static.flickr.com/67/200126290_2798330e61.jpg')
>> tids = [photo['tags'][0]['tid'] for photo in response['photos']]
>> tids

[
u'TEMP_F@0bf0294f6c43162105c9bdfa00bc00ab_15e78870a332a_47.00_28.50_0_1',
u'TEMP_F@008f7f3d4f93956f2fd24b1e01000084_e29f2ba8f58c6_51.20_35.20_0_1',
u'TEMP_F@0d38a4e97c5c63042b5da6da00a10088_73a8fb3908097_48.35_27.20_0_1'
]

#. Now when we have the temporary tag ids, we can use them to save the tags and train our namespace index::

>> client.tags_save(tids = ',' . join(tids), uid = 'guido@testns', label = 'Guido Van Rossum')

{
u'status': u'success',
u'message': u'Tags saved with uid: guido@testns, label: Guido Van Rossum',
u'saved_tags': [
{u'tid': u'00bc00ab_15e78870a332a', u'detected_tid': u'TEMP_F@0bf0294f6c43162105c9bdfa00bc00ab_15e78870a332a_47.00_28.50_0_1'},
{u'tid': u'01000084_e29f2ba8f58c6', u'detected_tid': u'TEMP_F@008f7f3d4f93956f2fd24b1e01000084_e29f2ba8f58c6_51.20_35.20_0_1'},
{u'tid': u'00a10088_73a8fb3908097', u'detected_tid': u'TEMP_F@0d38a4e97c5c63042b5da6da00a10088_73a8fb3908097_48.35_27.20_0_1'}
]
}

>> client.faces_train('guido@testns')

{
u'status': u'success',
u'created': [{
u'training_set_size': 3,
u'last_trained': 1361651583,
u'uid': u'guido@testns',
u'training_in_progress': False}
]
}

#. We can also check that the tags were saved by using the **tags_get** method::

>> client.tags_get('guido@testns')

{
u'status': u'success',
u'photos': [
{u'url': u'http://farm1.static.flickr.com/67/200126290_2798330e61.jpg', ...omitted for clarity...},
{u'url': u'http://farm1.static.flickr.com/43/104506247_c748f20b83.jpg', ...omitted for clarity...},
{u'url': u'http://savasplace.com/wp-content/uploads/2009/04/guido-van-rossum.jpg', ...omitted for clarity...}
],
u'usage': {...omitted for clarity...}
}

If you want to perform actions involving Facebook or Twitter users you need to provide the necessary credentials.
#. Now after we have trained our index, lets check if Guido is recognized::

#. **Facebook**::
>> client.faces_recognize('all', 'http://farm1.static.flickr.com/41/104498903_bad315cee0.jpg', namespace = 'testns')

client.set_facebook_oauth_credentials('FB_USER_ID', 'FB_SESSION_ID', 'FB_OAUTH_TOKEN')
{
u'status': u'success',
u'photos': [{
u'url': u'http://farm1.static.flickr.com/41/104498903_bad315cee0.jpg',
u'width': 500,
u'tags': [{
u'eye_left': {u'y': 31.2, u'x': 55.6},
u'confirmed': False,
u'uids': [{u'confidence': 34, u'uid': u'guido@testns'}],
u'width': 13.6,
u'yaw': -45,
u'manual': False,
u'height': 18.13,
u'threshold': 30,
u'mouth_center': {u'y': 43.47, u'x': 52.6},
u'nose': {u'y': 36.53, u'x': 53.4},
u'eye_right': {u'y': 30.93, u'x': 48.0},
u'pitch': 0,
u'tid': u'TEMP_F@08e31221350a43d267be01d500f10086_1d12ece6a6ea2_48.20_35.73_0_1',
u'attributes': {
u'gender': {u'confidence': 47, u'value': u'male'},
u'smiling': {u'confidence': 85, u'value': u'false'},
u'glasses': {u'confidence': 27, u'value': u'false'},
u'dark_glasses': {u'confidence': 89, u'value': u'false'},
u'face': {u'confidence': 71, u'value': u'true'}
},
u'recognizable': True,
u'roll': 3,
u'center': {u'y': 35.73, u'x': 48.2}
}],
u'pid': u'F@08e31221350a43d267be01d572dc824b_1d12ece6a6ea2',
u'height': 375
}],
u'usage': {...omitted for clarity...}
}

#. **Twitter (OAuth)**::
As you can see by looking at the "uids" list, Guido was now recognized with a 34% confidence!

client.set_twitter_oauth_credentials('OAUTH_USER', 'OAUTH_SECRET', 'OAUTH_TOKEN')
For more information about the SkyBiometry Face Detection and Recognition API and how to use it, visit the `official documentation`_.

.. _face.com: http://developers.face.com/
.. _official documentation: http://developers.face.com/docs/api/
.. _SkyBiometry page: http://www.skybiometry.com/Account
.. _official documentation: http://www.skybiometry.com/Documentation
2 changes: 2 additions & 0 deletions face_client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.py[co]
.*.sw?
2 changes: 1 addition & 1 deletion face_client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = (1, 2, 'dev')
__version__ = (1, 4, 'dev')

from face_client import *
Loading