StupidBeauty
Read times:2096Posted at: - no title specified

FacePlusPlus Java SDK文档翻译

这个SDK使用apache.http库和json库。

1. 安装

  1. 1. 下载 facepp.jar

  2. 2. 将它加入到java项目中。

2. 导入Import)包

  • •. import com.facepp.*;

  • •.利用妳的编辑器或集成开发环境的自动补全功能。

3. 调用FaceppAPI

  1. 1.创建一个com.facepp.http.HttpRequests对象

    HttpRequests httpRequests = new HttpRequests(you_api_key_string, you_api_secret_string);

  2. 2.创建一个com.facepp.http.PostParameters对象,用于传递所有参数

    PostParameters postParameters = new PostParameters().setUrl("http://faceplusplus.com/static/img/demo/8.jpg").setAttribute("all");

  3. 3.发起请求

    httpRequests.request("detection", "detect", postParameters);

    httpRequests.detectionDetect(postParameters);

  4. 4.使用com.facepp.json.FaceppJson 对象来获取结果

    FaceppResult result = httpRequests.detectionDetect(postParameters);

4. 从结果中获取各个值

  • •.示例

    result.get("face").getCount()

    result.get("face").get(0).get("face_id").toString()

    result.get("face").get(0).get("").toString("attribute").get("gender").get("confidence").toDouble()

5. 调试

  1. 1.对发送的请求进行调查

    postParameters.getMultiPart().writeTo(System.out);

  2. 2.将结果作为一个纯json来调查

    System.out.println(result)

    • •.一个多片断(multipart)http post 消息示例

      --0soLYaK4lNBytrh912fNS15mSORsgy_J
      Content-Disposition: form-data; name=" person_name "
      Content-Type: text/plain; charset=US-ASCII
      Content-Transfer-Encoding: 8bit

      my_person_name
      --0soLYaK4lNBytrh912fNS15mSORsgy_J
      Content-Disposition: form-data; name=" group_name "
      Content-Type: text/plain; charset=US-ASCII
      Content-Transfer-Encoding: 8bit

      my_group_name
      --0soLYaK4lNBytrh912fNS15mSORsgy_J--

6. 安卓注意事项

  • •. 注意 ,不能在 MainActivity 的线程 中发起请求。 妳需要在一个新的线程中做这件事

  • •. 注意 ,妳需要向 AndroidManifest.xml 中加入关于互联网访问的 uses-permission

    <uses-permission android:name="android.permission.INTERNET"/>

7. 更多示例代码

  • •.FaceppDemo

    利用FaceppSDK实现的一个Java项目

  • •.FaceppAndroidDemo

    利用FaceppSDK实现的一个安卓项目

  • •.PictureDetect

    一个安卓应用。先选择一张照片,利用FaceppSDK 进行检测,然后将人脸标识出来。

风吹就倒的美人

Your opinions
Your name:Email:Website url:Opinion content:
- no title specified

HxLauncher: Launch Android applications by voice commands