简体   繁体   English

Android中的FaceDetection在线API

[英]FaceDetection onLine API in Android

Can any one tell me which is the best way for onLine FaceDetection in Android. 谁能告诉我哪种方法是Android中在线FaceDetection的最佳方法。 Is there any API for the same? 是否有相同的API? If yes, then how we can implement that? 如果是,那么我们如何实现呢? Please suggest me for the right solution. 请为我建议正确的解决方案。

Thanks in advance. 提前致谢。

You can use Face.com API for the same. 您可以使用Face.com API来实现相同的目的。

It returns JSON response after facedetection. 人脸检测后返回JSON响应。 First you have to register on Face.com, it will generate your API ID and secret Key. 首先,您必须在Face.com上注册,它将生成您的API ID和秘密密钥。 Then you have to upload your image on the face.com server as: 然后,您必须以以下方式将图像上传到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;

This will return a response string as JSON, if the face is detected it gives all information about face if not then doen't give any information. 这将以JSON形式返回响应字符串,如果检测到面部,则将提供有关面部的所有信息,否则将不提供任何信息。 You have to parse that JSON and get the result and enjoy........ 您必须解析该JSON并获得结果并享受.......。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM