0

I have succesfully implemented the below:

private FaceServiceClient faceServiceClient =
        new FaceServiceRestClient("xxx", "yyy"); 
private void detectAndFrame(final Bitmap imageBitmap)
{
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
    ByteArrayInputStream inputStream =
            new ByteArrayInputStream(outputStream.toByteArray());
    AsyncTask<InputStream, String, Face[]> detectTask =
            new AsyncTask<InputStream, String, Face[]>() {
                @Override
                protected Face[] doInBackground(InputStream... params) {
                    try {
                        publishProgress("Detecting...");
                        Log.e("face", "detecting");
                        Face[] result = faceServiceClient.detect(
                                params[0],
                                false,         // returnFaceId
                                false,        // returnFaceLandmarks
                                null   // returnFaceAttributes: a string like "age, gender"
                        );

Now I want to get the face attributes like :

Age,Gender,FacialHair

Question 1:

  • I am importing FACE API 1.0 at the moment, is there any update version?
  • I am using FACE API on IOS as well and in Android I do not see attributes I can see in IOS like glasses, why?

Question 2:

I need an help on changing the query so it can get attributes like Age,Gender. I tried to change

null   // returnFaceAttributes: a string like "age, gender" 

to

age,gender   // returnFaceAttributes: a string like "age, gender"

or "Age, Gender" , or [age, gender] or [Age, Gender] with no luck.

From the interface I see:

public interface FaceServiceClient {
    Face[] detect(String var1, boolean var2, boolean var3, FaceServiceClient.FaceAttributeType[] var4) throws ClientException, IOException;

    Face[] detect(InputStream var1, boolean var2, boolean var3, FaceServiceClient.FaceAttributeType[] var4) throws ClientException, IOException;

and

public static enum FaceAttributeType {
    Age {
        public String toString() {
            return "age";
        }
    },
    Gender {
        public String toString() {
            return "gender";
        }
    },
    FacialHair {
        public String toString() {
            return "facialHair";
        }
    },
    Smile {
        public String toString() {
            return "smile";
        }
    },
    HeadPose {
        public String toString() {
            return "headPose";
        }
    };

How I have to format those parameters to get the values ?

Question 3:

I need to gather and work the output I receive from the call. What are the variables of the object returned? Like number of faces detected, age, gender?

czane
  • 392
  • 1
  • 6
  • 18

1 Answers1

2
  1. v1.0 is the most current API.
  2. The third argument to detect is an array of enumerated types. You can see a sample app here. The relevant code is thus:

    return faceServiceClient.detect(
            params[0],
            false,       /* Whether to return face ID */
            false,       /* Whether to return face landmarks */
            new FaceServiceClient.FaceAttributeType[] {
                    FaceServiceClient.FaceAttributeType.Age,
                    FaceServiceClient.FaceAttributeType.Gender
            });
    
  3. The response is an array of faces. The face count would be the length of said array. The age and gender face[n].faceAttributes.age and face[n].faceAttributes.gender, respectively.

cthrash
  • 2,938
  • 2
  • 11
  • 10
  • Super! I see currently we support: age,gender,headPose,smile,facialHair */ . Any idea when the other values like glasses will be supported also in Android? – czane Feb 05 '18 at 09:35
  • It should already be there. Is it not? Here's the complete list: https://github.com/Microsoft/Cognitive-Face-Android/blob/994f0b360aac19f1cbd94c759f494bb6ce8a0552/ClientLibrary/lib/src/main/java/com/microsoft/projectoxford/face/FaceServiceClient.java – cthrash Feb 05 '18 at 17:03
  • It isn't, with implementation 'com.microsoft.projectoxford:face:1.0.0' I just have FaceAttributeType.Age FaceAttributeType.Gender FaceAttributeType.Smile FaceAttributeType.FacialHair FaceAttributeType.HeadPose. Can you please check? – czane Feb 05 '18 at 17:46
  • Are you pulling packages from [Maven](https://mvnrepository.com/artifact/com.microsoft.projectoxford/vision)? You should be pulling in the latest version, which is 1.0.394 at the moment. – cthrash Feb 06 '18 at 00:18
  • Error:(85, 20) Failed to resolve: com.microsoft.projectoxford:face:1.0.394 using allprojects { repositories { jcenter() google() maven { url "https://dl.bintray.com/hani-momanii/maven" } } – czane Feb 06 '18 at 07:49
  • My mistake - that's the version for Vision API. Face API is [here](https://mvnrepository.com/artifact/com.microsoft.projectoxford/face). Version is **1.3.0**. – cthrash Feb 06 '18 at 16:18
  • Right ok. Build gradle finished, new values kept. Thanks! – czane Feb 06 '18 at 17:39