赞
踩
云服务、API、SDK,调试,查看,我都行
阅读短文您可以学习到:人工智能AI人脸的识别、检测、搜索、比对
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的使用依赖底座插件,请提前安装底座插件。
安装准备:下载并安装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安装
离线包安装:
说明:若当前您想要安装插件的IntelliJ IDE已经在桌面打开,则进入插件市场搜索Huawei Cloud API,进入插件详情页,在右上角会识别到本地已经打开的IDE,点击相应按钮,在弹出的IDE窗口中点击ok,则IDE后台会开始安装相应版本的API插件。
安装验证:在IntelliJ系列平台上安装插件成功后在左侧的导航栏中可以看到Huawei Cloud Toolkit图标,点击后面板会出现Huawei Cloud API的字样,则说明安装成功。
左侧展示API列表,可以查询所有API,目前云服务206,APIs9213
华为云提供了人脸识别服务端SDK,您可以直接集成服务端SDK来调用人脸识别服务的相关API,从而实现对人脸识别服务的快速操作。
该示例展示了如何通过Java版SDK实现人脸识别。
开发前准备:
安装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代码解析
- 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());
- }
- 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());
- }
- //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());
- }
- //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());
- }
- 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());
- }
- 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());
- }
身份验证
使用人脸检测与比对功能,可进行身份核实,适用于机场、海关等人证合一验证场景。
电子考勤
人脸检测及比对功能适用于客户企业对员工进行电子考勤。
客流分析
客流分析对于商场具有重要价值。基于人脸识别、搜索技术,帮助客户精准营销。
https://support.huaweicloud.com/usermanual-cbs/cbs_01_0029.html
https://console.huaweicloud.com/cbs/?region=cn-north-4#/cbs/management/skills
华为云devkit已上线:https://developer.huaweicloud.com/develop/toolkit.html
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。