Android 使用 faceAttributesType 调用 Face[] 检测

Android calling Face[] detect with faceAttributesType

我已经成功实施了以下内容:

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

现在我想获取面部属性,例如:

年龄、性别、面部毛发

问题 1:

问题 2:

我需要有关更改查询的帮助,以便它可以获得年龄、性别等属性。 我试着改变

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. 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