关于api:华为云API人脸识别服务FRS的感知力偷偷藏不住的你

28次阅读

共计 15469 个字符,预计需要花费 39 分钟才能阅读完成。

云服务、API、SDK,调试,查看,我都行

浏览短文您能够学习到:人工智能 AI 人脸的辨认、检测、搜寻、比对

1、IntelliJ IDEA 之 API 插件介绍

API 插件反对 VS Code IDE、IntelliJ IDEA 等平台、以及华为云自研 CodeArts IDE,基于华为云服务提供的能力,帮忙开发者更高效、便捷的搭建利用。API 插件关联华为云服务下的 API Explorer、DevStar、CodeLabs、SDK 核心和 CLI 核心产品,致力于为开发者提供更稳固、疾速、平安的编程体验。

在本插件中,咱们提供了但不局限于如下的性能:

对接华为云 API 开放平台,反对用户检索 API、查看 API 文档、调试 API、以及提供 SDK 示例代码供用户学习如何应用 API。

提供华为云 SDK 代码片段补全性能,SDK 依赖包主动引入,减速用户集成华为云 API。

对接华为云开发体验馆 Codelabs,提供 500+ 云服务代码示例,向导式教程帮忙用户疾速学习。

阐明:

在 IntelliJ IDEA 等系列平台和 VS Code IDE,华为云 API 插件的名称是 Huawei Cloud API。而在 CodeArts IDE,API 插件是 IDE 原生内置的,名称是华为云 API 开发套件。

API 插件在 IntelliJ IDEA 等系列平台和 VS Code IDE 的应用依赖底座插件,请提前装置底座插件。

2、API 插件装置 –IntelliJ IDEA

2.1 IntelliJ IDEA 等平台

装置筹备:下载并装置 JDK1.8 或更高版本。下载并装置 IntelliJ IDEA 2020.2 或更高版本。

须知:IntellIj 平台同时撑持包含 Goland、Pycharm 等在内的 IDE,若在其它相干 IDE 上开发,请下载配置好对应语言的编译器或者解释器。这里以 IDEA 为例介绍 IntelliJ 平台插件的装置流程,其余 IntelliJ 系列的 IDE 请参考 IDEA。

开始装置:

您能够在间接在 IDE 插件市场或者间接在 JetBrains 插件市场下载离线包装置。

https://developer.huaweicloud.com/develop/toolkit.html

IDE 装置

  1. 在 IntelliJ IDEA 顶部菜单栏中抉择 File > Settings,在 Settings 对话框的左侧导航栏中单击 Plugins。
  2. Plugins 区域单击 Marketplace, 在搜寻栏中输出 Huawei Cloud API。
  3. Search Results 区域会呈现 Huawei Cloud API,单击 Install,实现后重启 IDE。

离线包装置:

  1. 进入插件市场搜寻 Huawei Cloud API,进入插件详情页,在 Versions 页签下抉择想要版本的 API 插件,点击 Download 下载离线的插件压缩包保留到本地。。
  2. 在 IntelliJ IDEA 顶部菜单栏中抉择 File > Settings,在 Settings 对话框的左侧导航栏中单击 Plugins。
  3. 在 Plugins 区域单击,再单击 Install Plugin from Disk…。
  4. 在 Choose Plugin File 对话框中抉择离线安装包(不必解压),并依照 IntelliJ IDEA 装置页面的提醒,实现后续装置步骤。

阐明:若以后您想要装置插件的 IntelliJ IDE 曾经在桌面关上,则进入插件市场搜寻 Huawei Cloud API,进入插件详情页,在右上角会辨认到本地曾经关上的 IDE,点击相应按钮,在弹出的 IDE 窗口中点击 ok,则 IDE 后盾会开始装置相应版本的 API 插件。

装置验证:在 IntelliJ 系列平台上装置插件胜利后在左侧的导航栏中能够看到 Huawei Cloud Toolkit 图标,点击后面板会呈现 Huawei Cloud API 的字样,则阐明装置胜利。

2.2 华为云 API

https://developer.huaweicloud.com/develop/toolkit.html

左侧展现 API 列表,能够查问所有 API,目前云服务 206,APIs9213

3、抓住偷偷藏不住的你

3.1 后期筹备

华为云提供了人脸识别服务端 SDK,您能够间接集成服务端 SDK 来调用人脸识别服务的相干 API,从而实现对人脸识别服务的疾速操作。

该示例展现了如何通过 Java 版 SDK 实现人脸识别。

