我已成功实施以下内容:
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:
问题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:
我需要收集并处理从通话中收到的输出。返回的对象有哪些变量?与检测到的面部数量,年龄,性别一样?
答案 0 :(得分:1)
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
});
响应是一组面孔。面数将是所述阵列的长度。年龄和性别分别为face[n].faceAttributes.age
和face[n].faceAttributes.gender
。