All Products
Search
Document Center

Intelligent Media Management:Vehicle information detection

Last Updated:Nov 14, 2024

The vehicle information detection feature can detect vehicle information in images. This technology is widely used in traffic monitoring, intelligent parking systems, autonomous driving assistance, urban traffic management, electronic toll collection systems, and safety and rescue services. This topic describes how to use the vehicle information detection feature.

Scenarios

  • Traffic management: Vehicle information detection can be used in traffic monitoring and management systems, such as identifying the images captured for traffic violations to help deal with traffic violations.

  • Identification of abnormal vehicles: Vehicle information detection can detect images uploaded to Object Storage Service (OSS) buckets to help identify vehicle information and license plate information.

    Note

    Vehicle information includes vehicle locations, vehicle colors, and vehicle types. License plate information includes license plate locations and license plate texts.

  • Traffic analysis: Vehicle information detection can help you analyze traffic information such as road usage and traffic distribution.

Prerequisites

  • An AccessKey pair is created and obtained. For more information, see Create an AccessKey pair.

  • OSS is activated, a bucket is created, and objects are uploaded to the bucket. For more information, see Upload objects.

  • Intelligent Media Management (IMM) is activated. For more information, see Activate IMM.

  • A project is created in the IMM console. For more information, see Create a project.

    Note
    • You can also call the CreateProject operation to create a project. For more information, see CreateProject.

    • You can call the ListProjects operation to query the existing projects in a specific region. For more information, see ListProjects.

Usage

Call the DetectImageCars operation to detect vehicle information in images.

Example

  • IMM project name: test-project

  • Image location: oss://test-bucket/test-object.jpg

  • Image example:

    test-object

Sample request

{
  "ProjectName": "test-project",
  "SourceURI": "oss://test-bucket/test-object.jpg"
}

Sample response

{
  "Cars": [
    {
      "CarColorConfidence": 0.817,
      "Confidence": 0.994,
      "CarType": "car",
      "CarColor": "gray",
      "LicensePlates": [
        {
          "Confidence": 0.877,
          "Content": "VRED2015",
          "Boundary": {
            "Left": 1269,
            "Top": 715,
            "Height": 23,
            "Width": 140
          }
        }
      ],
      "CarTypeConfidence": 0.749,
      "Boundary": {
        "Left": 1172,
        "Top": 430,
        "Height": 427,
        "Width": 905
      }
    }
  ],
  "RequestId": "2F15B1A9-F671-58B3-B3E4-69C7339EB472"
}
Note

The sample response shows that the detection image contains a gray vehicle with the license plate VRED2015.

Sample code

The following sample code provides an example on how to use IMM SDK for Python to detect vehicle information:

# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
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:
        """
        Use your AccessKey ID and AccessKey secret to initialize the 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
        )
        # Specify the IMM endpoint. 
        config.endpoint = f'imm.cn-beijing.aliyuncs.com'
        return imm20200930Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        # The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. To prevent security risks, we recommend that you call API operations or perform routine O&M as a Resource Access Management (RAM) user. 
        # We recommend that you do not include your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. 
        # In this example, the AccessKey pair is read from the environment variables to implement identity verification for API access. For more information about how to configure environment variables, see https://help.aliyun.com/document_detail/2361894.html. 
        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_cars_request = imm_20200930_models.DetectImageCarsRequest(
            project_name='test-project',
            source_uri='oss://test-bucket/test-object.jpg'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # You can choose to print the response of the API operation. 
            client.detect_image_cars_with_options(detect_image_cars_request, runtime)
        except Exception as error:
            # Print the error message if necessary. 
            UtilClient.assert_as_string(error.message)

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        # The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. To prevent security risks, we recommend that you call API operations or perform routine O&M as a RAM user. 
        # We recommend that you do not include your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. 
        # In this example, the AccessKey pair is read from the environment variables to implement identity verification for API access. For more information about how to configure environment variables, see https://help.aliyun.com/document_detail/2361894.html. 
        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_cars_request = imm_20200930_models.DetectImageCarsRequest(
            project_name='test-project',
            source_uri='oss://test-bucket/test-object.jpg'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # You can choose to print the response of the API operation. 
            await client.detect_image_cars_with_options_async(detect_image_cars_request, runtime)
        except Exception as error:
            # Print the error message if necessary. 
            UtilClient.assert_as_string(error.message)


if __name__ == '__main__':
    Sample.main(sys.argv[1:])