Updated on 2024-04-22 GMT+08:00

Creating a Crowd Density Monitoring (Edge) Task

Function

This API is used to create a crowd density monitoring (edge) task.

URI

POST /v2/{project_id}/services/c-crowdcount-edge/tasks

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details about how to obtain the project ID and name, see Obtaining the Project ID and Name.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token. For details about how to obtain a user token, see Authentication.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

name

Yes

String

Job name. It can contain up to 100 characters and can include uppercase and lowercase letters, digits, hyphens (-), and underscores (_).

description

No

String

Job description. It can contain up to 500 characters.

Minimum: 0

Maximum: 500

schedule

No

TaskSchedule object

Task schedule. Only the weekly mode is supported.

input

Yes

TaskInput object

Input configuration of a job

output

Yes

TaskOutput object

Output configuration of a job. At least one output mode must be configured.

config

No

CrowdCountServiceConfig object

Job configuration parameters.

service_version

Yes

String

Service version. The value must match the regular expression ^[a-z0-9.]{3,32}$.

Minimum: 3

Maximum: 32

is_saved_as_template

No

Boolean

Whether to save the job configuration as a template.

resource_order_id

No

String

Resource order ID, which corresponds to the associated algorithm. This parameter is only mandatory for commercial algorithms and must match the regular expression ^[a-z0-9-_]{4,36}$.

Minimum: 4

Maximum: 36

Table 4 TaskSchedule

Parameter

Mandatory

Type

Description

type

Yes

String

Type of a scheduled task. This parameter is mandatory for scheduled tasks. The options are weekly and monthly.

timezone

Yes

String

Time zone where a user is located. This parameter is mandatory for scheduled jobs. The value is accurate to the minute.

days_of_week

No

Array of integers

Days in a week when a task is executed. This parameter is mandatory only for weekly tasks. The values 1 to 7 indicate Monday to Sunday respectively.

Minimum: 1

Maximum: 7

Array Length: 1 - 7

days_of_month

No

Array of integers

Days in a month when a task is executed. This parameter is mandatory only for monthly tasks. The values 1 to 31 indicate the first day to the 31st day of a month.

Minimum: 1

Maximum: 31

periods

No

Array<Array<>>

Time segment configuration. Select at least one time segment for executing a weekly or monthly job.

Table 5 TaskInput

Parameter

Mandatory

Type

Description

type

Yes

String

Task input type, which is mandatory when you create a task. The video_source type cannot be changed to other types. The following types are supported: obs (files stored in OBS, supported only by cloud tasks), url (specified file URL or stream request URL, supported only by cloud tasks), edgecamera (edge camera bound to IEF, supported only by edge tasks), restful (stream request URL obtained from a user-specified streaming server through a RESTful API, supported by both cloud and edge tasks), vcn (VCN device, supported only by edge tasks), and video_source (video sources managed in VIAS, supported by both cloud and edge tasks). You are advised to use the video_source type. Other types will be discontinued in the future. Options:

  • video_source

  • obs (not recommended and will be discontinued)

  • url (not recommended and will be discontinued)

  • edgecamera (not recommended and will be discontinued)

  • restful (not recommended and will be discontinued)

  • vcn (not recommended and will be discontinued)

data

Yes

Array of TaskInputData objects

Input details of a task, which is mandatory. The configuration varies according to the input type. Multiple inputs are allowed during creation, but only one input is allowed for update.

  • If the input type is obs, you must configure bucket, path, and index. Example: bucket: aicam, path: 3rdpartylicenses.txt, index: 0

  • If the input type is url, you must configure url and index. Example: url: https://xxx-xxx.com, index: 0

  • If the input type is restful, you must configure certificate_check, rtsp_path_in_response, url, index, and headers. Example: certificate_check: true, url: https://hsaij-dasahbi.com, rtsp_path_in_response: data/url, index: 0, headers: { AAA: AAA }

  • If the input type is vcn, you must configure device_id, stream_type, and index. Example: device_id: 21356478954612546874#gdhjkiushdgdksjhslmhscjsckjhdbnk, stream_type: 1, index: 0

  • If the input type is EdgeCamera, you must configure id and index. Example: id: 007cdafc-6000-47ce-b0e3-870b4a0db65e, index: 0.

Array Length: 1 - 50

vcn

No

TaskInputVcn object

VCN server information. This parameter is mandatory only when the input type is vcn.

Table 6 TaskInputData

Parameter

Mandatory

Type

Description

video_source_id

No

String

Video source ID. This parameter is mandatory when the input type is video_source.

stream_name

No

String

Name of a video stream.

bucket

No

String

OBS bucket name. This parameter is mandatory when the input type is obs.

Maximum: 63

path

