动作行为识别能力可以识别视频和图像中的人体动作行为,当前可以识别的行为类别包括举手、吸烟、打电话、洗手和拍照等。本文为您介绍动作行为识别常用语言的示例代码。
您可以进入在线咨询获取在线人工帮助。
阿里云视觉智能开放平台视觉AI能力API接入、接口使用或问题咨询等,请通过钉钉群(23109592)加入阿里云视觉智能开放平台咨询群联系我们。
能力介绍
关于动作行为识别的功能介绍以及具体调用参数说明,请参见动作行为识别。
SDK包安装
常见语言的SDK依赖包信息,请参见SDK总览。
配置环境变量
配置环境变量ALIBABA_CLOUD_ACCESS_KEY_ID和ALIBABA_CLOUD_ACCESS_KEY_SECRET。
阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维,具体操作,请参见创建RAM用户。
请不要将AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
Linux和macOS系统配置方法
在IntelliJ IDEA中打开终端Terminal。
执行以下命令,配置环境变量。
<access_key_id>
需替换为您RAM用户的AccessKey ID,<access_key_secret>
替换为您RAM用户的AccessKey Secret。如果后续需要进行更多权限相关的配置,具体操作请参见使用RAM Policy控制访问权限。export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id> export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>
Windows系统配置方法
新建环境变量文件,添加环境变量
ALIBABA_CLOUD_ACCESS_KEY_ID
和ALIBABA_CLOUD_ACCESS_KEY_SECRET
,并写入已准备好的AccessKey ID和AccessKey Secret。然后重启Windows系统。本操作以Windows 10为例进行说明。打开文件资源管理器,在此电脑上右键单击属性。
在右侧导航栏,单击高级系统配置。
在系统属性对话框的高级页签下,单击环境变量。
在环境变量对话框中,单击新建(W)。
在弹出的新建系统变量对话框中,添加环境变量
ALIBABA_CLOUD_ACCESS_KEY_ID
和ALIBABA_CLOUD_ACCESS_KEY_SECRET
,并写入已准备好的AccessKey ID和AccessKey Secret。重启Windows系统,使配置生效。
示例代码
文件在上海地域OSS
/*
引入依赖包
<!-- https://mvnrepository.com/artifact/com.aliyun/facebody20191230 -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>facebody20191230</artifactId>
<version>${aliyun.facebody.version}</version>
</dependency>
*/
import com.aliyun.facebody20191230.models.RecognizeActionResponse;
import com.aliyun.tea.TeaModel;
public class RecognizeAction {
public static com.aliyun.facebody20191230.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
/*
初始化配置对象com.aliyun.teaopenapi.models.Config
Config对象存放 AccessKeyId、AccessKeySecret、endpoint等配置
*/
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
.setAccessKeyId(accessKeyId)
.setAccessKeySecret(accessKeySecret);
// 访问的域名
config.endpoint = "facebody.cn-shanghai.aliyuncs.com";
return new com.aliyun.facebody20191230.Client(config);
}
public static void main(String[] args_) throws Exception {
// 创建AccessKey ID和AccessKey Secret,请参考https://help.aliyun.com/document_detail/175144.html
// 如果您使用的是RAM用户的AccessKey,还需要为子账号授予权限AliyunVIAPIFullAccess,请参考https://help.aliyun.com/document_detail/145025.html
// 从环境变量读取配置的AccessKey ID和AccessKey Secret。运行代码示例前必须先配置环境变量。
String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
com.aliyun.facebody20191230.Client client = RecognizeAction.createClient(accessKeyId, accessKeySecret);
com.aliyun.facebody20191230.models.RecognizeActionRequest.RecognizeActionRequestURLList URLList0 = new com.aliyun.facebody20191230.models.RecognizeActionRequest.RecognizeActionRequestURLList()
.setURL("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/1RecognizeAction1.png");
com.aliyun.facebody20191230.models.RecognizeActionRequest.RecognizeActionRequestURLList URLList1 = new com.aliyun.facebody20191230.models.RecognizeActionRequest.RecognizeActionRequestURLList()
.setURL("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/1RecognizeAction2.png");
com.aliyun.facebody20191230.models.RecognizeActionRequest.RecognizeActionRequestURLList URLList2 = new com.aliyun.facebody20191230.models.RecognizeActionRequest.RecognizeActionRequestURLList()
.setURL("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/1RecognizeAction3.png");
com.aliyun.facebody20191230.models.RecognizeActionRequest.RecognizeActionRequestURLList URLList3 = new com.aliyun.facebody20191230.models.RecognizeActionRequest.RecognizeActionRequestURLList()
.setURL("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/1RecognizeAction4.png");
com.aliyun.facebody20191230.models.RecognizeActionRequest recognizeActionRequest = new com.aliyun.facebody20191230.models.RecognizeActionRequest()
.setType(1)
.setURLList(java.util.Arrays.asList(
URLList0,
URLList1,
URLList2,
URLList3
));
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
try {
RecognizeActionResponse recognizeActionResponse = client.recognizeActionWithOptions(recognizeActionRequest, runtime);
// 获取整体结果
System.out.println(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(recognizeActionResponse)));
} catch (com.aliyun.tea.TeaException teaException) {
// 获取整体报错信息
System.out.println(com.aliyun.teautil.Common.toJSONString(teaException));
// 获取单个字段
System.out.println(teaException.getCode());
}
}
}
# -*- coding: utf-8 -*-
# 引入依赖包
# pip install alibabacloud_facebody20191230
import os
from alibabacloud_facebody20191230.client import Client
from alibabacloud_facebody20191230.models import RecognizeActionRequestURLList, RecognizeActionRequest
from alibabacloud_tea_openapi.models import Config
from alibabacloud_tea_util.models import RuntimeOptions
config = Config(
# 创建AccessKey ID和AccessKey Secret,请参考https://help.aliyun.com/document_detail/175144.html。
# 如果您用的是RAM用户的AccessKey,还需要为RAM用户授予权限AliyunVIAPIFullAccess,请参考https://help.aliyun.com/document_detail/145025.html。
# 从环境变量读取配置的AccessKey ID和AccessKey Secret。运行代码示例前必须先配置环境变量。
access_key_id=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID'),
access_key_secret=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET'),
# 访问的域名
endpoint='facebody.cn-shanghai.aliyuncs.com',
# 访问的域名对应的region
region_id='cn-shanghai'
)
runtime_option = RuntimeOptions()
urllist_0 = RecognizeActionRequestURLList(
url='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction1.png'
)
urllist_1 = RecognizeActionRequestURLList(
url='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction2.png'
)
urllist_2 = RecognizeActionRequestURLList(
url='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction3.png'
)
urllist_3 = RecognizeActionRequestURLList(
url='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction4.png'
)
recognize_action_request = RecognizeActionRequest(
type=1,
urllist=[
urllist_0,
urllist_1,
urllist_2,
urllist_3
]
)
try:
# 初始化Client
client = Client(config)
response = client.recognize_action_with_options(recognize_action_request, runtime_option)
# 获取整体结果
print(response.body)
except Exception as error:
# 获取整体报错信息
print(error)
# 获取单个字段
print(error.code)
<?php
//安装依赖包
//composer require alibabacloud/facebody-20191230
use AlibabaCloud\SDK\Facebody\V20191230\Facebody;
use AlibabaCloud\Tea\Utils\Utils;
use \Exception;
use AlibabaCloud\SDK\Facebody\V20191230\Models\RecognizeActionRequest\URLList;
use AlibabaCloud\SDK\Facebody\V20191230\Models\RecognizeActionRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
class RecognizeAction {
/**
* 使用AK&SK初始化账号Client
* @param string $accessKeyId
* @param string $accessKeySecret
* @return Facebody Client
*/
public static function createClient($accessKeyId, $accessKeySecret){
//初始化配置对象Darabonba\OpenApi\Models\Config。
//Config对象存放accessKeyId、accessKeySecret、endpoint等配置
$config = new Config([
"accessKeyId" => $accessKeyId,
"accessKeySecret" => $accessKeySecret
]);
// 访问的域名
$config->endpoint = "facebody.cn-shanghai.aliyuncs.com";
return new Facebody($config);
}
/**
* @param string[] $args
* @return void
*/
public static function main($args){
// 创建AccessKey ID和AccessKey Secret,请参考https://help.aliyun.com/document_detail/175144.html。
// 如果您用的是RAM用户的AccessKey,还需要为RAM用户授予权限AliyunVIAPIFullAccess,请参考https://help.aliyun.com/document_detail/145025.html。
// 从环境变量读取配置的AccessKey ID和AccessKey Secret。运行示例前必须先配置环境变量。
$accessKeyId = getenv('ALIBABA_CLOUD_ACCESS_KEY_ID');
$accessKeySecret = getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET');
$client = self::createClient($accessKeyId, $accessKeySecret);
$client = self::createClient($accessKeyId, $accessKeySecret);
$URLList0 = new URLList([
"URL" => "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction1.png"
]);
$URLList1 = new URLList([
"URL" => "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction2.png"
]);
$URLList2 = new URLList([
"URL" => "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction3.png"
]);
$URLList3 = new URLList([
"URL" => "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction4.png"
]);
$recognizeActionRequest = new RecognizeActionRequest([
"type" => 1,
"URLList" => [
$URLList0,
$URLList1,
$URLList2,
$URLList3
]
]);
$runtime = new RuntimeOptions([]);
try {
$resp = $client->recognizeActionWithOptions($recognizeActionRequest, $runtime);
# 获取整体结果
echo Utils::toJSONString($resp->body);
} catch (Exception $exception) {
# 获取整体报错信息
echo Utils::toJSONString($exception);
# 获取单个字段
echo $exception->getCode();
}
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
//$argv是预留的数组入参参数,无实际意义,无需进行修改
RecognizeAction::main(array_slice($argv, 1));
// 安装依赖包
// npm install @alicloud/facebody20191230
const FacebodyClient = require('@alicloud/facebody20191230');
const OpenapiClient = require('@alicloud/openapi-client');
const TeaUtil = require('@alicloud/tea-util');
let config = new OpenapiClient.Config({
// 创建AccessKey ID和AccessKey Secret,请参考https://help.aliyun.com/document_detail/175144.html。
// 如果您用的是RAM用户AccessKey,还需要为RAM用户授予权限AliyunVIAPIFullAccess,请参考https://help.aliyun.com/document_detail/145025.html。
// 从环境变量读取配置的AccessKey ID和AccessKey Secret。运行示例前必须先配置环境变量。
accessKeyId: process.env.ALIBABA_CLOUD_ACCESS_KEY_ID,
accessKeySecret: process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET
});
// 访问的域名
config.endpoint = `facebody.cn-shanghai.aliyuncs.com`;
const client = new FacebodyClient.default(config);
let URLList0 = new FacebodyClient.RecognizeActionRequestURLList({
URL: "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/1RecognizeAction1.png",
});
let URLList1 = new FacebodyClient.RecognizeActionRequestURLList({
URL: "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/1RecognizeAction2.png",
});
let URLList2 = new FacebodyClient.RecognizeActionRequestURLList({
URL: "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/1RecognizeAction3.png",
});
let URLList3 = new FacebodyClient.RecognizeActionRequestURLList({
URL: "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/1RecognizeAction4.png",
});
let recognizeActionRequest = new FacebodyClient.RecognizeActionRequest({
type: 1,
URLList: [
URLList0,
URLList1,
URLList2,
URLList3
],
});
let runtime = new TeaUtil.RuntimeOptions({ });
client.recognizeActionAdvance(recognizeActionRequest, runtime)
.then(function(recognizeActionRequestResponse) {
// 获取整体结果
console.log(recognizeActionRequestResponse);
// 获取单个字段
console.log(recognizeActionRequestResponse.body.data);
}, function(error) {
// 获取整体报错信息
console.log(error);
// 获取单个字段
console.log(error.data.Code);
})
/**
依赖github.com/alibabacloud-go/facebody-20191230/v4
建议使用go mod tidy安装依赖
*/
import (
"fmt"
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
facebody20191230 "github.com/alibabacloud-go/facebody-20191230/v4/client"
util "github.com/alibabacloud-go/tea-utils/v2/service"
"github.com/alibabacloud-go/tea/tea"
)
func main() {
// 创建AccessKey ID和AccessKey Secret,请参考https://help.aliyun.com/document_detail/175144.html。
// 如果您用的是RAM用户的AccessKey,还需要为RAM用户授予权限AliyunVIAPIFullAccess,请参考https://help.aliyun.com/document_detail/145025.html。
// 从环境变量读取配置的AccessKey ID和AccessKey Secret。运行示例前必须先配置环境变量。
accessKeyId := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
accessKeySecret := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
// 初始化配置对象 &openapi.Config。Config对象存放AccessKeyId、AccessKeySecret、Endpoint等配置。
config := &openapi.Config{
AccessKeyId: tea.String(accessKeyId),
AccessKeySecret: tea.String(accessKeySecret)
}
// 访问的域名
config.Endpoint = tea.String("facebody.cn-shanghai.aliyuncs.com")
client, err := facebody20191230.NewClient(config)
if err != nil {
panic(err)
}
recognizeActionRequestURLList1 := &facebody20191230.RecognizeActionRequestURLList{
URL: tea.String("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/1RecognizeAction1.png"),
}
recognizeActionRequestURLList2 := &facebody20191230.RecognizeActionRequestURLList{
URL: tea.String("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/1RecognizeAction2.png"),
}
recognizeActionRequestURLList3 := &facebody20191230.RecognizeActionRequestURLList{
URL: tea.String("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/1RecognizeAction3.png"),
}
recognizeActionRequestURLList4 := &facebody20191230.RecognizeActionRequestURLList{
URL: tea.String("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/1RecognizeAction4.png"),
}
recognizeActionAdvanceRequest := &facebody20191230.RecognizeActionRequest{
Type: tea.Int32(1),
URLList: []*facebody20191230.RecognizeActionRequestURLList{recognizeActionRequestURLList1, recognizeActionRequestURLList2, recognizeActionRequestURLList3, recognizeActionRequestURLList4},
}
runtime := &util.RuntimeOptions{}
recognizeFaceResponse, err := client.RecognizeActionWithOptions(recognizeActionAdvanceRequest, runtime)
if err != nil {
// 获取整体报错信息
fmt.Println(err.Error())
} else {
// 获取整体结果
fmt.Println(recognizeFaceResponse)
}
}
// 安装依赖包
// dotnet add package AlibabaCloud.SDK.Facebody20191230
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Xml.Linq;
using AlibabaCloud.SDK.Facebody20191230.Models;
using Tea;
using Tea.Utils;
namespace AlibabaCloud.SDK.Sample
{
public class Sample
{
/**
* 使用AK&SK初始化账号Client
* @param accessKeyId
* @param accessKeySecret
* @return Client
* @throws Exception
*/
public static AlibabaCloud.SDK.Facebody20191230.Client CreateClient(string accessKeyId, string accessKeySecret)
{
AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
{
AccessKeyId = accessKeyId,
AccessKeySecret = accessKeySecret,
};
config.Endpoint = "facebody.cn-shanghai.aliyuncs.com";
return new AlibabaCloud.SDK.Facebody20191230.Client(config);
}
public static void Main(string[] args)
{
// 创建AccessKey ID和AccessKey Secret,请参考https://help.aliyun.com/document_detail/175144.html。
// 如果您用的是RAM用户的AccessKey,还需要为RAM用户授予权限AliyunVIAPIFullAccess,请参考https://help.aliyun.com/document_detail/145025.html。
// 从环境变量读取配置的AccessKey ID和AccessKey Secret。运行示例前必须先配置环境变量。
string accessKeyId = System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID");
string accessKeySecret = System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
AlibabaCloud.SDK.Facebody20191230.Client client = CreateClient(accessKeyId, accessKeySecret);
AlibabaCloud.SDK.Facebody20191230.Models.RecognizeActionRequest.RecognizeActionRequestURLList URLList0 = new AlibabaCloud.SDK.Facebody20191230.Models.RecognizeActionRequest.RecognizeActionRequestURLList
{
URL = "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/1RecognizeAction1.png",
};
AlibabaCloud.SDK.Facebody20191230.Models.RecognizeActionRequest.RecognizeActionRequestURLList URLList1 = new AlibabaCloud.SDK.Facebody20191230.Models.RecognizeActionRequest.RecognizeActionRequestURLList
{
URL = "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/1RecognizeAction2.png",
};
AlibabaCloud.SDK.Facebody20191230.Models.RecognizeActionRequest.RecognizeActionRequestURLList URLList2 = new AlibabaCloud.SDK.Facebody20191230.Models.RecognizeActionRequest.RecognizeActionRequestURLList
{
URL = "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/1RecognizeAction3.png",
};
AlibabaCloud.SDK.Facebody20191230.Models.RecognizeActionRequest.RecognizeActionRequestURLList URLList3 = new AlibabaCloud.SDK.Facebody20191230.Models.RecognizeActionRequest.RecognizeActionRequestURLList
{
URL = "http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/1RecognizeAction4.png",
};
AlibabaCloud.SDK.Facebody20191230.Models.RecognizeActionRequest recognizeActionRequest = new AlibabaCloud.SDK.Facebody20191230.Models.RecognizeActionRequest
{
Type = 1,
URLList = new List<AlibabaCloud.SDK.Facebody20191230.Models.RecognizeActionRequest.RecognizeActionRequestURLList>
{
URLList0,
URLList1,
URLList2,
URLList3
},
};
AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
try
{
AlibabaCloud.SDK.Facebody20191230.Models.RecognizeActionResponse recognizeActionoResponse = client.RecognizeActionWithOptions(recognizeActionRequest, runtime);
// 获取整体结果
Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(recognizeActionoResponse.Body));
// 获取单个字段
Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(recognizeActionoResponse.Body.Data));
}
catch (TeaException error)
{
// 如有需要,请打印 error
Console.WriteLine(AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message));
}
catch (Exception _error)
{
TeaException error = new TeaException(new Dictionary<string, object>
{
{ "message", _error.Message }
});
// 如有需要,请打印 error
Console.WriteLine(AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message));
}
}
}
}
文件在本地或可访问的URL
/*
引入依赖包
<!-- https://mvnrepository.com/artifact/com.aliyun/facebody20191230 -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>facebody20191230</artifactId>
<version>${aliyun.facebody.version}</version>
</dependency>
*/
import com.aliyun.facebody20191230.models.RecognizeActionResponse;
import com.aliyun.tea.TeaModel;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;
public class RecognizeAction {
public static com.aliyun.facebody20191230.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
/*
初始化配置对象com.aliyun.teaopenapi.models.Config
Config对象存放 AccessKeyId、AccessKeySecret、endpoint等配置
*/
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
.setAccessKeyId(accessKeyId)
.setAccessKeySecret(accessKeySecret);
// 访问的域名
config.endpoint = "facebody.cn-shanghai.aliyuncs.com";
return new com.aliyun.facebody20191230.Client(config);
}
public static void main(String[] args_) throws Exception {
// 创建AccessKey ID和AccessKey Secret,请参考https://help.aliyun.com/document_detail/175144.html
// 如果您使用的是RAM用户的AccessKey,还需要为子账号授予权限AliyunVIAPIFullAccess,请参考https://help.aliyun.com/document_detail/145025.html
// 从环境变量读取配置的AccessKey ID和AccessKey Secret。运行代码示例前必须先配置环境变量。
String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
com.aliyun.facebody20191230.Client client = RecognizeAction.createClient(accessKeyId, accessKeySecret);
// 场景一,使用本地文件
InputStream inputStream0 = new FileInputStream(new File("/tmp/recognizeAction0.png"));
InputStream inputStream1 = new FileInputStream(new File("/tmp/recognizeAction1.png"));
// 场景二,使用任意可访问的url
URL url0 = new URL("https://viapi-test-bj.oss-cn-beijing.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction1.png");
InputStream inputStream2 = url0.openConnection().getInputStream();
URL url1 = new URL("https://viapi-test-bj.oss-cn-beijing.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction2.png");
InputStream inputStream3 = url1.openConnection().getInputStream();
com.aliyun.facebody20191230.models.RecognizeActionAdvanceRequest.RecognizeActionAdvanceRequestURLList URLList0 = new com.aliyun.facebody20191230.models.RecognizeActionAdvanceRequest.RecognizeActionAdvanceRequestURLList()
.setURLObject(inputStream0);
com.aliyun.facebody20191230.models.RecognizeActionAdvanceRequest.RecognizeActionAdvanceRequestURLList URLList1 = new com.aliyun.facebody20191230.models.RecognizeActionAdvanceRequest.RecognizeActionAdvanceRequestURLList()
.setURLObject(inputStream1);
com.aliyun.facebody20191230.models.RecognizeActionAdvanceRequest.RecognizeActionAdvanceRequestURLList URLList2 = new com.aliyun.facebody20191230.models.RecognizeActionAdvanceRequest.RecognizeActionAdvanceRequestURLList()
.setURLObject(inputStream2);
com.aliyun.facebody20191230.models.RecognizeActionAdvanceRequest.RecognizeActionAdvanceRequestURLList URLList3 = new com.aliyun.facebody20191230.models.RecognizeActionAdvanceRequest.RecognizeActionAdvanceRequestURLList()
.setURLObject(inputStream3);
com.aliyun.facebody20191230.models.RecognizeActionAdvanceRequest recognizeActionAdvanceRequest = new com.aliyun.facebody20191230.models.RecognizeActionAdvanceRequest()
.setType(1)
.setURLList(java.util.Arrays.asList(
URLList0,
URLList1,
URLList2,
URLList3
));
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
try {
RecognizeActionResponse recognizeActionResponse = client.recognizeActionAdvance(recognizeActionAdvanceRequest, runtime);
// 获取整体结果
System.out.println(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(recognizeActionResponse)));
} catch (com.aliyun.tea.TeaException teaException) {
// 获取整体报错信息
System.out.println(com.aliyun.teautil.Common.toJSONString(teaException));
// 获取单个字段
System.out.println(teaException.getCode());
}
}
}
# -*- coding: utf-8 -*-
# 引入依赖包
# pip install alibabacloud_facebody20191230
import os
import io
from urllib.request import urlopen
from alibabacloud_facebody20191230.client import Client
from alibabacloud_facebody20191230.models import RecognizeActionAdvanceRequestURLList, RecognizeActionAdvanceRequest
from alibabacloud_tea_openapi.models import Config
from alibabacloud_tea_util.models import RuntimeOptions
config = Config(
# 创建AccessKey ID和AccessKey Secret,请参考https://help.aliyun.com/document_detail/175144.html。
# 如果您用的是RAM用户的AccessKey,还需要为RAM用户授予权限AliyunVIAPIFullAccess,请参考https://help.aliyun.com/document_detail/145025.html。
# 从环境变量读取配置的AccessKey ID和AccessKey Secret。运行代码示例前必须先配置环境变量。
access_key_id=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID'),
access_key_secret=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET'),
# 访问的域名
endpoint='facebody.cn-shanghai.aliyuncs.com',
# 访问的域名对应的region
region_id='cn-shanghai'
)
runtime_option = RuntimeOptions()
#场景一:文件在本地
stream0 = open(r'/tmp/3RecognizeAction1.png', 'rb')
urllist_0 = RecognizeActionAdvanceRequestURLList()
urllist_0.urlobject = stream0
stream1 = open(r'/tmp/3RecognizeAction2.png', 'rb')
urllist_1 = RecognizeActionAdvanceRequestURLList()
urllist_1.urlobject = stream1
#场景二:使用任意可访问的url
url2 = 'https://viapi-test-bj.oss-cn-beijing.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction3.png'
img2 = urlopen(url2).read()
urllist_2 = RecognizeActionAdvanceRequestURLList()
urllist_2.urlobject = io.BytesIO(img2)
url3 = 'https://viapi-test-bj.oss-cn-beijing.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction4.png'
img3 = urlopen(url3).read()
urllist_3 = RecognizeActionAdvanceRequestURLList()
urllist_3.urlobject = io.BytesIO(img3)
recognize_action_request = RecognizeActionAdvanceRequest(
type=1,
urllist=[
urllist_0,
urllist_1,
urllist_2,
urllist_3
]
)
try:
# 初始化Client
client = Client(config)
response = client.recognize_action_advance(recognize_action_request, runtime_option)
# 获取整体结果
print(response.body)
except Exception as error:
# 获取整体报错信息
print(error)
# 获取单个字段
print(error.code)
# tips: 可通过error.__dict__查看属性名称
# 关闭流
stream0.close()
stream1.close()
<?php
//安装依赖包
//composer require alibabacloud/facebody-20191230
use AlibabaCloud\SDK\Facebody\V20191230\Facebody;
use AlibabaCloud\Tea\Utils\Utils;
use \Exception;
use AlibabaCloud\SDK\Facebody\V20191230\Models\RecognizeActionAdvanceRequest\URLList;
use AlibabaCloud\SDK\Facebody\V20191230\Models\RecognizeActionAdvanceRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use GuzzleHttp\Psr7\Stream;
class RecognizeActionAdvance {
/**
* 使用AK&SK初始化账号Client
* @param string $accessKeyId
* @param string $accessKeySecret
* @return Facebody Client
*/
public static function createClient($accessKeyId, $accessKeySecret){
//初始化配置对象Darabonba\OpenApi\Models\Config。
//Config对象存放accessKeyId、accessKeySecret、endpoint等配置
$config = new Config([
"accessKeyId" => $accessKeyId,
"accessKeySecret" => $accessKeySecret
]);
// 访问的域名
$config->endpoint = "facebody.cn-shanghai.aliyuncs.com";
return new Facebody($config);
}
/**
* @param string[] $args
* @return void
*/
public static function main($args){
// 创建AccessKey ID和AccessKey Secret,请参考https://help.aliyun.com/document_detail/175144.html。
// 如果您用的是RAM用户的AccessKey,还需要为RAM用户授予权限AliyunVIAPIFullAccess,请参考https://help.aliyun.com/document_detail/145025.html。
// 从环境变量读取配置的AccessKey ID和AccessKey Secret。运行示例前必须先配置环境变量。
$accessKeyId = getenv('ALIBABA_CLOUD_ACCESS_KEY_ID');
$accessKeySecret = getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET');
$client = self::createClient($accessKeyId, $accessKeySecret);
// 场景一,使用本地文件
#$file = fopen('/tmp/RecognizeAction.png', 'rb');
#$stream = new Stream($file);
// 场景二,使用任意可访问的url
$file0 = fopen('https://viapi-test-bj.oss-cn-beijing.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction1.png', 'rb');
$stream0 = new Stream($file0);
$file1 = fopen('https://viapi-test-bj.oss-cn-beijing.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction2.png', 'rb');
$stream1 = new Stream($file1);
$file2 = fopen('https://viapi-test-bj.oss-cn-beijing.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction3.png', 'rb');
$stream2 = new Stream($file2);
$file3 = fopen('https://viapi-test-bj.oss-cn-beijing.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction4.png', 'rb');
$stream3 = new Stream($file3);
$URLList0 = new URLList([
"URLObject" => $stream0
]);
$URLList1 = new URLList([
"URLObject" => $stream1
]);
$URLList2 = new URLList([
"URLObject" => $stream2
]);
$URLList3 = new URLList([
"URLObject" => $stream3
]);
$recognizeActionAdvanceRequest = new RecognizeActionAdvanceRequest([
"type" => 1,
"URLList" => [
$URLList0,
$URLList1,
$URLList2,
$URLList3
]
]);
$runtime = new RuntimeOptions([]);
try {
$resp = $client->recognizeActionAdvance($recognizeActionAdvanceRequest, $runtime);
# 获取整体结果
echo Utils::toJSONString($resp->body);
} catch (Exception $exception) {
# 获取整体报错信息
echo Utils::toJSONString($exception);
# 获取单个字段
echo $exception->getCode();
}
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
//$argv是预留的数组入参参数,无实际意义,无需进行修改
RecognizeActionAdvance::main(array_slice($argv, 1));
// 安装依赖包
// npm install @alicloud/facebody20191230
const FacebodyClient = require('@alicloud/facebody20191230');
const OpenapiClient = require('@alicloud/openapi-client');
const TeaUtil = require('@alicloud/tea-util');
const fs = require('fs');
const http = require('http');
const https = require('https');
let config = new OpenapiClient.Config({
// 创建AccessKey ID和AccessKey Secret,请参考https://help.aliyun.com/document_detail/175144.html。
// 如果您用的是RAM用户AccessKey,还需要为RAM用户授予权限AliyunVIAPIFullAccess,请参考https://help.aliyun.com/document_detail/145025.html。
// 从环境变量读取配置的AccessKey ID和AccessKey Secret。运行示例前必须先配置环境变量。
accessKeyId: process.env.ALIBABA_CLOUD_ACCESS_KEY_ID,
accessKeySecret: process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET
});
// 访问的域名
config.endpoint = `facebody.cn-shanghai.aliyuncs.com`;
const client = new FacebodyClient.default(config);
const getResponse = function (httpClient, url) {
return new Promise((resolve, reject) => {
httpClient.get(url, function (response) {
resolve(response);
})
})
}
const request = async function () {
try {
// 场景一,使用本地文件
const fileStream0 = fs.createReadStream('/tmp/3RecognizeAction1.png');
const fileStream1 = fs.createReadStream('/tmp/3RecognizeAction2.png');
const URLList0 = new FacebodyClient.RecognizeActionAdvanceRequestURLList();
URLList0.URLObject = fileStream0;
const URLList1 = new FacebodyClient.RecognizeActionAdvanceRequestURLList();
URLList1.URLObject = fileStream1;
// 场景二,使用任意可访问的url
const url2 = new URL("https://viapi-test-bj.oss-cn-beijing.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction3.png");
const httpClient2 = (url2.protocol == "https:") ? https : http;
const URLList2 = new FacebodyClient.RecognizeActionAdvanceRequestURLList();
URLList2.URLObject = await getResponse(httpClient2, url2);
const url3 = new URL("https://viapi-test-bj.oss-cn-beijing.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction4.png");
const httpClient3 = (url3.protocol == "https:") ? https : http;
const URLList3 = new FacebodyClient.RecognizeActionAdvanceRequestURLList();
URLList3.URLObject = await getResponse(httpClient3, url3);
let recognizeActionRequest = new FacebodyClient.RecognizeActionAdvanceRequest({
type: 1,
URLList: [
URLList0,
URLList1,
URLList2,
URLList3,
],
});
let runtime = new TeaUtil.RuntimeOptions({});
client.recognizeActionAdvance(recognizeActionRequest, runtime)
.then(function (recognizeActionRequestResponse) {
// 获取整体结果
console.log(recognizeActionRequestResponse);
// 获取单个字段
console.log(recognizeActionRequestResponse.body.data);
}, function (error) {
// 获取整体报错信息
console.log(error);
// 获取单个字段
console.log(error.data);
})
} catch (error) {
console.log(error);
}
}();
/**
依赖github.com/alibabacloud-go/facebody-20191230/v4
建议使用go mod tidy安装依赖
*/
import (
"fmt"
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
facebody20191230 "github.com/alibabacloud-go/facebody-20191230/v4/client"
util "github.com/alibabacloud-go/tea-utils/v2/service"
"github.com/alibabacloud-go/tea/tea"
"net/http"
"os"
)
func main() {
// 创建AccessKey ID和AccessKey Secret,请参考https://help.aliyun.com/document_detail/175144.html。
// 如果您用的是RAM用户的AccessKey,还需要为RAM用户授予权限AliyunVIAPIFullAccess,请参考https://help.aliyun.com/document_detail/145025.html。
// 从环境变量读取配置的AccessKey ID和AccessKey Secret。运行示例前必须先配置环境变量。
accessKeyId := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
accessKeySecret := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
// 初始化配置对象 &openapi.Config。Config对象存放AccessKeyId、AccessKeySecret、Endpoint等配置。
config := &openapi.Config{
AccessKeyId: tea.String(accessKeyId),
AccessKeySecret: tea.String(accessKeySecret)
}
// 访问的域名
config.Endpoint = tea.String("facebody.cn-shanghai.aliyuncs.com")
client, err := facebody20191230.NewClient(config)
if err != nil {
panic(err)
}
// 场景一,使用本地文件
file1, err := os.Open("/tmp/RecognizeAction1.png")
if err != nil {
fmt.Println("can not open file", err)
panic(err)
}
file2, err := os.Open("/tmp/RecognizeAction2.png")
if err != nil {
fmt.Println("can not open file", err)
panic(err)
}
recognizeActionAdvanceRequestURLList1 := &facebody20191230.RecognizeActionAdvanceRequestURLList{
URLObject: file1,
}
recognizeActionAdvanceRequestURLList2 := &facebody20191230.RecognizeActionAdvanceRequestURLList{
URLObject: file2,
}
// 场景二,使用任意可访问的url
httpClient := http.Client{}
file3, _ := httpClient.Get("https://viapi-test-bj.oss-cn-beijing.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction1.png")
file4, _ := httpClient.Get("https://viapi-test-bj.oss-cn-beijing.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction2.png")
recognizeActionAdvanceRequestURLList3 := &facebody20191230.RecognizeActionAdvanceRequestURLList{
URLObject: file3.Body,
}
recognizeActionAdvanceRequestURLList4 := &facebody20191230.RecognizeActionAdvanceRequestURLList{
URLObject: file4.Body,
}
recognizeActionAdvanceRequest := &facebody20191230.RecognizeActionAdvanceRequest{
Type: tea.Int32(1),
URLList: []*facebody20191230.RecognizeActionAdvanceRequestURLList{recognizeActionAdvanceRequestURLList1, recognizeActionAdvanceRequestURLList2, recognizeActionAdvanceRequestURLList3, recognizeActionAdvanceRequestURLList4},
}
runtime := &util.RuntimeOptions{}
recognizeFaceAdvanceResponse, err := client.RecognizeActionAdvance(recognizeActionAdvanceRequest, runtime)
if err != nil {
// 获取整体报错信息
fmt.Println(err.Error())
} else {
// 获取整体结果
fmt.Println(recognizeFaceAdvanceResponse)
}
}
// 安装依赖包
// dotnet add package AlibabaCloud.SDK.Facebody20191230
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using AlibabaCloud.SDK.Facebody20191230.Models;
using Tea;
using Tea.Utils;
using static System.Net.WebRequestMethods;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace AlibabaCloud.SDK.Sample
{
public class Sample
{
/**
* 使用AK&SK初始化账号Client
* @param accessKeyId
* @param accessKeySecret
* @return Client
* @throws Exception
*/
public static AlibabaCloud.SDK.Facebody20191230.Client CreateClient(string accessKeyId, string accessKeySecret)
{
AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
{
AccessKeyId = accessKeyId,
AccessKeySecret = accessKeySecret,
};
config.Endpoint = "facebody.cn-shanghai.aliyuncs.com";
return new AlibabaCloud.SDK.Facebody20191230.Client(config);
}
public static void Main(string[] args)
{
// 创建AccessKey ID和AccessKey Secret,请参考https://help.aliyun.com/document_detail/175144.html。
// 如果您用的是RAM用户的AccessKey,还需要为RAM用户授予权限AliyunVIAPIFullAccess,请参考https://help.aliyun.com/document_detail/145025.html。
// 从环境变量读取配置的AccessKey ID和AccessKey Secret。运行示例前必须先配置环境变量。
string accessKeyId = System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID");
string accessKeySecret = System.Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
AlibabaCloud.SDK.Facebody20191230.Client client = CreateClient(accessKeyId, accessKeySecret);
AlibabaCloud.SDK.Facebody20191230.Models.RecognizeActionAdvanceRequest.RecognizeActionAdvanceRequestURLList URLList0 = new AlibabaCloud.SDK.Facebody20191230.Models.RecognizeActionAdvanceRequest.RecognizeActionAdvanceRequestURLList
();
AlibabaCloud.SDK.Facebody20191230.Models.RecognizeActionAdvanceRequest.RecognizeActionAdvanceRequestURLList URLList1 = new AlibabaCloud.SDK.Facebody20191230.Models.RecognizeActionAdvanceRequest.RecognizeActionAdvanceRequestURLList
();
AlibabaCloud.SDK.Facebody20191230.Models.RecognizeActionAdvanceRequest.RecognizeActionAdvanceRequestURLList URLList2 = new AlibabaCloud.SDK.Facebody20191230.Models.RecognizeActionAdvanceRequest.RecognizeActionAdvanceRequestURLList
();
AlibabaCloud.SDK.Facebody20191230.Models.RecognizeActionAdvanceRequest.RecognizeActionAdvanceRequestURLList URLList3 = new AlibabaCloud.SDK.Facebody20191230.Models.RecognizeActionAdvanceRequest.RecognizeActionAdvanceRequestURLList
();
// 场景一,使用本地文件
System.IO.StreamReader file1 = new System.IO.StreamReader(@"/tmp/3RecognizeAction1.png");
System.IO.StreamReader file2 = new System.IO.StreamReader(@"/tmp/3RecognizeAction2.png");
URLList0.URLObject = file1.BaseStream;
URLList1.URLObject = file2.BaseStream;
// 场景二,使用任意可访问的url
HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create("https://viapi-test-bj.oss-cn-beijing.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction1.png");
WebResponse response1 = request1.GetResponse();
Stream stream1 = response1.GetResponseStream();
HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create("https://viapi-test-bj.oss-cn-beijing.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction2.png");
WebResponse response2 = request2.GetResponse();
Stream stream2 = response2.GetResponseStream();
URLList2.URLObject = stream1;
URLList3.URLObject = stream2;
AlibabaCloud.SDK.Facebody20191230.Models.RecognizeActionAdvanceRequest recognizeActionAdvanceRequest = new AlibabaCloud.SDK.Facebody20191230.Models.RecognizeActionAdvanceRequest
{
Type = 1,
URLList = new List<AlibabaCloud.SDK.Facebody20191230.Models.RecognizeActionAdvanceRequest.RecognizeActionAdvanceRequestURLList>
{
URLList0,
URLList1,
URLList2,
URLList3
},
};
AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
try
{
AlibabaCloud.SDK.Facebody20191230.Models.RecognizeActionResponse recognizeActionResponse = client.RecognizeActionAdvance(recognizeActionAdvanceRequest, runtime);
// 获取整体结果
Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(recognizeActionResponse.Body));
// 获取单个字段
Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(recognizeActionResponse.Body.Data));
}
catch (TeaException error)
{
// 如有需要,请打印 error
Console.WriteLine(AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message));
}
catch (Exception _error)
{
TeaException error = new TeaException(new Dictionary<string, object>
{
{ "message", _error.Message }
});
// 如有需要,请打印 error
Console.WriteLine(AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message));
}
}
}
}