全部产品

Re ID设备升级

更新时间:2020-08-20 11:35:28

慧眼通开放文档

对接流程

liucheng

依赖下载

  • 阿里云API网关SDK(链接

接口

请求图片地址

描述: 在上传人脸图片之前,首先从阿里云获取上传url,此url只用于上传(不支持下载图片),且有效期5分钟,超时无效;
path: /solution/commercial/paas/picture/getuploadurl
版本号: 1.0.0
约束: 只支持jpg/jpeg图片
请求参数

字段名称 类型 描述 是否必须
bizCode String 业务码,
10001-人脸图片
10002-广告推荐

返回参数

字段名称 类型 描述 是否必须
code Integer 返回码
message String 返回描述
data JSONArray 上传地址
fileKey String oss文件名称
fileUrl String oss上传地址

参考代码(Java)

  1. import com.alibaba.cloudapi.sdk.model.ApiResponse;
  2. import com.aliyun.iotx.api.client.IoTApiClientBuilderParams;
  3. import com.aliyun.iotx.api.client.IoTApiRequest;
  4. import com.aliyun.iotx.api.client.SyncApiClient;
  5. import com.google.common.collect.Maps;
  6. import java.util.Map;
  7. public class ApiService {
  8. private static String appKey = "xxx";
  9. private static String appSecret = "xxx";
  10. private static SyncApiClient syncApiClient = null;
  11. public static void main(String[] args) {
  12. try {
  13. // 初始化
  14. init();
  15. //请求参数
  16. IoTApiRequest request = new IoTApiRequest();
  17. //设置头
  18. Map<String, String> headers = Maps.newHashMap();
  19. //上报事件
  20. ApiResponse response = getUploadUrl(request, headers);
  21. // 打印结果
  22. System.out.println(
  23. "request-id = " + response.getHeaders().get("x-ca-request-id")
  24. + "\ncode = " + response.getCode()
  25. + "\nmessage = " + response.getMessage()
  26. + "\ncontent = " + new String(response.getBody(), "utf-8"));
  27. }catch (Exception e){
  28. e.printStackTrace();
  29. }
  30. }
  31. /**
  32. * 初始化
  33. */
  34. public static void init(){
  35. IoTApiClientBuilderParams builderParams = new IoTApiClientBuilderParams();
  36. builderParams.setAppKey(appKey);
  37. builderParams.setAppSecret(appSecret);
  38. syncApiClient = new SyncApiClient(builderParams);
  39. }
  40. /**
  41. * 请求图片地址
  42. * @param request
  43. * @param headers
  44. * @return
  45. * @throws Exception
  46. */
  47. public static ApiResponse getUploadUrl(IoTApiRequest request, Map<String, String> headers) throws Exception{
  48. //设置api的版本
  49. request.setApiVer("1.0.0");
  50. //设置参数
  51. request.putParam("bizCode", "10001");
  52. //请求参数版本,域名、pathrequest
  53. return syncApiClient.postBody("api.link.aliyun.com",
  54. "/solution/commercial/paas/picture/getuploadurl",
  55. request, true, headers);
  56. }
  57. }

上传图片

描述: 获取上传地址之后,直接通过http put方式上传图片
约束: 只支持jpg/jpeg图片,图片大小不宜超过6M,图片质量清晰、可明显辨识人脸
参考代码(Java)

  1. import org.apache.commons.io.IOUtils;
  2. import org.apache.http.HttpEntity;
  3. import org.apache.http.client.HttpClient;
  4. import org.apache.http.client.entity.EntityBuilder;
  5. import org.apache.http.client.methods.HttpPut;
  6. import org.apache.http.impl.client.HttpClients;
  7. import java.io.FileInputStream;
  8. import java.io.IOException;
  9. public class Demo {
  10. public static void main(String[] args) throws IOException {
  11. String fileUrl = "";
  12. String fileName="/Users/admin/Downloads/888888.jpg";
  13. //调用上传
  14. uploadPicture(fileUrl, fileName);
  15. }
  16. /**
  17. * 上传底库照片
  18. * @param fileUrl 图片oss上传地址
  19. * @param filePath 图片本地路径
  20. * @throws IOException
  21. */
  22. public static void uploadPicture(String fileUrl, String filePath) throws IOException {
  23. HttpClient httpClient = HttpClients.createDefault();
  24. HttpEntity reqEntity = null;
  25. reqEntity = EntityBuilder.create().setBinary(IOUtils.toByteArray(new FileInputStream(filePath))).build();
  26. HttpPut put = new HttpPut(fileUrl);
  27. put.setHeader("Content-Type", "application/octet-stream");
  28. put.setEntity(reqEntity);
  29. System.out.println("******* : " + reqEntity.getContentLength()/8/1024);
  30. httpClient.execute(put);
  31. }
  32. }

上报事件

path: /solution/commercial/paas/aidevice/post/event
版本号: 1.0.0
约束: 只支持jpg/jpeg图片,payload中包含rect用于标识人脸坐标,阿里云用此坐标裁剪人脸图片,
请求参数

字段名称 类型 描述 是否必须
dto JSON
thingType String 摄像头固定填写IPC
productKey String IoT平台productKey
deviceName String IoT平台deviceName
eventCode String IoT平台人脸检测事件码10008
eventName String 事件名称
eventTime Long 图像抓拍时间戳
pictureId String 图片上传之后由IoT平台返回的唯一Key, fileKey
payload String “{\”age\”:18,\”gender\”:\”male\”,\”rect\”:\”[0.21, 0.33, 0.62, 0.88]\”,\”blurScore\”:\”0.62\”,\”poseScore\”:\”0.8\”,\”landmarks\”:\”[[0.1, 0.1], [0.1, 0.1],[0.1, 0.1],[0.1, 0.1],[0.1, 0.1]]\”,\”trackId\”:\”xxx\”}”

返回参数

字段名称 类型 描述 是否必须
code Integer 返回码
message String 返回描述

参考代码(Java)

  1. import com.alibaba.cloudapi.sdk.model.ApiResponse;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.aliyun.iotx.api.client.IoTApiClientBuilderParams;
  4. import com.aliyun.iotx.api.client.IoTApiRequest;
  5. import com.aliyun.iotx.api.client.SyncApiClient;
  6. import com.google.common.collect.Maps;
  7. import java.util.Map;
  8. public class ApiService {
  9. private static String appKey = "xxx";
  10. private static String appSecret = "xxx";
  11. private static SyncApiClient syncApiClient = null;
  12. public static void main(String[] args) {
  13. try {
  14. // 初始化
  15. init();
  16. //请求参数
  17. IoTApiRequest request = new IoTApiRequest();
  18. //设置头
  19. Map<String, String> headers = Maps.newHashMap();
  20. //上报事件
  21. ApiResponse response = postEvent(request, headers);
  22. // 打印结果
  23. System.out.println(
  24. "request-id = " + response.getHeaders().get("x-ca-request-id")
  25. + "\ncode = " + response.getCode()
  26. + "\nmessage = " + response.getMessage()
  27. + "\ncontent = " + new String(response.getBody(), "utf-8"));
  28. }catch (Exception e){
  29. e.printStackTrace();
  30. }
  31. }
  32. /**
  33. * 初始化
  34. */
  35. public static void init(){
  36. IoTApiClientBuilderParams builderParams = new IoTApiClientBuilderParams();
  37. builderParams.setAppKey(appKey);
  38. builderParams.setAppSecret(appSecret);
  39. syncApiClient = new SyncApiClient(builderParams);
  40. }
  41. /**
  42. * 上报事件
  43. * @param request
  44. * @param headers
  45. * @return
  46. * @throws Exception
  47. */
  48. public static ApiResponse postEvent(IoTApiRequest request, Map<String, String> headers) throws Exception{
  49. //设置api的版本
  50. request.setApiVer("1.0.0");
  51. //设置参数
  52. //request.putParam("appId", "j7uLiStPSiZScgh5JlFv000100");
  53. JSONObject dto = new JSONObject();
  54. dto.put("thingType", "IPC");
  55. dto.put("productKey", "xxx");
  56. dto.put("deviceName", "xxx");
  57. dto.put("eventCode", "10008");
  58. dto.put("eventName", "人脸检测");
  59. dto.put("eventTime", "1594233255196");
  60. dto.put("pictureId", "xxx.jpg");
  61. dto.put("payload", "{\"age\":18,\"gender\":\"male\",\"rect\":\"[0.5945,0.3212,0.0313,0.0702]\",\"blurScore\":\"0.62\",\"poseScore\":\"0.8\",\"trackId\":\"xxxxxxxx\"}");
  62. request.putParam("dto", dto);
  63. //请求参数版本,域名、path、request
  64. return syncApiClient.postBody("api.link.aliyun.com",
  65. "/solution/commercial/paas/aidevice/post/event",
  66. request, true, headers);
  67. }
  68. }