开发前筹备:

  • 已注册华为云,并实现实名认证。
  • 已订阅人脸识别服务。
  • 已具备开发环境,反对 Java JDK 1.8 及其以上版本。
  • 已获取华为云账号对应的 Access Key(AK)和 Secret Access Key(SK)。请在华为云控制台“我的凭证 > 拜访密钥”页面上创立和查看您的 AK/SK。具体请参见 拜访密钥。
  • 已获取直播服务对应区域的我的项目 ID,请在华为云控制台“我的凭证 > API 凭证”页面上查看我的项目 ID。具体请参见 API 凭证。

装置 SDK:

您能够通过 Maven 配置所依赖的人脸识别服务 SDK

<dependency>

    <groupId>com.huaweicloud.sdk</groupId>

    <artifactId>huaweicloud-sdk-frs</artifactId>

    <version>3.1.19</version>

</dependency>

开始应用:

导入依赖模块

import com.huaweicloud.sdk.core.auth.ICredential;

import com.huaweicloud.sdk.core.auth.BasicCredentials;

import com.huaweicloud.sdk.core.exception.ConnectionException;

import com.huaweicloud.sdk.core.exception.RequestTimeoutException;

import com.huaweicloud.sdk.core.exception.ServiceResponseException;

//v2 版本 sdk

import com.huaweicloud.sdk.frs.v2.region.FrsRegion;

import com.huaweicloud.sdk.frs.v2.*;

import com.huaweicloud.sdk.frs.v2.model.*;

初始化认证信息

public static ICredential getCredential(String ak, String sk) {return new BasicCredentials()

            .withAk(ak)

            .withSk(sk);

}

相干参数阐明如下所示:

ak:华为云账号 Access Key。

sk:华为云账号 Secret Access Key。

初始化人脸识别服务的客户端

public static FrsClient getClient(Region region, ICredential auth) {

    // 初始化人脸识别服务的客户端

    return FrsClient.newBuilder()

            .withCredential(auth)

            .withRegion(region) // 抉择服务所在区域 FrsRegion.CN_NORTH_4

            .build();}

相干参数阐明如下所示:

service region: 服务所在区域,例如:

CN_NORTH_1 北京一

CN_NORTH_4 北京四

SDK demo 代码解析

3.2 人脸识别 / 检测

DetectFaceByBase64Request detectRequest = new DetectFaceByBase64Request();
FaceDetectBase64Req faceDetectBase64Req = new FaceDetectBase64Req();
faceDetectBase64Req.withImageBase64("/9j/4AAQSkZJRgABAQAAAQABAAD...");
faceDetectBase64Req.withAttributes("2");
detectRequest.setBody(faceDetectBase64Req);
try {DetectFaceByBase64Response detectResponse = client.detectFaceByBase64(detectRequest);
    System.out.println(detectResponse.toString());
} catch (ConnectionException e) {e.printStackTrace();
} catch (RequestTimeoutException e) {e.printStackTrace();
} catch (ServiceResponseException e) {e.printStackTrace();
    System.out.println(e.getHttpStatusCode());
    System.out.println(e.getErrorCode());
    System.out.println(e.getErrorMsg());
}
3.2.1    人脸比对
CompareFaceByBase64Request compareRequest = new CompareFaceByBase64Request();
FaceCompareBase64Req faceCompareBase64Req = new FaceCompareBase64Req();
faceCompareBase64Req.withImage1Base64("/9j/4AAQSkZJRgABAQAAAQABAAD...");
faceCompareBase64Req.withImage2Base64("/9j/4AAQSkZJRgABAQAAAQABAAD...");
compareRequest.withBody(faceCompareBase64Req);
try {CompareFaceByBase64Response compareResponse = client.compareFaceByBase64(compareRequest);
    System.out.println(compareResponse.toString());
} catch (ConnectionException e) {e.printStackTrace();
} catch (RequestTimeoutException e) {e.printStackTrace();
} catch (ServiceResponseException e) {e.printStackTrace();
    System.out.println(e.getHttpStatusCode());
    System.out.println(e.getErrorCode());
    System.out.println(e.getErrorMsg());
}

3.2.2 人脸搜寻

