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

Commit

Permalink
Add emotion support for Android SDK and Sample. (#7)
Browse files Browse the repository at this point in the history
* Replace old deprecated Project url.

* Add emotion support.

* gradle upgrade.

* Bump version to 1.2.5.
  • Loading branch information
huxuan authored Mar 22, 2017
1 parent 13d3956 commit f466981
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 31 deletions.
14 changes: 7 additions & 7 deletions ClientLibrary/lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ group = "com.microsoft.projectoxford"
// Artifact name is the name of the technology
archivesBaseName = "face"
// Update your version
version = "1.2.1"
version = "1.2.5"

// Upload artifacts to maven central repository staging servers
uploadArchives {
Expand All @@ -50,22 +50,22 @@ uploadArchives {
// optionally artifactId can be defined here

// Descriptions of the artifacts.
description 'This client library allows the use of Microsoft\'s state-of-the-art cloud-based face algorithms to detect and recognize human faces in images. See https://github.com/Microsoft/ProjectOxford-ClientSDK/tree/master/Face for more information.'
description 'This client library allows the use of Microsoft\'s state-of-the-art cloud-based face algorithms to detect and recognize human faces in images. See https://github.com/Microsoft/Cognitive-Face-Android for more information.'

// Project URL
url 'https://github.com/Microsoft/ProjectOxford-ClientSDK'
url 'https://github.com/Microsoft/Cognitive-Face-Android'

// Github information
scm {
connection 'scm:git:https://github.com/Microsoft/ProjectOxford-ClientSDK'
developerConnection 'scm:git:https://github.com/Microsoft/ProjectOxford-ClientSDK'
url 'scm:git:https://github.com/Microsoft/ProjectOxford-ClientSDK'
connection 'scm:git:https://github.com/Microsoft/Cognitive-Face-Android'
developerConnection 'scm:git:https://github.com/Microsoft/Cognitive-Face-Android'
url 'scm:git:https://github.com/Microsoft/Cognitive-Face-Android'
}

licenses {
license {
name 'MIT'
url 'https://github.com/Microsoft/ProjectOxford-ClientSDK/blob/master/LICENSE.md'
url 'https://github.com/Microsoft/Cognitive-Face-Android/blob/master/LICENSE.md'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,18 @@ public String toString() {
* Analyses glasses type
*/
Glasses {
public String toString() { return "glasses"; }
public String toString() {
return "glasses";
}
},

/**
* Analyses emotion type
*/
Emotion {
public String toString() {
return "emotion";
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license.
//
// Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services
//
// Microsoft Cognitive Services (formerly Project Oxford) GitHub:
// https://github.com/Microsoft/Cognitive-Face-Android
//
// Copyright (c) Microsoft Corporation
// All rights reserved.
//
// MIT License:
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
package com.microsoft.projectoxford.face.contract;

public class Emotion {
public double anger;
public double contempt;
public double disgust;
public double fear;
public double happiness;
public double neutral;
public double sadness;
public double surprise;
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ public class FaceAttribute {
public HeadPose headPose;

public Glasses glasses;

public Emotion emotion;
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ from everyone in it.
<img src="SampleScreenshots/SampleRunning3.png" width="30%"/>

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

## Contributing
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>).
Expand Down
11 changes: 5 additions & 6 deletions Sample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(include: ['*.jar'], dir: 'libs')

//
// Use the following line to include client library for Face API from Maven Central Repository
//
compile 'com.microsoft.projectoxford:face:1.2.1'
compile "com.android.support:appcompat-v7:22.1.0"

compile 'com.microsoft.projectoxford:face:1.2.5'
compile 'com.android.support:appcompat-v7:22.1.0'
compile 'com.google.code.gson:gson:2.3.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
import android.widget.TextView;

import com.microsoft.projectoxford.face.FaceServiceClient;
import com.microsoft.projectoxford.face.contract.Emotion;
import com.microsoft.projectoxford.face.contract.Face;
import com.microsoft.projectoxford.face.contract.FacialHair;
import com.microsoft.projectoxford.face.contract.HeadPose;
import com.microsoft.projectoxford.face.samples.R;
import com.microsoft.projectoxford.face.samples.helper.ImageHelper;
import com.microsoft.projectoxford.face.samples.helper.LogHelper;
Expand Down Expand Up @@ -89,8 +92,10 @@ protected Face[] doInBackground(InputStream... params) {
new FaceServiceClient.FaceAttributeType[] {
FaceServiceClient.FaceAttributeType.Age,
FaceServiceClient.FaceAttributeType.Gender,
FaceServiceClient.FaceAttributeType.Glasses,
FaceServiceClient.FaceAttributeType.Smile,
FaceServiceClient.FaceAttributeType.Glasses,
FaceServiceClient.FaceAttributeType.FacialHair,
FaceServiceClient.FaceAttributeType.Emotion,
FaceServiceClient.FaceAttributeType.HeadPose
});
} catch (Exception e) {
Expand Down Expand Up @@ -366,15 +371,75 @@ public View getView(final int position, View convertView, ViewGroup parent) {

// Show the face details.
DecimalFormat formatter = new DecimalFormat("#0.0");
String face_description = "Age: " + formatter.format(faces.get(position).faceAttributes.age) + "\n"
+ "Gender: " + faces.get(position).faceAttributes.gender + "\n"
+ "Head pose(in degree): roll(" + formatter.format(faces.get(position).faceAttributes.headPose.roll) + "), "
+ "yaw(" + formatter.format(faces.get(position).faceAttributes.headPose.yaw) + ")\n"
+ "Glasses: " + faces.get(position).faceAttributes.glasses + "\n"
+ "Smile: " + formatter.format(faces.get(position).faceAttributes.smile);
String face_description = String.format("Age: %s\nGender: %s\nSmile: %s\nGlasses: %s\nFacialHair: %s\nHeadPose: %s",
faces.get(position).faceAttributes.age,
faces.get(position).faceAttributes.gender,
faces.get(position).faceAttributes.smile,
faces.get(position).faceAttributes.glasses,
getFacialHair(faces.get(position).faceAttributes.facialHair),
getEmotion(faces.get(position).faceAttributes.emotion),
getHeadPose(faces.get(position).faceAttributes.headPose)
);
((TextView) convertView.findViewById(R.id.text_detected_face)).setText(face_description);

return convertView;
}

private String getFacialHair(FacialHair facialHair)
{
return (facialHair.moustache + facialHair.beard + facialHair.sideburns > 0) ? "Yes" : "No";
}

private String getEmotion(Emotion emotion)
{
String emotionType = "";
double emotionValue = 0.0;
if (emotion.anger > emotionValue)
{
emotionValue = emotion.anger;
emotionType = "Anger";
}
if (emotion.contempt > emotionValue)
{
emotionValue = emotion.contempt;
emotionType = "Contempt";
}
if (emotion.disgust > emotionValue)
{
emotionValue = emotion.disgust;
emotionType = "Disgust";
}
if (emotion.fear > emotionValue)
{
emotionValue = emotion.fear;
emotionType = "Fear";
}
if (emotion.happiness > emotionValue)
{
emotionValue = emotion.happiness;
emotionType = "Happiness";
}
if (emotion.neutral > emotionValue)
{
emotionValue = emotion.neutral;
emotionType = "Neutral";
}
if (emotion.sadness > emotionValue)
{
emotionValue = emotion.sadness;
emotionType = "Sadness";
}
if (emotion.surprise > emotionValue)
{
emotionValue = emotion.surprise;
emotionType = "Surprise";
}
return String.format("%s: %f", emotionType, emotionValue);
}

private String getHeadPose(HeadPose headPose)
{
return String.format("Pitch: %s, Roll: %s, Yaw: %s", headPose.pitch, headPose.roll, headPose.yaw);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services
//
// Microsoft Cognitive Services (formerly Project Oxford) GitHub:
// https://github.com/Microsoft/ProjectOxford-ClientSDK
// https://github.com/Microsoft/Cognitive-Face-Android
//
// Copyright (c) Microsoft Corporation
// All rights reserved.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services
//
// Microsoft Cognitive Services (formerly Project Oxford) GitHub:
// https://github.com/Microsoft/ProjectOxford-ClientSDK
// https://github.com/Microsoft/Cognitive-Face-Android
//
// Copyright (c) Microsoft Corporation
// All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion Sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.android.tools.build:gradle:2.2.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
12 changes: 6 additions & 6 deletions Sample/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Jun 06 16:40:57 PDT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
#Wed Dec 21 14:05:31 CST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

0 comments on commit f466981

Please sign in to comment.