Tous les produits
Search
Centre de documentation

Object Storage Service:Détection du corps humain

Dernière mise à jour :Aug 18, 2026

Détectez tous les corps humains présents dans une image et renvoyez leurs cadres de délimitation ainsi que leurs scores de confiance.

Scénarios

  • Détection de piétons : localisez les piétons dans les images.

  • Suivi de trajectoire : analysez le comportement des piétons grâce à la détection et au suivi.

  • Comptage de personnes : comptez les individus sur les images pour l'analyse du trafic ou la sécurité des lieux.

Utilisation

Prérequis

Exemples de code

Les exemples suivants détectent les corps humains à l'aide des SDK OSS.

Java

Le SDK OSS pour Java version 3.17.4 ou ultérieure est requis.

import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.OSSObject;
import com.aliyun.oss.model.GetObjectRequest;
import com.aliyuncs.exceptions.ClientException;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

public class Demo {
    public static void main(String[] args) throws ClientException, ClientException {
        // Specify the endpoint of the region in which the bucket is located.
        String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
        // Specify the region of the endpoint. Example: cn-hangzhou.
        String region = "cn-hangzhou";
        // Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
        EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
        // Specify the name of the bucket.
        String bucketName = "examplebucket";
        // If the image is stored in the root directory of the bucket, enter the image name. If the image is not stored in the root directory of the bucket, you must specify the full path of the image. Example: exampledir/example.jpg.
        String key = "example.jpg";

        // Create an OSSClient instance.
        // Call the shutdown method to release resources when the OSSClient is no longer in use.
        ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
        clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
        OSS ossClient = OSSClientBuilder.create()
                .endpoint(endpoint)
                .credentialsProvider(credentialsProvider)
                .clientConfiguration(clientBuilderConfiguration)
                .region(region)
                .build();

        try {
            // Create a processing instruction for human body detection.
            GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key);
            getObjectRequest.setProcess("image/bodies");

            // Use the getObject method, and pass the processing instruction.
            OSSObject ossObject = ossClient.getObject(getObjectRequest);

            // Read and display the query results.
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            int bytesRead;
            while ((bytesRead = ossObject.getObjectContent().read(buffer)) != -1) {
                baos.write(buffer, 0, bytesRead);
            }
            String imageBodies = baos.toString("UTF-8");
            System.out.println("Image Bodies:");
            System.out.println(imageBodies);
        } catch (IOException e) {
            System.out.println("Error: " + e.getMessage());
        } finally {
            // Shut down the OSSClient instance.
            ossClient.shutdown();
        }
    }
}

Python

Le SDK OSS pour Python version 2.18.4 ou ultérieure est requis.

# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider

# Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())

# Specify the region endpoint. For example: https://oss-cn-hangzhou.aliyuncs.com for China (Hangzhou).
endpoint = 'https://oss-cn-hangzhou.aliyuncs.com'
# Specify the ID of the Alibaba Cloud region in which the bucket is located.
region = 'cn-hangzhou'
bucket = oss2.Bucket(auth, endpoint, 'examplebucket', region=region)

# Specify the object name (key). For nested files, provide the full path. Example: exampledir/example.jpg
key = 'example.jpg'

# Create a processing instruction for human body detection.
process = 'image/bodies'

try:
    # Use the process parameter of the get_object method to pass the processing instruction.
    result = bucket.get_object(key, process=process)

    # Read and display the query results.
    image_bodies = result.read().decode('utf-8')
    print("Image Bodies:")
    print(image_bodies)
except oss2.exceptions.OssError as e:
    print("Error:", e)

Go

Le SDK OSS pour Go version 3.0.2 ou ultérieure est requis.

package main

import (
	"fmt"
	"io"
	"os"

	"github.com/aliyun/aliyun-oss-go-sdk/oss"
)

