任何人都可以告诉我哪种是Android中onLine FaceDetection的最佳方式。有没有相同的API?如果是,那么我们如何实现呢?请建议我找到合适的解决方案。
提前致谢。
答案 0 :(得分:0)
您可以使用Face.com API。
它在facedetection后返回JSON响应。 首先,您必须在Face.com上注册,它将生成您的API ID和密钥。 然后,您必须将您的图像上传到face.com服务器上:
Bitmap img = BitmapFactory.decodeFile(paramFile.getPath());
System.out.println("The Width="+img.getWidth()+" & Height:"+img.getHeight());
String str = "";
if (this.httpclient == null)
{
BasicHttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 10000);
HttpConnectionParams.setSoTimeout(httpParams, 10000);
this.httpclient = new DefaultHttpClient(httpParams);
}
this.httpclient.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1);
HttpPost post = new HttpPost("http://api.face.com/faces/detect.json");
HttpClientParams.setCookiePolicy(post.getParams(), "compatibility");
MultipartEntity multiPart = new MultipartEntity();
multiPart.addPart("upload", new FileBody(paramFile, "image/jpeg"));
multiPart.addPart("api_key", new StringBody("5438f02c1f03bbd229e209abfc811cfb"));
multiPart.addPart("api_secret", new StringBody("6892f15e9721ad0e720a82f8a7d214c9"));
multiPart.addPart("f_upload", new StringBody(paramFile.getName()));
multiPart.addPart("detector", new StringBody("Aggressive"));
multiPart.addPart("attributes", new StringBody("all"));
post.setEntity(multiPart);
response = this.httpclient.execute(post);
HttpEntity responseEntity = response.getEntity();
if (responseEntity != null)
str = EntityUtils.toString(responseEntity);
return (String)str;
这将返回一个响应字符串作为JSON,如果检测到面部,它会提供有关面部的所有信息,如果没有,则不提供任何信息。你必须解析那个JSON并获得结果并享受........