【发布时间】:2018-07-17 13:29:52
【问题描述】:
我正在试用 Microsoft 的这段代码,但我想结合他们制作的 2 个功能。一种是分析图像,一种是检测名人。但是,我很难从一个函数返回 2 个值。 这里是处理方法...
private String process() throws VisionServiceException, IOException {
Gson gson = new Gson();
String model = "celebrities";
ByteArrayOutputStream output = new ByteArrayOutputStream();
bitmapPicture.compress(Bitmap.CompressFormat.JPEG, 100, output);
ByteArrayInputStream inputStream = new ByteArrayInputStream(output.toByteArray());
AnalysisResult v = this.client.describe(inputStream, 1);
AnalysisInDomainResult m = this.client.analyzeImageInDomain(inputStream,model);
String result = gson.toJson(v);
String result2 = gson.toJson(m);
Log.d("result", result);
return result, result2;
}
并用这种方法将2个结果结合起来......
@Override
protected void onPostExecute(String data) {
super.onPostExecute(data);
mEditText.setText("");
if (e != null) {
mEditText.setText("Error: " + e.getMessage());
this.e = null;
} else {
Gson gson = new Gson();
AnalysisResult result = gson.fromJson(data, AnalysisResult.class);
//pang detect ng peymus...
AnalysisInDomainResult result2 = gson.fromJson(data, AnalysisInDomainResult.class);
//decode the returned result
JsonArray detectedCelebs = result2.result.get("celebrities").getAsJsonArray();
if(result2.result != null){
mEditText.append("Celebrities detected: "+detectedCelebs.size()+"\n");
for(JsonElement celebElement: detectedCelebs) {
JsonObject celeb = celebElement.getAsJsonObject();
mEditText.append("Name: "+celeb.get("name").getAsString() +", score" +
celeb.get("confidence").getAsString() +"\n");
}
}else {
for (Caption caption: result.description.captions) {
mEditText.append("Your seeing " + caption.text + ", confidence: " + caption.confidence + "\n");
}
mEditText.append("\n");
}
/* for (String tag: result.description.tags) {
mEditText.append("Tag: " + tag + "\n");
}
mEditText.append("\n");
mEditText.append("\n--- Raw Data ---\n\n");
mEditText.append(data);*/
mEditText.setSelection(0);
}
}
提前致谢!
【问题讨论】:
-
在数组或列表(或其他集合)中,或通过复合对象
-
使用地图。和值的不同键。 E.gL map.put(result1,val1);map.put(result2,val2);返回地图;
-
我试过你的建议@akshayapandey。 Map.put(result, result);Map.put(result2, result2);但是,它在放置时出现错误,说“无法从静态上下文中引用非静态方法put(K,V)。如何解决这个问题?谢谢。
-
Map map = new HashMap(); map.put......
标签: java android return microsoft-cognitive