Action recognition
The Recognize Action feature identifies human actions in videos and images. Supported actions include raising a hand, smoking, making a phone call, washing hands, and taking a photo. This topic provides sample code in several programming languages to help you get started with this feature.
-
For real-time assistance, start an online consultation.
-
If you have questions about API access or usage for the Alibaba Cloud Vision AI Platform, join our DingTalk group (ID: 23109592) to contact us.
Overview
For a detailed description of the Recognize Action feature and its API parameters, see Recognize Action.
Install the SDK
For information about the SDK dependency packages for popular languages, see SDK Overview.
Configure environment variables
Configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.
An Alibaba Cloud account has full access to all API operations. We recommend that you use a RAM user for API calls or routine O&M. For more information, see Create a RAM user.
Do not save your AccessKey ID or AccessKey Secret in project code. Otherwise, the AccessKey pair may be leaked and the security of all resources in your account may be compromised.
Configure environment variables on Linux and macOS
Open a terminal in IntelliJ IDEA.
Run the following commands to configure the environment variables.
Replace
<access_key_id>with the AccessKey ID of your RAM user and<access_key_secret>with the AccessKey Secret of your RAM user. If you need to configure more permissions, see Control access permissions using a RAM policy.export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id> export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>
Configure environment variables on Windows
Create a new environment variable file, add the environment variables
ALIBABA_CLOUD_ACCESS_KEY_IDandALIBABA_CLOUD_ACCESS_KEY_SECRET, and set them to the AccessKey ID and AccessKey Secret that you have prepared. Then, restart the Windows operating system. The following example uses Windows 10.Open File Explorer, right-click This PC, and then select Properties.
In the left-side navigation pane, click Advanced system settings.
On the Advanced tab of the System Properties dialog box, click Environment Variables.
In the Environment Variables dialog box, click New.
In the New System Variable dialog box, add the environment variables
ALIBABA_CLOUD_ACCESS_KEY_IDandALIBABA_CLOUD_ACCESS_KEY_SECRET, and set them to the AccessKey ID and AccessKey Secret that you have prepared.Restart the Windows operating system for the configurations to take effect.
Sample code
Files in OSS (Shanghai)
/*
Add the dependency.
<!-- 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 {
/*
Initialize the configuration object com.aliyun.teaopenapi.models.Config.
It stores configuration parameters such as your AccessKey ID, AccessKey Secret, and endpoint.
*/
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
.setAccessKeyId(accessKeyId)
.setAccessKeySecret(accessKeySecret);
// The endpoint of the service.
config.endpoint = "facebody.cn-shanghai.aliyuncs.com";
return new com.aliyun.facebody20191230.Client(config);
}
public static void main(String[] args_) throws Exception {
// For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/175144.html.
// If you use a RAM user's AccessKey, you must grant the RAM user the AliyunVIAPIFullAccess permission. For more information, see https://help.aliyun.com/document_detail/145025.html.
// Read the AccessKey ID and AccessKey Secret from environment variables. Ensure these variables are configured before running the sample code.
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);
// Obtain the complete response.
System.out.println(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(recognizeActionResponse)));
} catch (com.aliyun.tea.TeaException teaException) {
// Obtain the complete error message.
System.out.println(com.aliyun.teautil.Common.toJSONString(teaException));
// Obtain a specific field.
System.out.println(teaException.getCode());
}
}
}
# -*- coding: utf-8 -*-
# Install the dependency.
# 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(
# For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/175144.html.
# If you use a RAM user's AccessKey, you must grant the RAM user the AliyunVIAPIFullAccess permission. For more information, see https://help.aliyun.com/document_detail/145025.html.
# Read the AccessKey ID and AccessKey Secret from environment variables. Ensure these variables are configured before running the sample code.
access_key_id=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID'),
access_key_secret=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET'),
# The endpoint of the service.
endpoint='facebody.cn-shanghai.aliyuncs.com',
# The region ID that corresponds to the endpoint.
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:
# Initialize the client.
client = Client(config)
response = client.recognize_action_with_options(recognize_action_request, runtime_option)
# Obtain the complete response.
print(response.body)
except Exception as error:
# Obtain the complete error message.
print(error)
# Obtain a specific field.
print(error.code)
<?php
// Install the dependency.
//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 {
/**
* Use the AccessKey pair to initialize the client.
* @param string $accessKeyId
* @param string $accessKeySecret
* @return Facebody Client
*/
public static function createClient($accessKeyId, $accessKeySecret){
// Initialize the configuration object Darabonba\OpenApi\Models\Config.
// It stores configuration parameters such as your accessKeyId, accessKeySecret, and endpoint.
$config = new Config([
"accessKeyId" => $accessKeyId,
"accessKeySecret" => $accessKeySecret
]);
// The endpoint of the service.
$config->endpoint = "facebody.cn-shanghai.aliyuncs.com";
return new Facebody($config);
}
/**
* @param string[] $args
* @return void
*/
public static function main($args){
// For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/175144.html.
// If you use a RAM user's AccessKey, you must grant the RAM user the AliyunVIAPIFullAccess permission. For more information, see https://help.aliyun.com/document_detail/145025.html.
// Read the AccessKey ID and AccessKey Secret from environment variables. Ensure these variables are configured before running the sample code.
$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);
# Obtain the complete response.
echo Utils::toJSONString($resp->body);
} catch (Exception $exception) {
# Obtain the complete error message.
echo Utils::toJSONString($exception);
# Obtain a specific field.
echo $exception->getCode();
}
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
// The $argv is a reserved array parameter. Do not modify it.
RecognizeAction::main(array_slice($argv, 1));
// Install the dependency.
// 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({
// For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/175144.html.
// If you use a RAM user's AccessKey, you must grant the RAM user the AliyunVIAPIFullAccess permission. For more information, see https://help.aliyun.com/document_detail/145025.html.
// Read the AccessKey ID and AccessKey Secret from environment variables. Ensure these variables are configured before running the sample code.
accessKeyId: process.env.ALIBABA_CLOUD_ACCESS_KEY_ID,
accessKeySecret: process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET
});
// The endpoint of the service.
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) {
// Obtain the complete response.
console.log(recognizeActionRequestResponse);
// Obtain a specific field.
console.log(recognizeActionRequestResponse.body.data);
}, function(error) {
// Obtain the complete error message.
console.log(error);
// Obtain a specific field.
console.log(error.data.Code);
})
/**
This code depends on github.com/alibabacloud-go/facebody-20191230/v4. We recommend that you run go mod tidy to install the dependency.
*/
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() {
// For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/175144.html.
// If you use a RAM user's AccessKey, you must grant the RAM user the AliyunVIAPIFullAccess permission. For more information, see https://help.aliyun.com/document_detail/145025.html.
// Read the AccessKey ID and AccessKey Secret from environment variables. Ensure these variables are configured before running the sample code.
accessKeyId := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
accessKeySecret := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
// Initialize the configuration object &openapi.Config. It stores configuration parameters such as your AccessKey ID, AccessKey Secret, and endpoint.
config := &openapi.Config{
AccessKeyId: tea.String(accessKeyId),
AccessKeySecret: tea.String(accessKeySecret)
}
// The endpoint of the service.
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{}
recognizeActionResponse, err := client.RecognizeActionWithOptions(recognizeActionAdvanceRequest, runtime)
if err != nil {
// Obtain the complete error message.
fmt.Println(err.Error())
} else {
// Obtain the complete response.
fmt.Println(recognizeActionResponse)
}
}
// Install the dependency.
// 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
{
/**
* Use the AccessKey pair to initialize the 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)
{
// For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/175144.html.
// If you use a RAM user's AccessKey, you must grant the RAM user the AliyunVIAPIFullAccess permission. For more information, see https://help.aliyun.com/document_detail/145025.html.
// Read the AccessKey ID and AccessKey Secret from environment variables. Ensure these variables are configured before running the sample code.
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 recognizeActionResponse = client.RecognizeActionWithOptions(recognizeActionRequest, runtime);
// Obtain the complete response.
Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(recognizeActionResponse.Body));
// Obtain a specific field.
Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(recognizeActionResponse.Body.Data));
}
catch (TeaException error)
{
// Print the error details.
Console.WriteLine(AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message));
}
catch (Exception _error)
{
TeaException error = new TeaException(new Dictionary<string, object>
{
{ "message", _error.Message }
});
// Print the error details.
Console.WriteLine(AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message));
}
}
}
}
Local files and URLs
/*
Add the dependency.
<!-- 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 {
/*
Initialize the configuration object com.aliyun.teaopenapi.models.Config.
It stores configuration parameters such as your AccessKey ID, AccessKey Secret, and endpoint.
*/
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
.setAccessKeyId(accessKeyId)
.setAccessKeySecret(accessKeySecret);
// The endpoint of the service.
config.endpoint = "facebody.cn-shanghai.aliyuncs.com";
return new com.aliyun.facebody20191230.Client(config);
}
public static void main(String[] args_) throws Exception {
// For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/175144.html.
// If you use a RAM user's AccessKey, you must grant the RAM user the AliyunVIAPIFullAccess permission. For more information, see https://help.aliyun.com/document_detail/145025.html.
// Read the AccessKey ID and AccessKey Secret from environment variables. Ensure these variables are configured before running the sample code.
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);
// Scenario 1: Use a local file.
InputStream inputStream0 = new FileInputStream(new File("/tmp/recognizeAction0.png"));
InputStream inputStream1 = new FileInputStream(new File("/tmp/recognizeAction1.png"));
// Scenario 2: Use a file from a publicly accessible URL.
URL url0 = new URL("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction1.png");
InputStream inputStream2 = url0.openConnection().getInputStream();
URL url1 = new URL("http://viapi-test.oss-cn-shanghai.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);
// Obtain the complete response.
System.out.println(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(recognizeActionResponse)));
} catch (com.aliyun.tea.TeaException teaException) {
// Obtain the complete error message.
System.out.println(com.aliyun.teautil.Common.toJSONString(teaException));
// Obtain a specific field.
System.out.println(teaException.getCode());
}
}
}
# -*- coding: utf-8 -*-
# Install the dependency.
# 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(
# For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/175144.html.
# If you use a RAM user's AccessKey, you must grant the RAM user the AliyunVIAPIFullAccess permission. For more information, see https://help.aliyun.com/document_detail/145025.html.
# Read the AccessKey ID and AccessKey Secret from environment variables. Ensure these variables are configured before running the sample code.
access_key_id=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID'),
access_key_secret=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET'),
# The endpoint of the service.
endpoint='facebody.cn-shanghai.aliyuncs.com',
# The region ID that corresponds to the endpoint.
region_id='cn-shanghai'
)
runtime_option = RuntimeOptions()
# Scenario 1: Use a local file.
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
# Scenario 2: Use a file from a publicly accessible URL.
url2 = 'http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction3.png'
img2 = urlopen(url2).read()
urllist_2 = RecognizeActionAdvanceRequestURLList()
urllist_2.urlobject = io.BytesIO(img2)
url3 = 'http://viapi-test.oss-cn-shanghai.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:
# Initialize the client.
client = Client(config)
response = client.recognize_action_advance(recognize_action_request, runtime_option)
# Obtain the complete response.
print(response.body)
except Exception as error:
# Obtain the complete error message.
print(error)
# Obtain a specific field.
print(error.code)
# Tip: You can view the attribute names by using error.__dict__.
# Close the streams.
stream0.close()
stream1.close()
<?php
// Install the dependency.
//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 {
/**
* Use the AccessKey pair to initialize the client.
* @param string $accessKeyId
* @param string $accessKeySecret
* @return Facebody Client
*/
public static function createClient($accessKeyId, $accessKeySecret){
// Initialize the configuration object Darabonba\OpenApi\Models\Config.
// It stores configuration parameters such as your accessKeyId, accessKeySecret, and endpoint.
$config = new Config([
"accessKeyId" => $accessKeyId,
"accessKeySecret" => $accessKeySecret
]);
// The endpoint of the service.
$config->endpoint = "facebody.cn-shanghai.aliyuncs.com";
return new Facebody($config);
}
/**
* @param string[] $args
* @return void
*/
public static function main($args){
// For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/175144.html.
// If you use a RAM user's AccessKey, you must grant the RAM user the AliyunVIAPIFullAccess permission. For more information, see https://help.aliyun.com/document_detail/145025.html.
// Read the AccessKey ID and AccessKey Secret from environment variables. Ensure these variables are configured before running the sample code.
$accessKeyId = getenv('ALIBABA_CLOUD_ACCESS_KEY_ID');
$accessKeySecret = getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET');
$client = self::createClient($accessKeyId, $accessKeySecret);
// Scenario 1: Use a local file.
#$file = fopen('/tmp/RecognizeAction.png', 'rb');
#$stream = new Stream($file);
// Scenario 2: Use a file from a publicly accessible URL.
$file0 = fopen('http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction1.png', 'rb');
$stream0 = new Stream($file0);
$file1 = fopen('http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction2.png', 'rb');
$stream1 = new Stream($file1);
$file2 = fopen('http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction3.png', 'rb');
$stream2 = new Stream($file2);
$file3 = fopen('http://viapi-test.oss-cn-shanghai.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);
# Obtain the complete response.
echo Utils::toJSONString($resp->body);
} catch (Exception $exception) {
# Obtain the complete error message.
echo Utils::toJSONString($exception);
# Obtain a specific field.
echo $exception->getCode();
}
}
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
require_once $path;
}
// The $argv is a reserved array parameter. Do not modify it.
RecognizeActionAdvance::main(array_slice($argv, 1));
// Install the dependency.
// 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({
// For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/175144.html.
// If you use a RAM user's AccessKey, you must grant the RAM user the AliyunVIAPIFullAccess permission. For more information, see https://help.aliyun.com/document_detail/145025.html.
// Read the AccessKey ID and AccessKey Secret from environment variables. Ensure these variables are configured before running the sample code.
accessKeyId: process.env.ALIBABA_CLOUD_ACCESS_KEY_ID,
accessKeySecret: process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET
});
// The endpoint of the service.
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 {
// Scenario 1: Use a local file.
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;
// Scenario 2: Use a file from a publicly accessible URL.
const url2 = new URL("http://viapi-test.oss-cn-shanghai.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("http://viapi-test.oss-cn-shanghai.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) {
// Obtain the complete response.
console.log(recognizeActionRequestResponse);
// Obtain a specific field.
console.log(recognizeActionRequestResponse.body.data);
}, function (error) {
// Obtain the complete error message.
console.log(error);
// Obtain a specific field.
console.log(error.data);
})
} catch (error) {
console.log(error);
}
}();
/**
This code depends on github.com/alibabacloud-go/facebody-20191230/v4. We recommend that you run go mod tidy to install the dependency.
*/
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() {
// For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/175144.html.
// If you use a RAM user's AccessKey, you must grant the RAM user the AliyunVIAPIFullAccess permission. For more information, see https://help.aliyun.com/document_detail/145025.html.
// Read the AccessKey ID and AccessKey Secret from environment variables. Ensure these variables are configured before running the sample code.
accessKeyId := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
accessKeySecret := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
// Initialize the configuration object &openapi.Config. It stores configuration parameters such as your AccessKey ID, AccessKey Secret, and endpoint.
config := &openapi.Config{
AccessKeyId: tea.String(accessKeyId),
AccessKeySecret: tea.String(accessKeySecret)
}
// The endpoint of the service.
config.Endpoint = tea.String("facebody.cn-shanghai.aliyuncs.com")
client, err := facebody20191230.NewClient(config)
if err != nil {
panic(err)
}
// Scenario 1: Use a local file.
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,
}
// Scenario 2: Use a file from a publicly accessible URL.
httpClient := http.Client{}
file3, _ := httpClient.Get("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction1.png")
file4, _ := httpClient.Get("http://viapi-test.oss-cn-shanghai.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{}
recognizeActionAdvanceResponse, err := client.RecognizeActionAdvance(recognizeActionAdvanceRequest, runtime)
if err != nil {
// Obtain the complete error message.
fmt.Println(err.Error())
} else {
// Obtain the complete response.
fmt.Println(recognizeActionAdvanceResponse)
}
}
// Install the dependency.
// 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
{
/**
* Use the AccessKey pair to initialize the 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)
{
// For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/175144.html.
// If you use a RAM user's AccessKey, you must grant the RAM user the AliyunVIAPIFullAccess permission. For more information, see https://help.aliyun.com/document_detail/145025.html.
// Read the AccessKey ID and AccessKey Secret from environment variables. Ensure these variables are configured before running the sample code.
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
();
// Scenario 1: Use a local file.
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;
// Scenario 2: Use a file from a publicly accessible URL.
HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeAction/3RecognizeAction1.png");
WebResponse response1 = request1.GetResponse();
Stream stream1 = response1.GetResponseStream();
HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create("http://viapi-test.oss-cn-shanghai.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);
// Obtain the complete response.
Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(recognizeActionResponse.Body));
// Obtain a specific field.
Console.WriteLine(AlibabaCloud.TeaUtil.Common.ToJSONString(recognizeActionResponse.Body.Data));
}
catch (TeaException error)
{
// Print the error details.
Console.WriteLine(AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message));
}
catch (Exception _error)
{
TeaException error = new TeaException(new Dictionary<string, object>
{
{ "message", _error.Message }
});
// Print the error details.
Console.WriteLine(AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message));
}
}
}
}