0

I am trying to create image classifier based on MS API by using python.

At first, I would like follow a instruction via MSDN "How to identify Face" This instruction is based on C#, but I would like to refer and convert into python

https://msdn.microsoft.com/en-us/library/mt605327.aspx

And based on my analysis, in order to identify face, the procedure is like this.

2. Person Group - Create a Person Group API

Person - Create a Person API

Person – Add a Person Face 3. Train Person group Person Group – Train Person Group API. Person Group - Get Person Group Training Status

  1. Identify

    Face – Identify.

Q1. How to create sub group like example? Below code basically create person group id and I am not sure how to add sub groups such as "Anna", "Bill", "Claire" in this case.

#Person Group - Create a Person Group API
group_id = 'myfriend'
params = urllib.urlencode({ 'personGroupId': group_id})

body = '{"name": "myfriend1","userData": "user_profivde_data"}'
print(body)

try:
conn = httplib.HTTPSConnection('api.projectoxford.ai')
conn.request("PUT", "/face/v1.0/persongroups/{personGroupId}?%s" % params, body, headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))

Q2. How to add several user face data instead of url? it seems like it requires body for url which only can data one. I would like get several data upload via my disk.

# Person - Add a Person Face

params = urllib.urlencode({
# Request parameters
'personGroupId': 'myfriend1',
'personId': "f50119eb-5a61-479f-9c57-d2af4eb99c48",
'userData': '{r/media/ryan/Windows_D/xx/xx.jpg}',
#'targetFace': '{string}',
})

body = '{ "url": "" }'

try:
conn = httplib.HTTPSConnection('api.projectoxford.ai')
conn.request("POST", "/face/v1.0/persongroups/{personGroupId}/persons/{personId}/persistedFaces?%s" % params, body, headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))

It would be very nice if someone has python code for image grouping by ms api.

Thanks for your help and I really appreciated it.

user2314737
  • 27,088
  • 20
  • 102
  • 114
RSBS
  • 107
  • 8

1 Answers1

0

Q1: Once you successfully create a PersonGroup you then create Person objects as part of that group using the Create Person POST call API Reference | How-To doc. You can have multiple person groups, and each person group can have multiple person objects. Person objects must exist in a person group.

Q2: Adding Faces takes only a single face each time, so if you have 5 faces to add to a Person object it will require 5 calls of adding a person face. Though its in C#, there's an example of iterating through a folder to do this in this How-To doc

Also there's a python notebook showing how to use Face API's detection here which might be of interest: https://github.com/Microsoft/ProjectOxford-ClientSDK/blob/master/Face/Python/Jupyter%20Notebook/Face%20Detection%20Example.ipynb

We're always looking to extend the examples and would happily review a pull request if you want to extend this Python one with an example for identification :-)

Ryan Galgon
  • 431
  • 1
  • 3
  • 9
  • Thanks for your answer. But I still don't understand how to add several pictures at once with person group and use face identity or grouping. None of explanation has those details and I already tried facial detection examples via github which is easy task since it doesn't have to upload the picture. **I really appreciate if you could explain via python code or where to find information (Face API Doc. doesn't have enough details for each one)** – RSBS Jun 28 '16 at 04:22
  • Each API call adds a single picture (see Q2 above) so adding 5 faces requires 5 API calls of add a person face. If you could post an example of the code you're trying to run I could help more. The Face API doc shows how to do it with a standard HTTP call, you can then use Requests or your favorite python http library to make the call. – Ryan Galgon Jul 06 '16 at 00:04