SearchFaceByBase64Request searchRequest = new SearchFaceByBase64Request();
searchRequest.withFaceSetName("face_set_name");
FaceSearchBase64Req faceSearchBase64Req = new FaceSearchBase64Req();
List<Map<String, String>> listbodySort = new ArrayList<>();
Map<String, String> map = new HashMap<>();
map.put("timestamp","asc");
listbodySort.add(map);
List<String> listbodyReturnFields = new ArrayList<>();
listbodyReturnFields.add("timestamp");
listbodyReturnFields.add("id");
faceSearchBase64Req.withSort(listbodySort);
faceSearchBase64Req.withReturnFields(listbodyReturnFields);
faceSearchBase64Req.withImageBase64("/9j/4AAQSkZJRgABAQAAAQABAAD...");
searchRequest.withBody(faceSearchBase64Req);
try {SearchFaceByBase64Response searchResponse = client.searchFaceByBase64(searchRequest);
    System.out.println(searchResponse.toString());
} catch (ConnectionException e) {e.printStackTrace();
} catch (RequestTimeoutException e) {e.printStackTrace();
} catch (ServiceResponseException e) {e.printStackTrace();
    System.out.println(e.getHttpStatusCode());
    System.out.println(e.getErrorCode());
    System.out.println(e.getErrorMsg());
}

创建人脸库

CreateFaceSetRequest createFaceSetRequest = new CreateFaceSetRequest();
CreateFaceSetReq createFaceSetReq = new CreateFaceSetReq();
createFaceSetReq.withFaceSetName("face_set_name");
Map<String, TypeInfo> stringTypeInfoMap = new HashMap<>();
TypeInfo typeInfo = new TypeInfo();
typeInfo.withType("long");
stringTypeInfoMap.put("timestamp", typeInfo);
createFaceSetReq.withExternalFields(stringTypeInfoMap);
createFaceSetRequest.withBody(createFaceSetReq);
try {CreateFaceSetResponse createFaceSetResponse = client.createFaceSet(createFaceSetRequest);
    System.out.println(createFaceSetResponse.toString());
} catch (ConnectionException e) {e.printStackTrace();
} catch (RequestTimeoutException e) {e.printStackTrace();
} catch (ServiceResponseException e) {e.printStackTrace();
    System.out.println(e.getHttpStatusCode());
    System.out.println(e.getErrorCode());
    System.out.println(e.getErrorMsg());
}

查问人脸库

ShowFaceSetRequest showFaceSetRequest = new ShowFaceSetRequest();
showFaceSetRequest.withFaceSetName("face_set_name");
try {ShowFaceSetResponse showFaceSetResponse = client.showFaceSet(showFaceSetRequest);
    System.out.println(showFaceSetResponse.toString());
} catch (ConnectionException e) {e.printStackTrace();
} catch (RequestTimeoutException e) {e.printStackTrace();
} catch (ServiceResponseException e) {e.printStackTrace();
    System.out.println(e.getHttpStatusCode());
    System.out.println(e.getErrorCode());
    System.out.println(e.getErrorMsg());
}

查问所有人脸库

ShowAllFaceSetsRequest showAllFaceSetsRequest = new ShowAllFaceSetsRequest();
try {ShowAllFaceSetsResponse showAllFaceSetsResponse = client.showAllFaceSets(showAllFaceSetsRequest);
    System.out.println(showAllFaceSetsResponse.toString());
} catch (ConnectionException e) {e.printStackTrace();
} catch (RequestTimeoutException e) {e.printStackTrace();
} catch (ServiceResponseException e) {e.printStackTrace();
    System.out.println(e.getHttpStatusCode());
    System.out.println(e.getErrorCode());
    System.out.println(e.getErrorMsg());
}

删除人脸库

DeleteFaceSetRequest deleteFaceSetRequest = new DeleteFaceSetRequest();
deleteFaceSetRequest.withFaceSetName("face_set_name");
try {DeleteFaceSetResponse deleteFaceSetResponse = client.deleteFaceSet(deleteFaceSetRequest);
    System.out.println(deleteFaceSetResponse.toString());
} catch (ConnectionException e) {e.printStackTrace();
} catch (RequestTimeoutException e) {e.printStackTrace();
} catch (ServiceResponseException e) {e.printStackTrace();
    System.out.println(e.getHttpStatusCode());
    System.out.println(e.getErrorCode());
    System.out.println(e.getErrorMsg());
}

增加人脸

//add face
AddFacesByBase64Request addFacesByBase64Request = new AddFacesByBase64Request();
addFacesByBase64Request.withFaceSetName("face_set_name");
AddFacesBase64Req addFacesBase64Req = new AddFacesBase64Req();
addFacesBase64Req.withExternalFields("{"timestamp":12}");
addFacesBase64Req.withImageBase64("9j/4AAQSkZJRgABAQAAAQABAAD...");
addFacesByBase64Request.withBody(addFacesBase64Req);
try {AddFacesByBase64Response addFacesByBase64Response = client.addFacesByBase64(addFacesByBase64Request);
    System.out.println(addFacesByBase64Response.toString());
} catch (ConnectionException e) {e.printStackTrace();
} catch (RequestTimeoutException e) {e.printStackTrace();
} catch (ServiceResponseException e) {e.printStackTrace();
    System.out.println(e.getHttpStatusCode());
    System.out.println(e.getErrorCode());
    System.out.println(e.getErrorMsg());
}

