Skip to main content
Version: 5.1.6

Traffic Counting API

Ultinous AI Suite's measurement-based counters are designed to be used with custom third party software. This guide will cover how the data created by the counters can be read from Ultinous AI Suite.

If you wish to double-check the data produced by your counters, they can be viewed inside Ultinous AI Suite as well, in a dedicated Counters interface.

Prerequisites

  • Finished the Quick Start Guide and created a test Solution to make sure that your camera is working and events are triggered. (This test Solution can be deleted after testing.)
  • Created an API Token so that the third party software has access to Ultinous AI Suite.
  • Created a Traffic Counting solution. Please note that the technical name value will be the identifier value for the API. This is a UUID by default, but can be renamed to any unique string.

Using the API

The output from each counter is a number indicating the number of detections in the union of all cameras' regions of interests (ROI).

The API is read-only and has two main ways of accessing the counters:

  • Batch mode, where past counter values are of interest.
  • Live Server Side Event mode for real time processing of values.

A list of available technical names can also be queried: these are unique identifiers assigned to each registered solution. Editable in the Ultinous AI Suite web interface, otherwise a default technical name is generated.

To reach the endpoints, an API token has to be generated - see the API Token section of the guide.

API URL

const url = "http://<address-of-Ultinous AI Suite>/API"; //< note the /API at the end.

Bach mode

JSON output

Path: /traffic_counter/batch

Parameters:

  • from_timestamp: (int64) The starting timestamp of the request interval (inclusive).
  • to_timestamp: (int64) The end timestamp of the request interval (exclusive).
  • technical_name: (string) The UUID of the solution.
  • token: (string) The token you generated in the web interface, see above.

Example javascript

The following example is using javascript and its fetch function to show how these values can be read.

const url = "http://<address-of-Ultinous AI Suite>/API"; //< note the /API at the end.
/**
* maximum time interval is three days
* @param technical_name: string ; counter technical name
* @param token : A base64 token issued by Ultinous AI Suite
* @param from_timestamp : unix timestamp; Only show counter values from given date
* @param to_timestamp : unix timestamp; Show values until.
*/
const params = new URLSearchParams({
'from_timestamp':'unix-timestamp',
'to_timestamp':'unix-timestamp',
'token':'api-token',
'technical_name':'counter-technical-name'
});

fetch(`${url}/traffic_counter/batch${params.toString()}`)
.then( value => console.log(value.json()))

Example response

[ //< Array of aggregation periods
{
"timestamp": 1659625903893,
"direction": "IN",
"camera": {
"display_name": "motionfilterperson",
"technical_name": "motionfilterperson-cam"
},
"object_type": "PERSON_FULL_BODY"
},
{
"timestamp": 1659625909393,
"direction": "OUT",
"camera": {
"display_name": "motionfilterperson",
"technical_name": "motionfilterperson-cam"
},
"object_type": "PERSON_FULL_BODY"
},
{
"timestamp": 1659625919093,
"direction": "IN",
"camera": {
"display_name": "motionfilterperson",
"technical_name": "motionfilterperson-cam"
},
"object_type": "PERSON_FULL_BODY"
}
]

CSV output

Path: /traffic_counter/batch/csv

Parameters:

  • from_timestamp: (int64) The starting timestamp of the request interval (inclusive).
  • to_timestamp: (int64) The end timestamp of the request interval (exclusive).
  • technical_name: (string) The UUID of the solution.

Example javascript

The following example is using javascript and its fetch function to show how these values can be read.

const url = "http://<address-of-Ultinous AI Suite>/API"; //< note the /API at the end.
/**
* maximum time interval is three days
* @param technical_name: string ; counter technical name
* @param token : A base64 token issued by Ultinous AI Suite
* @param from_timestamp : unix timestamp; Only show counter values from given date
* @param to_timestamp : unix timestamp; Show values until.
*/
const params = new URLSearchParams({
'from_timestamp':'unix-timestamp',
'to_timestamp':'unix-timestamp',
'token':'api-token',
'technical_name':'counter-technical-name'
});

fetch(`${url}/traffic_counter/batch/csv${params.toString()}`)
.then( value => console.log(value.json()))

Example response

timestamp,direction,technical_name,object_type
1659625903893,IN,motionfilterperson-cam,PERSON_FULL_BODY
1659625909393,OUT,motionfilterperson-cam,PERSON_FULL_BODY
1659625919093,IN,motionfilterperson-cam,PERSON_FULL_BODY
1659625936593,OUT,motionfilterperson-cam,PERSON_FULL_BODY
1659625938093,IN,motionfilterperson-cam,PERSON_FULL_BODY
1659625946093,OUT,motionfilterperson-cam,PERSON_FULL_BODY
1659625949493,IN,motionfilterperson-cam,PERSON_FULL_BODY
1659625955793,OUT,motionfilterperson-cam,PERSON_FULL_BODY
1659625963993,IN,motionfilterperson-cam,PERSON_FULL_BODY
1659625969493,OUT,motionfilterperson-cam,PERSON_FULL_BODY
1659625978993,IN,motionfilterperson-cam,PERSON_FULL_BODY

Server Side Event Mode

Path: /traffic_counter/live

Parameters:

  • technical_names: array of technical names

Time ordered merged

Example request

const params = new URLSearchParams({
'token':'api-token',
'technical_names':['name-1','name2'] //< Multiple technical_names can be requested
});
const evtPath = `${url}/traffic_counter/live?${params.toString()}`
const evtSource = new EventSource(evtPath)
evtSource.onmessage = evt => console.log(evt.data)

Example response

[ //< Array of technical_name and record pairs
"77effbb0-2e1b-4090-8ef3-abe41a12f642":{
"timestamp": 1659625903893,
"direction": "IN",
"camera": {
"display_name": "motionfilterperson",
"technical_name": "motionfilterperson-cam"
},
"object_type": "PERSON_FULL_BODY"
},
"77effbb0-2e1b-4090-8ef3-abe41a12f642":{
"timestamp": 1659625909393,
"direction": "OUT",
"camera": {
"display_name": "motionfilterperson",
"technical_name": "motionfilterperson-cam"
},
"object_type": "PERSON_FULL_BODY"
},
"77effbb0-2e1b-4090-8ef3-abe41a12f642":{
"timestamp": 1659625919093,
"direction": "IN",
"camera": {
"display_name": "motionfilterperson",
"technical_name": "motionfilterperson-cam"
},
"object_type": "PERSON_FULL_BODY"
}
]

List of technical names

Path: /traffic_counter/technical_names

["name-1", "name2"]

A queryable list of available technical names.

Troubleshooting

Error Status Codes

  • 401 Unauthorized - Wrong API Key. Make sure a valid key is set up.
  • 404 Not Found - The technical_name(s) parameter is invalid.
  • 502 Bad Gateway - Ultinous AI Suite API is not running. Please try logging in to the Ultinous AI Suite User Interface, or restart the physical device.