func main() {
	// Obtain the temporary access credentials from the environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
	provider, err := oss.NewEnvironmentVariableCredentialsProvider()
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	// Create an OSSClient instance.
	// Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. Specify your actual endpoint.
	// Specify the ID of the Alibaba Cloud region in which the bucket is located. Example: cn-hangzhou.
	client, err := oss.New("https://oss-cn-hangzhou.aliyuncs.com", "", "", oss.SetCredentialsProvider(&provider), oss.AuthVersion(oss.AuthV4), oss.Region("cn-hangzhou"))
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	// Specify the name of the bucket. Example: examplebucket.
	bucketName := "examplebucket"

	bucket, err := client.Bucket(bucketName)
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	// If the image is stored in the root directory of the bucket, enter the name of the image. If the image is not stored in the root directory of the bucket, you must specify the full path of the image. Example: exampledir/example.jpg.
	// Create a processing instruction for human body detection by using the oss.Process method.
	body, err := bucket.GetObject("example.jpg", oss.Process("image/bodies"))
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}

	defer body.Close()

	data, err := io.ReadAll(body)
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	fmt.Println("data:", string(data))
}

PHP

Le SDK OSS pour PHP version 2.7.0 ou ultérieure est requis.

<?php
if (is_file(__DIR__ . '/../autoload.php')) {
    require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
    require_once __DIR__ . '/../vendor/autoload.php';
}
use OSS\Credentials\EnvironmentVariableCredentialsProvider;
use OSS\OssClient;

try {
    // Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
    $provider = new EnvironmentVariableCredentialsProvider(); 
    // Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
    $endpoint = 'https://oss-cn-hangzhou.aliyuncs.com';
    // Specify the name of the bucket. Example: examplebucket.
    $bucket = 'examplebucket';
    // If the image is stored in the root directory of the bucket, enter the name of the image. If the image is not stored in the root directory of the bucket, you must specify the full path of the image. Example: exampledir/example.jpg.
    $key = 'example.jpg'; 

    $config = array(
        "provider" => $provider,
        "endpoint" => $endpoint,        
        "signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V4,
        // Specify the ID of the Alibaba Cloud region in which the bucket is located.
        "region" => "cn-hangzhou"
    );
    $ossClient = new OssClient($config);
  // Create a processing instruction for human body detection.
  $options[$ossClient::OSS_PROCESS] = "image/bodies";
  $result = $ossClient->getObject($bucket,$key,$options);
  var_dump($result);
} catch (OssException $e) {
  printf($e->getMessage() . "\n");
  return;
}

Paramètres

Nom de l'opération : image/bodies

Paramètre de la requête

Paramètre

Type

Obligatoire

Description

Exemple

sen

int

Non

Sensibilité de la détection. Des valeurs plus élevées permettent de détecter davantage de corps. Valeurs valides : 0 à 100. Valeur par défaut : 60.

50

Paramètres de la réponse

Remarque

Les champs de la réponse sont décrits dans la rubrique DetectImageBodies - Détecter les corps humains dans les images.

API associées

Pour une utilisation avancée, appelez directement les API RESTful avec un calcul de signature V4. (Recommandé) Inclure une signature V4.

Ajoutez le paramètre x-oss-process à l'opération GetObject pour traiter les images. GetObject.

Exemple 1

Exemple de requête

GET /example.jpg?x-oss-process=image/bodies HTTP/1.1
Host: image-demo.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 21 Jul 2023 08:49:07 GMT
Authorization: SignatureValue

Exemple de réponse

HTTP/1.1 200 OK
Server: AliyunOSS
Date: Fri, 21 Jul 2023 08:49:09 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 145
Connection: keep-alive
x-oss-request-id: 64BA4685A645AE37313CBD14
ETag: "2CE2EA370531B7CC1D23BE6015CF5DA5"
Last-Modified: Mon, 10 Jul 2023 13:07:30 GMT
x-oss-object-type: Normal
x-oss-hash-crc64ecma: 13420962247653419692
x-oss-storage-class: Standard
x-oss-ec: 0048-00000104
Content-Disposition: attachment
x-oss-force-download: true
x-oss-server-time: 329

