Android使用faceAttributesType

时间:2018-02-04 10:49:44

标签: microsoft-cognitive face-api

我已成功实施以下内容:

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"
                        );

现在我想获得像:

这样的面部属性

年龄,性别,FacialHair

问题1:

  • 我现在正在导入FACE API 1.0,有没有更新版本?
  • 我也在IOS上使用FACE API而在Android中我看不到IOS中可以看到的属性,比如眼镜,为什么?

问题2:

我需要帮助更改查询,以便获取Age,Gender等属性。 我试图改变

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

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

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

从界面中我看到:

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;

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";
        }
    };

我如何格式化这些参数以获取值?

问题3:

我需要收集并处理从通话中收到的输出。返回的对象有哪些变量?与检测到的面部数量,年龄,性别一样?

1 个答案:

答案 0 :(得分:1)

  1. v1.0是最新的API。
  2. detect的第三个参数是枚举类型的数组。您可以看到示例应用here。因此相关的代码是:

    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. 响应是一组面孔。面数将是所述阵列的长度。年龄和性别分别为face[n].faceAttributes.ageface[n].faceAttributes.gender