No

String

OBS path. This parameter is mandatory when the input type is obs.

Maximum: 1023

url

No

String

File URL or RESTful request URL for obtaining a video stream. This parameter is mandatory when the input type is url or edgerestful. The value contains a maximum of 1000 characters.

Maximum: 1000

headers

No

Object

Headers carried in the RESTful request for obtaining a video stream. This parameter is optional when the input type is edgerestful. The value is key-value pairs in JSON format. A maximum of 10 key-value pairs are allowed.

certificate_check

No

Boolean

Whether to verify the certificate of the HTTPS request. This parameter is mandatory when the input type is edgerestful. The value can be true or false.

rtsp_path_in_response

No

String

Video stream address in the response body for the RESTful request. This parameter is mandatory when the input type is edgerestful. The value contains a maximum of 1024 characters.

Maximum: 1024

device_id

No

String

VCN ID. This parameter is mandatory when the input type is vcn.

stream_type

No

Integer

Stream type used for analysis. This parameter is optional when the input type is vcn. The value ranges from 1 to 3. The value 1 indicates primary stream, the value 2 indicates secondary stream 1, and the value 3 indicates secondary stream 2.

Minimum: 1

Maximum: 3

id

No

String

ID of the edge device mounted to IEF. This parameter is mandatory when the input type is edgecamera.

Maximum: 63

Table 7 TaskInputVcn

Parameter

Mandatory

Type

Description

ip

Yes

String

IP address of the VCN server. This parameter is mandatory only when the input type is vcn.

port

Yes

Integer

Port number of the VCN server. This parameter is mandatory only when the input type is vcn.

Minimum: 0

Maximum: 65535

username

Yes

String

Account name of a VCN server. This parameter is mandatory only when the input type is vcn. The value must match the regular expression ^.{1,100}$.

password

Yes

String

Password of a VCN server account. This parameter is mandatory only when the input type is vcn. The value must match the regular expression ^.{1,1000}$.

Table 8 TaskOutput

Parameter

Mandatory

Type

Description

obs

No

TaskOutputObs object

Configuration information when the output type is obs.

dis

No

TaskOutputDis object

Configuration information when the output type is dis.

webhook

No

TaskOutputWebhook object

Configuration information when the output type is webhook.

event_center

No

Boolean

Whether to send alarms to the event center. This parameter is valid for cloud jobs.

Default: false

Table 9 TaskOutputObs

Parameter

Mandatory

Type

Description

bucket

Yes

String

OBS bucket name. This parameter is mandatory when the OBS output type is used. The verification rule is (pattern: " ^[a-z0-9](?!.[-.][-.].)([a-z0-9-.]{1,61})[a-z0-9]$ ").

Maximum: 63

path

Yes

String

