Skip to content
This repository was archived by the owner on Nov 8, 2021. It is now read-only.

Commit 2044352

Browse files
authored
Support more face attributes in SDK & Sample. (#11)
* Update docstrings for face.detect by introducing emotion. * Update sample to support headPose,facialHair,emotion. * Add missing emotion attribute. * Update README.md. * pylint. * Bump version to 1.2.5.
1 parent c4965ae commit 2044352

File tree

7 files changed

+31
-15
lines changed

7 files changed

+31
-15
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ python sample
5959
```
6060

6161
## Contributing
62-
We welcome contributions. Feel free to file issues and pull requests on the repo and we'll address them as we can. Learn more about how you can help on our [Contribution Rules & Guidelines](</CONTRIBUTING.md>).
62+
We welcome contributions. Feel free to file issues and pull requests on the repo and we'll address them as we can. Learn more about how you can help on our [Contribution Rules & Guidelines](</CONTRIBUTING.md>).
6363

6464
You can reach out to us anytime with questions and suggestions using our communities below:
6565
- **Support questions:** [StackOverflow](<https://stackoverflow.com/questions/tagged/microsoft-cognitive>)
@@ -68,7 +68,7 @@ You can reach out to us anytime with questions and suggestions using our communi
6868
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
6969

7070
## Updates
71-
* 8/2016: Sample updated for [July 2016 Face API changes](https://www.microsoft.com/cognitive-services/en-us/face-api/documentation/overview#changes)
71+
* [Face API Release Notes](https://www.microsoft.com/cognitive-services/en-us/face-api/documentation/ReleaseNotes)
7272

7373
## License
7474
All Microsoft Cognitive Services SDKs and samples are licensed with the MIT License. For more details, see

Diff for: cognitive_face/face.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ def detect(image, face_id=True, landmarks=False, attributes=''):
1313
1414
Args:
1515
image: A URL or a file path or a file-like object represents an image.
16-
face_id: Optional parameter. Return `face_id`s of the detected faces or
17-
not. The default value is `True`.
18-
landmarks: Optional parameter. Return face landmarks of the detected
19-
faces or not. The default value is `False`.
20-
attributes: Optional parameter. Analyze and return the one or more
21-
specified face attributes in the comma-separated string like
22-
`age,gender`. Supported face attributes include age, gender,
23-
headPose, smile, facialHair, and glasses. Note that each face
24-
attribute analysis has additional computational and time cost.
16+
face_id: [Optional] Return faceIds of the detected faces or not. The
17+
default value is true.
18+
landmarks: [Optional] Return face landmarks of the detected faces or
19+
not. The default value is false.
20+
attributes: [Optional] Analyze and return the one or more specified
21+
face attributes in the comma-separated string like
22+
"returnFaceAttributes=age,gender". Supported face attributes
23+
include age, gender, headPose, smile, facialHair, glasses and
24+
emotion. Note that each face attribute analysis has additional
25+
computational and time cost.
2526
2627
Returns:
2728
An array of face entries ranked by face rectangle size in descending

Diff for: sample/model/face.py

+11
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,19 @@ def __init__(self, res, path, size=util.MAX_THUMBNAIL_SIZE):
3333
attr = res['faceAttributes']
3434
self.age = int(attr['age'])
3535
self.gender = attr['gender']
36+
self.head_pose = "Pitch: {}, Roll:{}, Yaw:{}".format(
37+
attr['headPose']['pitch'],
38+
attr['headPose']['roll'],
39+
attr['headPose']['yaw']
40+
)
3641
self.smile = float(attr['smile']) > 0 and 'Smile' or 'Not Smile'
42+
self.facial_hair = sum(attr['facialHair'].values()) > 0 and 'Yes' \
43+
or 'No'
3744
self.glasses = attr['glasses']
45+
self.emotion = max(
46+
attr['emotion'],
47+
key=lambda key: attr['emotion'][key]
48+
)
3849
self.bmp = util.scale_bitmap(self.bmp, size)
3950

4051
def set_name(self, name):

Diff for: sample/util.py

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
)
3333
LOG_FACE_LIST_NOT_EXIST = 'Response: Face List {} does not exist before.'
3434
LOG_FACE_LIST_EXIST = 'Response: Face List {} exists.'
35+
LABEL_FACE = '{} years old, {}\n{}\n{}, {}\nFacial Hair: {}\nEmotion: {}\n'
3536

3637

3738
class SubscriptionKey(object):

Diff for: sample/view/base.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,14 @@ def OnDrawItem(self, dc, rect, index):
242242

243243
textx = rect.x + 2 + face.bmp.GetWidth() + 2
244244
label_rect = wx.Rect(textx, rect.y, rect.width - textx, rect.height)
245-
label = '{} years old\n{}\n{}\n{}\n'.format(
245+
label = util.LABEL_FACE.format(
246246
face.age,
247247
face.gender,
248+
face.head_pose,
248249
face.smile,
249-
face.glasses
250+
face.glasses,
251+
face.facial_hair,
252+
face.emotion
250253
)
251254
dc.DrawLabel(label, label_rect, wx.ALIGN_LEFT | wx.ALIGN_TOP)
252255

Diff for: sample/view/panel_detection.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def async_detect(self, path):
9999
self.rsizer.Layout()
100100
self.vhsizer.Layout()
101101

102-
attributes = 'age,gender,smile,glasses'
102+
attributes = 'age,gender,headPose,smile,facialHair,glasses,emotion'
103103
res = util.CF.face.detect(path, False, False, attributes)
104104
faces = [model.Face(face, path) for face in res]
105105
self.face_list.SetItems(faces)

Diff for: setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def readme():
2020

2121
setup(
2222
name='cognitive_face',
23-
version='1.2.1',
23+
version='1.2.5',
2424
packages=find_packages(exclude=['tests']),
2525
install_requires=['requests'],
2626
author='Microsoft',

0 commit comments

Comments
 (0)