主体识别

AI搜索开放平台,支持从图像中自动检测并识别一个或多个主要目标。适用于智能监控、自动驾驶、图像检索等典型计算机视觉应用场景。

准备工作

为确保 SDK 能正常调用服务,请在使用前完成必要的准备工作,包括配置运行环境及获取服务访问所需的认证与接入信息。

参数说明

  • 请求体body最大不能超过8MB。

  • 更多参数说明请参见主体识别

from alibabacloud_tea_openapi.models import Config
from alibabacloud_searchplat20240529.client import Client
from alibabacloud_searchplat20240529.models import GetImageObjectDetectionRequest, GetImageObjectDetectionResponse

if __name__ == '__main__': 
    # token配置,endpoint配置
    config = Config(bearer_token="替换为您的API-KEY",
                     # endpoint: 配置统一的请求入口 需要去掉http://
                    endpoint="替换API访问地址",
                    # 支持 protocol 配置 HTTPS/HTTP
                    protocol="http")
    client = Client(config=config)
    request = GetImageObjectDetectionRequest()
    request.from_map({"image":{"url":"https://img.alicdn.com/imgextra/i1/O1CN01WksnF41hlhBFsXDNB_!!6000000004318-0-tps-1000-1400.jpg"}})
    response : GetImageObjectDetectionResponse = client.get_image_object_detection("default", 'ops-object-detect-001', request)
    print (response.body.result)
    print (response.body.usage)

执行成功将返回以下结果:

{
  "result": {
    "objects": [
      {
        "confidence": 0.2972888,
        "location": {
          "width": 386,
          "height": 200,
          "X": 543,
          "Y": 346
        }
      },
      {
        "confidence": 0.19349518,
        "location": {
          "width": 266,
          "height": 140,
          "X": 278,
          "Y": 285
        }
      },
      {
        "confidence": 0.15851636,
        "location": {
          "width": 257,
          "height": 170,
          "X": 184,
          "Y": 488
        }
      }
    ]
  },
  "latency": 211,
  "usage": {
    "image": 1
  },
  "request_id": "6c93e8a7a236fa5e9a117c51f3747cd7"
}