您可以使用人體檢測功能檢測圖片中所有的人體以及人體位置框和信賴度。這項技術可以應用於安全監控、人流統計等多個領域,本文介紹如何使用人體檢測功能。
前提條件
已建立並擷取AccessKey。具體操作,請參見建立AccessKey。
已開通OSS服務、建立儲存空間並上傳檔案到儲存空間。具體操作,請參見控制台上傳檔案。
已開通Intelligent Media Management服務。具體操作,請參見開通產品。
已通過Intelligent Media Management控制台建立專案。具體操作,請參見建立專案。
使用方法
調用DetectImageBodies - 檢測圖片中的人體介面擷取靶心圖表片人體資訊。
請求樣本
{
"ProjectName": "test-project",
"SourceURI": "oss://test-bucket/test-object.jpg",
"Sensitivity": 1
}
返回樣本
{
"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.596,
"Boundary": {
"Left": 63,
"Top": 102,
"Height": 100,
"Width": 82
}
},
{
"Confidence": 0.566,
"Boundary": {
"Left": 194,
"Top": 123,
"Height": 82,
"Width": 40
}
}
]
}
檢測結果說明
返回樣本顯示在當前圖片中檢測出四個人體資訊,人體的位置如下圖所示。

範例程式碼
以Python SDK為例,人體檢測的完整範例程式碼如下。
import sys
import os
from typing import List
from alibabacloud_imm20200930.client import Client as imm20200930Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_imm20200930 import models as imm_20200930_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client(
access_key_id: str,
access_key_secret: str,
) -> imm20200930Client:
"""
使用AccessKey ID&AccessKey Secret初始化帳號Client。
@param access_key_id:
@param access_key_secret:
@return: Client
@throws Exception
"""
config = open_api_models.Config(
access_key_id=access_key_id,
access_key_secret=access_key_secret
)
config.endpoint = f'imm.cn-beijing.aliyuncs.com'
return imm20200930Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
imm_access_key_id = os.getenv("AccessKeyId")
imm_access_key_secret = os.getenv("AccessKeySecret")
client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
detect_image_bodies_request = imm_20200930_models.DetectImageBodiesRequest(
project_name='test-project',
source_uri='oss://test-bucket/test-object.jpg',
sensitivity=1
)
runtime = util_models.RuntimeOptions()
try:
client.detect_image_bodies_with_options(detect_image_bodies_request, runtime)
except Exception as error:
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
imm_access_key_id = os.getenv("AccessKeyId")
imm_access_key_secret = os.getenv("AccessKeySecret")
client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
detect_image_bodies_request = imm_20200930_models.DetectImageBodiesRequest(
project_name='test-project',
source_uri='oss://test-bucket/test-object.jpg',
sensitivity=1
)
runtime = util_models.RuntimeOptions()
try:
await client.detect_image_bodies_with_options_async(detect_image_bodies_request, runtime)
except Exception as error:
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])