我想使用我的代码针对我的clarifai应用程序中的现有图像搜索图像。
我正在从Java代码中调用 Clarifai API,并且获得了成功的响应。
但是我没有得到有效的图像URL作为响应。如果我做错了任何人,可以指导我吗?
下面给出了我的Java代码
public List<String> startClarifaiCall() {
List<String> imageURLList = new ArrayList<String>();
int resultSize = 0;
String clarifaiURLImage = "";
ClarifaiClient client = new ClarifaiBuilder("4d9d30e02e5c4caaa4eb5cf2d18a28c2").buildSync();
ClarifaiResponse<SearchInputsResult> clarifaiResponse =
client.searchInputs(
SearchClause.matchImageVisually(
ClarifaiImage.of("http://kathycooperfloorcloths.com/images/artfloorlargebluesuzanni.jpg")))
.getPage(1).executeSync();
System.out.println("Response JSON: "+ clarifaiResponse.rawBody());
if(clarifaiResponse.isSuccessful()) {
System.out.println("responce success: "+clarifaiResponse.getStatus().description());
System.out.println("responce code: "+clarifaiResponse.getStatus().statusCode());
SearchInputsResult inputsResult = clarifaiResponse.get();
resultSize = inputsResult.searchHits().size();
System.out.println("resultSize: "+resultSize);
for ( SearchHit searchHit : inputsResult.searchHits()) {
System.out.println("searchHit id: "+searchHit.input().id());
System.out.println("searchHit score: "+searchHit.score());
clarifaiURLImage = searchHit.input().inputValue().toString();
//clarifaiURLImage = "image\":{\"url\":\"https://s3.amazonaws.com/clarifai-api/img3/prod/small/0649bfb9dbd74c969f8227719abf8f56/a10468ad49606451bd2881d1deba8476\"}";
clarifaiURLImage = clarifaiURLImage.substring(clarifaiURLImage.indexOf("https"), clarifaiURLImage.lastIndexOf('}'));
System.out.println("searchHit ClarifaiURLImage: "+clarifaiURLImage);
if(searchHit.score()>=0.7) {
imageURLList.add(clarifaiURLImage);
}
}
System.out.println("\n");
} else {
System.out.println("responce failure: "+clarifaiResponse.getStatus().description());
System.out.println("error details: "+clarifaiResponse.getStatus().errorDetails());
}
return imageURLList;
}
我得到波纹管输出。但是图片网址不是有效的图片链接:
responce success: Ok
responce code: 10000
resultSize: 3
searchHit id: 3abd65d787a9486cad467e0d33bd2214
searchHit score: 0.71550095
searchHit ClarifaiURLImage: https://s3.amazonaws.com/clarifai-api/img3/prod/small/0649bfb9dbd74c969f8227719abf8f56/a10468ad49606451bd2881d1deba8476
searchHit id: e36bd9a71fc54de4acd39b511aca5e3c
searchHit score: 0.7147794
searchHit ClarifaiURLImage: https://s3.amazonaws.com/clarifai-api/img3/prod/small/0649bfb9dbd74c969f8227719abf8f56/4ee2739d9dbed1358298aa9e9a65a422
searchHit id: 8b543b3639ed440185b0886a5a3a6001
searchHit score: 0.71341443
searchHit ClarifaiURLImage: https://s3.amazonaws.com/clarifai-api/img3/prod/small/0649bfb9dbd74c969f8227719abf8f56/15a31caa8d3cbdc65e4e7a63a242ffb9
如果我做错了任何人都可以提供帮助。