删除人脸

//delete face by faceId
DeleteFaceByFaceIdRequest deleteFaceByFaceIdRequest = new DeleteFaceByFaceIdRequest();
deleteFaceByFaceIdRequest.withFaceSetName("face_set_name");
deleteFaceByFaceIdRequest.withFaceId("iexEBb6t");
try {DeleteFaceByFaceIdResponse deleteFaceByFaceIdResponse = client.deleteFaceByFaceId(deleteFaceByFaceIdRequest);
    System.out.println(deleteFaceByFaceIdResponse.toString());
} catch (ConnectionException e) {e.printStackTrace();
} catch (RequestTimeoutException e) {e.printStackTrace();
} catch (ServiceResponseException e) {e.printStackTrace();
    System.out.println(e.getHttpStatusCode());
    System.out.println(e.getErrorCode());
    System.out.println(e.getErrorMsg());
}

批量删除人脸

BatchDeleteFacesRequest batchDeleteFacesRequest = new BatchDeleteFacesRequest();
batchDeleteFacesRequest.withFaceSetName("face_set_name");
DeleteFacesBatchReq deleteFacesBatchReq = new DeleteFacesBatchReq();
deleteFacesBatchReq.withFilter("age:[20 TO 30]");
batchDeleteFacesRequest.withBody(deleteFacesBatchReq);
try {BatchDeleteFacesResponse batchDeleteFacesResponse = client.batchDeleteFaces(batchDeleteFacesRequest);
    System.out.println(batchDeleteFacesResponse.toString());
} catch (ConnectionException e) {e.printStackTrace();
} catch (RequestTimeoutException e) {e.printStackTrace();
} catch (ServiceResponseException e) {e.printStackTrace();
    System.out.println(e.getHttpStatusCode());
    System.out.println(e.getErrorCode());
    System.out.println(e.getErrorMsg());
}

更新人脸

UpdateFaceRequest updateFaceRequest = new UpdateFaceRequest();
updateFaceRequest.withFaceSetName("face_set_name");
UpdateFaceReq updateFaceReq = new UpdateFaceReq();
updateFaceReq.withFaceId("iexEBb6t");
updateFaceRequest.withBody(updateFaceReq);
try {UpdateFaceResponse response = client.updateFace(updateFaceRequest);
    System.out.println(response.toString());
} catch (ConnectionException e) {e.printStackTrace();
} catch (RequestTimeoutException e) {e.printStackTrace();
} catch (ServiceResponseException e) {e.printStackTrace();
    System.out.println(e.getHttpStatusCode());
    System.out.println(e.getErrorCode());
    System.out.println(e.getErrorMsg());
}

查问人脸

//show faces by faceId
ShowFacesByFaceIdRequest showFacesByFaceIdRequest = new ShowFacesByFaceIdRequest();
showFacesByFaceIdRequest.withFaceSetName("face_set_name");
showFacesByFaceIdRequest.withFaceId("iexEBb6t");
try {ShowFacesByFaceIdResponse response = client.showFacesByFaceId(showFacesByFaceIdRequest);
    System.out.println(response.toString());
} catch (ConnectionException e) {e.printStackTrace();
} catch (RequestTimeoutException e) {e.printStackTrace();
} catch (ServiceResponseException e) {e.printStackTrace();
    System.out.println(e.getHttpStatusCode());
    System.out.println(e.getErrorCode());
    System.out.println(e.getErrorMsg());
}

 

3.3 活体辨认 / 检测

3.3.1 动作活体检测

//detect live by base64
DetectLiveByBase64Request request = new DetectLiveByBase64Request();
LiveDetectBase64Req body = new LiveDetectBase64Req();
body.withActions("1,2,3,4");
body.withVideoBase64("/9j/4AAQSkZJRgABAQAAAQABAAD...");
request.withBody(body);
try {DetectLiveByBase64Response response = client.detectLiveByBase64(request);
    System.out.println(response.toString());
} catch (ConnectionException e) {e.printStackTrace();
} catch (RequestTimeoutException e) {e.printStackTrace();
} catch (ServiceResponseException e) {e.printStackTrace();
    System.out.println(e.getHttpStatusCode());
    System.out.println(e.getErrorCode());
    System.out.println(e.getErrorMsg());
}

 

3.3.2 默活体检测

