Object tracking tracks multiple objects detected in an input video. To make
an object tracking request, call the
annotate
method and specify OBJECT_TRACKING
in the features
field.
An object tracking request annotates a video with labels for entities and spatial locations for entities that are detected in the video or video segments provided. For example, a video of vehicles crossing a traffic signal might produce labels such as "car", "truck", "bike," "tires", "lights", "window" and so on. Each label can include a series of bounding boxes, with each bounding box having an associated time segment containing a time offset that indicates the duration offset from the beginning of the video. The annotation also contains additional entity information including an entity id that you can use to find more information about the entity in the Google Knowledge Graph Search API.
Object Tracking vs. Label Detection
Object tracking differs from label detection in that label detection provides labels without bounding boxes, whereas object tracking provides the labels of the individual objects present in a given video along with the bounding box of each object instance at every time step.
Also object tracking attempts to assign the same ID to the same object instance as long as the object has not departed the scene. So, if there are a red car and a blue one at time 0s, the tracking request will assign the red car an ID (say 0) and the blue car another ID (say 1). If at time 1s both cars are visible, the tracking request will assign them the same IDs they received at time 0s.
Request Object Tracking for a Video on Cloud Storage
The following samples demonstrate object tracking on a file located in Cloud Storage.
REST & CMD LINE
Send the process request
The following shows how to send a POST
request to the
annotate
method.
The example uses the access token for a service account set up for the project
using the Cloud SDK. For instructions on installing the Cloud SDK,
setting up a project with a service
account, and obtaining an access token, see the
Video Intelligence quickstart.
Before using any of the request data below, make the following replacements:
- input-uri: base-64-encoded-content
For example:
"inputUri": "gs://cloud-videointelligence-demo/assistant.mp4",
HTTP method and URL:
POST https://videointelligence.googleapis.com/v1/videos:annotate
Request JSON body:
{ "inputUri": "base-64-encoded-content", "features": ["OBJECT_TRACKING"] }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ "name": "projects/project-number/locations/location-id/operations/operation-id" }
If the request is successful, the Video Intelligence API returns the name
of your
operation. The above shows an example of such a response, where project-number
is the number of your project and operation-id
is the ID of the long-running
operation created for the request.
Get the results
To get the results of your request, send a GET
, using the operation name returned from the
call to videos:annotate
, as shown in the following example.
Before using any of the request data below, make the following replacements:
- operation-name: the name of the operation as
returned by the Video Intelligence API. The operation name has the format
projects/project-number/locations/location-id/operations/operation-id
HTTP method and URL:
GET https://videointelligence.googleapis.com/v1/operation-name
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
Download annotation results
Copy the annotation from the source to the destination bucket: (see Copy files and objects)
gsutil cp gcs_uri gs://my-bucket
Note: If the output gcs uri is provided by the user, then the annotation is stored in that gcs uri.
C#
Go
Java
Node.js
PHP
Python
Ruby
Request Object Tracking for Video from a Local File
The following samples demonstrate object tracking on a file stored locally.
REST & CMD LINE
Send the process request
To perform annotation on a local video file, base64-encode the contents of the video file.
Include the base64-encoded contents in the inputContent
field of the request.
For information on how to base64-encode the contents of a video file, see
Base64 Encoding.
The following shows how to send a POST
request to the
videos:annotate
method. The example uses the access token for
a service account set up for the project using the Cloud SDK. For
instructions on installing the Cloud SDK, setting up a project with a service
account, and obtaining an access token, see the
Video Intelligence quickstart.
Before using any of the request data below, make the following replacements:
- inputContent: base-64-encoded-content
For example:"UklGRg41AwBBVkkgTElTVAwBAABoZHJsYXZpaDgAAAA1ggAAxPMBAAAAAAAQCAA..."
HTTP method and URL:
POST https://videointelligence.googleapis.com/v1/videos:annotate
Request JSON body:
{ "inputContent": "base-64-encoded-content", "features": ["OBJECT_TRACKING"] }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
If the request is successful, Video Intelligence the name
for your operation. The
following shows an example of such a response, where project-number
is the number of your project and operation-id
is the ID of the long-running operation created for the request.
Get the results
To get the results of your request, you must send a GET
, using the operation name returned from the
call to videos:annotate
, as shown in the following example.
Before using any of the request data below, make the following replacements:
- operation-name: the name of the operation as
returned by the Video Intelligence API. The operation name has the format
projects/project-number/locations/location-id/operations/operation-id
HTTP method and URL:
GET https://videointelligence.googleapis.com/v1/operation-name
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
C#
Go
Java
Node.js
PHP