{
  "RequestId": "58C0F6A4-7B26-5E22-9C60-EFF90E2082ED",
  "Bodies": [
    {
       "Confidence": 0.733,
       "Boundary": {
         "Left": 115,
         "Top": 97,
         "Height": 103,
         "Width": 63
         }
     }
   ]
}

Exemple 2

Exemple de requête

Dans cet exemple, la valeur du paramètre sen est 50.

GET /example.jpg?x-oss-process=image/bodies,sen_50 HTTP/1.1
Host: image-demo.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 21 Jul 2023 08:54:54 GMT
Authorization: SignatureValue

Exemple de réponse

HTTP/1.1 200 OK
Server: AliyunOSS
Date: Fri, 21 Jul 2023 08:54:56 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 145
Connection: keep-alive
x-oss-request-id: 64BA47E05B40CC33396D6AA3
ETag: "2CE2EA370531B7CC1D23BE6015CF5DA5"
Last-Modified: Mon, 10 Jul 2023 13:07:30 GMT
x-oss-object-type: Normal
x-oss-hash-crc64ecma: 13420962247653419692
x-oss-storage-class: Standard
x-oss-ec: 0048-00000104
Content-Disposition: attachment
x-oss-force-download: true
x-oss-server-time: 394

{
  "RequestId": "E9BDE106-1436-5077-9F6E-65D81DC6FEC8",
  "Bodies": [
    {
      "Confidence": 0.733,
      "Boundary": {
        "Left": 115,
        "Top": 97,
        "Height": 103,
        "Width": 63
      }
    },
    {
      "Confidence": 0.732,
      "Boundary": {
        "Left": 214,
        "Top": 121,
        "Height": 86,
        "Width": 63
      }
    },
    {
      "Confidence": 0.656,
      "Boundary": {
        "Left": 63,
        "Top": 102,
        "Height": 100,
        "Width": 82
      }
    }
  ]
}

Facturation

La détection du corps humain entraîne des frais à la fois sur OSS et sur IMM :

  • Côté OSS : Tarification OSS

    API

    Élément de facturation

    Description

    GetObject

    Requêtes GET

    Des frais de requête vous sont facturés en fonction du nombre de requêtes abouties.

    Trafic sortant sur Internet

    Si vous appelez l'opération GetObject à l'aide d'un endpoint public, tel que oss-cn-hangzhou.aliyuncs.com, ou d'un endpoint d'accélération, tel que oss-accelerate.aliyuncs.com, des frais de trafic sortant sur Internet vous sont facturés en fonction de la taille des données.

    Capacité de récupération des données à accès peu fréquent

    Si des objets IA (Infrequent Access) sont récupérés, des frais de récupération de données IA vous sont facturés en fonction de la taille des données IA récupérées.

    Capacité de récupération directe des données depuis Archive

    Si des objets Archive dans un bucket pour lequel l'accès en temps réel est activé sont récupérés, des frais de récupération de données Archive vous sont facturés en fonction de la taille des objets Archive récupérés.

    Accélération du transfert

    Si vous activez l'accélération du transfert et utilisez un endpoint d'accélération pour accéder à votre bucket, des frais d'accélération du transfert vous sont facturés en fonction de la taille des données.

    HeadObject

    Requêtes GET

    Des frais de requête vous sont facturés en fonction du nombre de requêtes abouties.

  • Côté IMM : Éléments de facturation IMM

    Important

    À partir du 28 juillet 2025 à 11 h 00 (UTC+8), la détection du corps humain par IMM passe d'un service gratuit à un service payant. L'élément de facturation est ImageDetect. Annonce relative à l'ajustement de la facturation IMM.

    API

    Élément de facturation

    Description

    DetectImageBodies

    ImageDetect

    Des frais de requête vous sont facturés en fonction du nombre de requêtes abouties.

Remarques d'utilisation

  • La détection du corps humain prend uniquement en charge le traitement synchrone via x-oss-process.

  • L'accès anonyme est refusé.