//detect live face by base64
DetectLiveFaceByBase64Request request = new DetectLiveFaceByBase64Request();
LiveDetectFaceBase64Req body = new LiveDetectFaceBase64Req();
body.withImageBase64("/9j/4AAQSkZJRgABAQAAAQABAAD...");
request.withBody(body);
try {DetectLiveFaceByBase64Response response = client.detectLiveFaceByBase64(request);
    System.out.println(response.toString());
} catch (ConnectionException e) {e.printStackTrace();
} catch (RequestTimeoutException e) {e.printStackTrace();
} catch (ServiceResponseException e) {e.printStackTrace();
    System.out.println(e.getHttpStatusCode());
    System.out.println(e.getErrorCode());
    System.out.println(e.getErrorMsg());
}

3.4 人脸搜寻

SearchFaceByBase64Request searchRequest = new SearchFaceByBase64Request();
searchRequest.withFaceSetName("face_set_name");
FaceSearchBase64Req faceSearchBase64Req = new FaceSearchBase64Req();
List<Map<String, String>> listbodySort = new ArrayList<>();
Map<String, String> map = new HashMap<>();
map.put("timestamp","asc");
listbodySort.add(map);
List<String> listbodyReturnFields = new ArrayList<>();
listbodyReturnFields.add("timestamp");
listbodyReturnFields.add("id");
faceSearchBase64Req.withSort(listbodySort);
faceSearchBase64Req.withReturnFields(listbodyReturnFields);
faceSearchBase64Req.withImageBase64("/9j/4AAQSkZJRgABAQAAAQABAAD...");
searchRequest.withBody(faceSearchBase64Req);
try {SearchFaceByBase64Response searchResponse = client.searchFaceByBase64(searchRequest);
    System.out.println(searchResponse.toString());
} catch (ConnectionException e) {e.printStackTrace();
} catch (RequestTimeoutException e) {e.printStackTrace();
} catch (ServiceResponseException e) {e.printStackTrace();
    System.out.println(e.getHttpStatusCode());
    System.out.println(e.getErrorCode());
    System.out.println(e.getErrorMsg());
}

3.5 人脸比对

CompareFaceByBase64Request compareRequest = new CompareFaceByBase64Request();
FaceCompareBase64Req faceCompareBase64Req = new FaceCompareBase64Req();
faceCompareBase64Req.withImage1Base64("/9j/4AAQSkZJRgABAQAAAQABAAD...");
faceCompareBase64Req.withImage2Base64("/9j/4AAQSkZJRgABAQAAAQABAAD...");
compareRequest.withBody(faceCompareBase64Req);
try {CompareFaceByBase64Request compareRequest = new CompareFaceByBase64Request();
FaceCompareBase64Req faceCompareBase64Req = new FaceCompareBase64Req();
faceCompareBase64Req.withImage1Base64("/9j/4AAQSkZJRgABAQAAAQABAAD...");
faceCompareBase64Req.withImage2Base64("/9j/4AAQSkZJRgABAQAAAQABAAD...");
compareRequest.withBody(faceCompareBase64Req);
try {CompareFaceByBase64Response compareResponse = client.compareFaceByBase64(compareRequest);
    System.out.println(compareResponse.toString());
} catch (ConnectionException e) {e.printStackTrace();
} catch (RequestTimeoutException e) {e.printStackTrace();
} catch (ServiceResponseException e) {e.printStackTrace();
    System.out.println(e.getHttpStatusCode());
    System.out.println(e.getErrorCode());
    System.out.println(e.getErrorMsg());
}
    CompareFaceByBase64Response compareResponse = client.compareFaceByBase64(compareRequest);
    System.out.println(compareResponse.toString());
} catch (ConnectionException e) {e.printStackTrace();
} catch (RequestTimeoutException e) {e.printStackTrace();
} catch (ServiceResponseException e) {e.printStackTrace();
    System.out.println(e.getHttpStatusCode());
    System.out.println(e.getErrorCode());
    System.out.println(e.getErrorMsg());
}

4、偷偷藏不住的你

身份验证

应用人脸检测与比对性能,可进行身份核实,实用于机场、海关等物证合一验证场景。

电子考勤

人脸检测及比对性能实用于客户企业对员工进行电子考勤。

客流剖析

客流剖析对于商场具备重要价值。基于人脸识别、搜寻技术,帮忙客户精准营销。

5、参考文献

https://support.huaweicloud.com/usermanual-cbs/cbs_01_0029.html

https://console.huaweicloud.com/cbs/?region=cn-north-4#/cbs/m…

6、体验插件的魅力

华为云 devkit 已上线:

正文完
 0