Python、Java SDK两种方式调用阿里云人脸检测与五官定位

Step By Step

1.开通人脸人体服务。

人脸人体
Python、Java SDK两种方式调用阿里云人脸检测与五官定位

2.获取您的真实AK信息

查看AK
Python、Java SDK两种方式调用阿里云人脸检测与五官定位

3.添加java依赖

       <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>4.4.14</version>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>facebody20191230</artifactId>
            <version>2.0.1</version>
        </dependency>

4.Java SDK Code

// This file is auto-generated, don't edit it. Thanks.
package com.aliyun.sample;

import com.aliyun.tea.*;
import com.aliyun.facebody20191230.*;
import com.aliyun.facebody20191230.models.*;
import com.aliyun.teaopenapi.*;
import com.aliyun.teaopenapi.models.*;
import com.google.gson.Gson;

public class Sample {

/**
 * 使用AK&SK初始化账号Client
 * @param accessKeyId
 * @param accessKeySecret
 * @return Client
 * @throws Exception
 */
public static com.aliyun.facebody20191230.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
    Config config = new Config()
            // 您的AccessKey ID
            .setAccessKeyId(accessKeyId)
            // 您的AccessKey Secret
            .setAccessKeySecret(accessKeySecret);
    // 访问的域名
    config.endpoint = "facebody.cn-shanghai.aliyuncs.com";
    return new com.aliyun.facebody20191230.Client(config);
}

public static void main(String[] args_) throws Exception {
    java.util.List<String> args = java.util.Arrays.asList(args_);
    com.aliyun.facebody20191230.Client client = Sample.createClient("ak", "sk");
    DetectFaceRequest detectFaceRequest = new DetectFaceRequest()
            .setImageURL("图片ossurl")
            .setLandmark(true);
    // 复制代码运行请自行打印 API 的返回值
    DetectFaceResponse response= client.detectFace(detectFaceRequest);
    System.out.println(new Gson().toJson(response));
}

}

5.运行结果

Python、Java SDK两种方式调用阿里云人脸检测与五官定位

6.添加python依赖

pip install alibabacloud_facebody20191230==3.0.1

7.Python SDK Code

# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import sys

from typing import List

from alibabacloud_facebody20191230.client import Client as facebody20191230Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_facebody20191230 import models as facebody_20191230_models


class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client(
        access_key_id: str,
        access_key_secret: str,
    ) -> facebody20191230Client:
        """
        使用AK&SK初始化账号Client
        @param access_key_id:
        @param access_key_secret:
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            # 您的AccessKey ID,
            access_key_id="ak",
            # 您的AccessKey Secret,
            access_key_secret="sk"
        )
        # 访问的域名
        config.endpoint = f'facebody.cn-shanghai.aliyuncs.com'
        return facebody20191230Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client('accessKeyId', 'accessKeySecret')
        detect_face_request = facebody_20191230_models.DetectFaceRequest(
            image_url='图片ossurl',
            landmark=True
        )
        # 复制代码运行请自行打印 API 的返回值
        res = client.detect_face(detect_face_request)
        print(res)

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        client = Sample.create_client('accessKeyId', 'accessKeySecret')
        detect_face_request = facebody_20191230_models.DetectFaceRequest(
            image_url='图片ossurl',
            landmark=True
        )
        # 复制代码运行请自行打印 API 的返回值
        await client.detect_face_async(detect_face_request)



if __name__ == '__main__':
    Sample.main(sys.argv[1:])

8.运行结果

Python、Java SDK两种方式调用阿里云人脸检测与五官定位

参考链接

人脸检测与五官定位

上一篇:阿里云内容安全java SDK实现本土图片审核


下一篇:Python学习笔记:通过python爬虫获取豆瓣电影Top250