我正在阅读 Microsoft 面向 Android 手持设备的 Face API 的入门教程。截至目前,除了识别部分之外的一切都有效。我可以浏览照片了。但是,检测方法总是返回 null,因此没有绘制红色矩形。如果有人已经成功完成了本教程,如果您能帮助我,我将不胜感激。下面是检测方法:
public Face[] detect(InputStream image, boolean analyzesFaceLandmarks, boolean analyzesAge, boolean analyzesGender, boolean analyzesHeadPose) throws ClientException, IOException {
Map<String, Object> params = new HashMap<>();
params.put("analyzesAge", analyzesAge);
params.put("analyzesGender", analyzesGender);
params.put("analyzesFaceLandmarks", analyzesFaceLandmarks);
params.put("analyzesHeadPose", analyzesHeadPose);
String path = ServiceHost + "/detections";
String uri = WebServiceRequest.getUrl(path, params);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int bytesRead;
byte[] bytes = new byte[1024];
while ((bytesRead = image.read(bytes)) > 0) {
byteArrayOutputStream.write(bytes, 0, bytesRead);
}
byte[] data = byteArrayOutputStream.toByteArray();
params.clear();
params.put("data", data);
String json = this.restCall.request(uri, "POST", params, "application/octet-stream");
Type listType = new TypeToken<List<Face>>() {
}.getType();
List<Face> faces = this.gson.fromJson(json, listType);
return faces.toArray(new Face[faces.size()]);
}