OBS path. This parameter is mandatory when the OBS output type is used. The verification rule is ^(?![/.\s])(?!.//.)([^:*?"<>|]{0,1023})(?<![.\s])$.

Maximum: 1023

data_category

No

Array of strings

List of job output types. This parameter is optional and is required only for some services. The output contains data in the dataCategory list.

Array Length: 0 - 10

Table 10 TaskOutputDis

Parameter

Mandatory

Type

Description

stream_name

Yes

String

DIS stream name. This parameter is mandatory when the dis type is used.

Maximum: 64

data_category

No

Array of strings

List of job output types. This parameter is optional and is required only for some services. The output contains data in the dataCategory list.

Array Length: 0 - 10

Table 11 TaskOutputWebhook

Parameter

Mandatory

Type

Description

url

Yes

String

Result callback address. This parameter is mandatory when the output type is webhook.

Maximum: 1000

headers

Yes

Object

Headers carried in result callback. This parameter is mandatory when the output type is webhook. The value is key-value pairs in JSON format. A maximum of 10 key-value pairs are allowed, and a minimum of 1 key-value pair is allowed.

data_category

No

Array of strings

List of job output types. This parameter is optional and is required only for some services. The output contains data in the dataCategory list.

Array Length: 0 - 10

Table 12 CrowdCountServiceConfig

Parameter

Mandatory

Type

Description

common

No

CrowdCountCommon object

Job runtime configuration items customized by the service publisher. The value must be in JSON format. For details about the configuration items, see the description of the corresponding algorithm service.

Table 13 CrowdCountCommon

Parameter

Mandatory

Type

Description

alarm_threshold

No

String

People count alarm thresholds. Default value: 50. The value must be a positive integer. When the number of people in a video frame is greater than or equal to the threshold, the video image is output in JSON format for alarm. You can enter different alarm thresholds for each ROI. The alarm thresholds are separated by spaces.

  • If the number of alarm thresholds within the list is greater than the actual number of ROIs, the first alarm thresholds matching the number of ROIs are used.

  • If the number of alarm thresholds within the list is less than the actual number of ROIs, use the default value for the rest part.

  • For example, if there are three ROIs and three threshold values (25 30 20) are entered, the image is sent as long as one ROI alarm is generated. When there are only two values (25 15) are entered, the threshold of the third ROI will be defaulted to 50. When there are more than three threshold values (such as 25 36 23 40) are entered, the first three values (25 36 23) are automatically selected.

sampling_time_interval

No

Integer

Interval at which video sampling is performed. The default value is 10s. The value range is [5, 3600], seconds. By default, a video image is sampled every 10 seconds, and N frames will be skipped between every two image samplings.

  • N = sampling_time_interval x Frame rate (fps). For example, if the frame rate is 25 fps and the sampling interval is 1 second, 25 frames will be skipped between every two image samplings.

Minimum: 5

Maximum: 3600

Default: 10

alert_mode

No

String

Alarming mode. Default value: single. There are two alarm modes:

  • single: event alarming. An alarm is reported only when a new alarm event is generated and the number of people reaches the alarm threshold.

  • periodic: periodic alarming. An alarm is reported each time a video sampling interval expires.

Default: single

banner_detection_sw

No

Integer

Whether to enable protest banner detection. The value ranges from 0 to 1 and the default value is 0. When the function is enabled, the system detects banners in the ROI area of video images.

Minimum: 0

Maximum: 1

Default: 0

banner_threshold

No

String

List of banner detection alarm thresholds. The default value is 1. The value must be a positive integer. For details about how to use this parameter, see alarm_threshold.

visualization_output_sw

No

Integer

Whether to send the edited video image with scenario information in it. The value ranges from 0 to 1 and the default value is 0. By default, when the number of people in each ROI exceeds the alarm threshold, only the structured information of the original image is sent. The detected people and banners can be displayed only after the visualization function is enabled. The visualized alarm information in images for different scenarios is as follows:

  • Banners for protests are marked in red boxes.

  • If a densely populated area is detected, the area is rendered in different colors.

  • Each ROI is marked with a yellow polygon in the image.

Minimum: 0

Maximum: 1

Default: 0

density_sw

No

Integer

Density estimation status. You can customize whether to use a density estimation model to evaluate the number of people. Use a density estimation model if the number of people is large and the alarm threshold is large.

  • A density estimation model is used by default. The value ranges from 0 to 1 and the default value is 1.

Minimum: 0

Maximum: 1

Default: 1

image_compression_ratio

No

Integer

Corresponds to the Image Compression Ratio parameter on the console. The value ranges from 20 to 100. The default value is 90, indicating that the image compression ratio is 90%.

Minimum: 20

Maximum: 100

Default: 90

target_roi

No

String

Corresponds to the Target ROI parameter on the console.

  • This parameter specifies the detection area. The value of this parameter is a JSON string. An escape character must be added in an API call. For details about the JSON format, see Setting target_roi.

  • Example: {"polygons":[{"data":[[84,389],[1840,349],[1824,526],[78,526]]}]}

  • If this parameter is not specified, the detection area is the entire video frame.

Response Parameters

Status code: 200

Table 14 Response body parameters

Parameter

Type

Description

tasks

Array of TaskResponse objects

ID list of tasks created in VIAS

Table 15 TaskResponse

Parameter

Type

Description

id

String

ID of a task created in VIAS

Status code: 400

Table 16 Response body parameters

Parameter

Type

Description

error_code

String

Error code

error_msg

String

Error information

detail

String

Error details

params

Array of strings

Error parameters

Array Length: 0 - 1

reason

String

Error cause

advice

String

Suggestion

Status code: 500

Table 17 Response body parameters

Parameter

Type

Description

error_code

String

Error code

error_msg

String

Error information

detail

String

Error details

params

Array of strings

Error parameters

Array Length: 0 - 1

reason

String

Error cause

advice

String

Suggestion

Example Requests

  • This request is used to create a crowd density monitoring (edge) task, with the input type set to video_source and the output type set to webhook.

    POST /v2/{project_id}/services/c-crowdcount-edge/tasks
    
    {
      "name" : "crowdcount-edge-task",
      "description" : "Crowdcounttedetection task test",
      "input" : {
        "type" : "video_source",
        "data" : [ {
          "video_source_id" : "xxxxxxx-xxxxxxx-xxxxxxx-xxxxx-xxxxxx"
        } ]
      },
      "output" : {
        "webhook" : {
          "url" : "https://127.0.0.1:8080/webhook",
          "headers" : {
            "x-auth-token" : "tokentest"
          }
        }
      },
      "service_version" : "3.0",
      "resource_order_id" : "840a5cf90d4a4bbaa71f251dfe8fe64e",
      "config" : {
        "common" : {
          "banner_detection_sw" : 1,
          "banner_threshold" : "2",
          "alarm_threshold" : "5",
          "sampling_time_interval" : 8,
          "density_sw" : 1,
          "visualization_output_sw" : 1,
          "image_compression_ratio" : 80,
          "target_roi" : "{\"polygons\":[{\"data\":[[100,100],[1800,100],[1800,1000],[100,1000]]}]}"
        }
      }
    }
  • This request is used to create a crowd density monitoring (edge) task, with the input type set to vcn and the output type set to dis.

    POST /v2/{project_id}/services/c-crowdcount-edge/tasks
    
    {
      "name" : "crowdcount-edge-task",
      "description" : "Crowdcounttedetection task test",
      "input" : {
        "type" : "vcn",
        "data" : [ {
          "device_id" : "aec5857c-222f-4aa9-be39-23654e118886",
          "stream_type" : 2
        } ],
        "vcn" : {
          "ip" : "127.0.0.1",
          "port" : 8080,
          "username" : "vcntest",
          "password" : "123456abcd"
        }
      },
      "output" : {
        "dis" : {
          "stream_name" : "dis-test"
        }
      },
      "service_version" : "3.0",
      "resource_order_id" : "840a5cf90d4a4bbaa71f251dfe8fe64e",
      "config" : {
        "common" : {
          "banner_detection_sw" : 1,
          "banner_threshold" : "2",
          "alarm_threshold" : "5",
          "sampling_time_interval" : 8,
          "density_sw" : 1,
          "visualization_output_sw" : 1,
          "image_compression_ratio" : 80,
          "target_roi" : "{\"polygons\":[{\"data\":[[100,100],[1800,100],[1800,1000],[100,1000]]}]}"
        }
      }
    }
  • This request is used to create a crowd density monitoring (edge) task, with the input type set to edgecamera and the output type set to dis.

    POST /v2/{project_id}/services/c-crowdcount-edge/tasks
    
    {
      "name" : "crowdcount-edge-task",
      "description" : "Crowdcounttedetection task test",
      "input" : {
        "type" : "edgecamera",
        "data" : [ {
          "id" : "aec5857c-222f-4aa9-be39-23654e118886",
          "index" : 0
        } ]
      },
      "output" : {
        "dis" : {
          "stream_name" : "crowdcount-edge"
        }
      },
      "service_version" : "3.0",
      "resource_order_id" : "840a5cf90d4a4bbaa71f251dfe8fe64e",
      "config" : {
        "common" : {
          "banner_detection_sw" : 1,
          "banner_threshold" : "2",
          "alarm_threshold" : "5",
          "sampling_time_interval" : 8,
          "density_sw" : 1,
          "visualization_output_sw" : 1,
          "image_compression_ratio" : 80,
          "target_roi" : "{\"polygons\":[{\"data\":[[100,100],[1800,100],[1800,1000],[100,1000]]}]}"
        }
      }
    }
  • This request is used to create a crowd density monitoring (edge) task, with the input type set to restful and the output type set to webhook.

    POST /v2/{project_id}/services/c-crowdcount-edge/tasks
    
    {
      "name" : "crowdcount-edge-task",
      "description" : "Crowdcounttedetection task test",
      "input" : {
        "type" : "restful",
        "data" : [ {
          "url" : "https://restfultest",
          "certificate_check" : false,
          "node_id" : "aec5857c-222f-4aa9-be39-23654e118886",
          "rtsp_path_in_response" : "http://testpath"
        } ]
      },
      "output" : {
        "webhook" : {
          "url" : "https://127.0.0.1:8080/webhook",
          "headers" : {
            "x-auth-token" : "tokentest"
          }
        }
      },
      "service_version" : "3.0",
      "resource_order_id" : "840a5cf90d4a4bbaa71f251dfe8fe64e",
      "config" : {
        "common" : {
          "banner_detection_sw" : 1,
          "banner_threshold" : "2",
          "alarm_threshold" : "5",
          "sampling_time_interval" : 8,
          "density_sw" : 1,
          "visualization_output_sw" : 1,
          "image_compression_ratio" : 80,
          "target_roi" : "{\"polygons\":[{\"data\":[[100,100],[1800,100],[1800,1000],[100,1000]]}]}"
        }
      }
    }

Example Responses

Status code: 200

Operation successful

{
  "tasks" : [ {
    "id" : "20690c67d71549c39085a3b28c18f24f"
  } ]
}

Status Codes

Status Code

Description

200

Operation successful

400

Request error

500

Internal error

Error Codes

See Error Codes.