Object tracking tracks objects detected in an input video. To make
an object tracking request, call the
annotate
method and specify OBJECT_TRACKING
in the features
field.
For entities and spatial locations that are detected in a video or video segments, an object tracking request annotates the video with the appropriate labels for these entities and spatial locations. 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. 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.
Multiple instances of the same object type are assigned to different instances
of ObjectTrackingAnnotation
message where all the occurrences of a given
object track are kept in its own instance of ObjectTrackingAnnotation
. For
example, if there is a red car and a blue car appearing for 5 seconds in a
video, the tracking request should return two instances of
ObjectTrackingAnnotation
. The first instance will contain
the locations of one of the two cars, for example, the red car, while the
second will contain the locations of the other car.
Request object tracking for a video on Cloud Storage
The following samples demonstrate object tracking on a file located in Cloud Storage.
REST
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 Google Cloud CLI. For instructions on installing the Google Cloud CLI,
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, make the following replacements:
- INPUT_URI: STORAGE_URI
For example:
"inputUri": "gs://cloud-videointelligence-demo/assistant.mp4",
- PROJECT_NUMBER: The numeric identifier for your Google Cloud project
HTTP method and URL:
POST https://videointelligence.googleapis.com/v1/videos:annotate
Request JSON body:
{ "inputUri": "STORAGE_URI", "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, 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
- PROJECT_NUMBER: The numeric identifier for your Google Cloud project
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)
gcloud storage 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.
Go
Java
Node.js
To authenticate to Video Intelligence, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
Additional languages
C#: Please follow the C# setup instructions on the client libraries page and then visit the Video Intelligence reference documentation for .NET.
PHP: Please follow the PHP setup instructions on the client libraries page and then visit the Video Intelligence reference documentation for PHP.
Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the Video Intelligence reference documentation for Ruby.
Request object tracking for video from a local file
The following samples demonstrate object tracking on a file stored locally.
REST
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 Google Cloud CLI. For
instructions on installing the Google Cloud CLI, 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, make the following replacements:
- inputContent: BASE64_ENCODED_CONTENT
For example:"UklGRg41AwBBVkkgTElTVAwBAABoZHJsYXZpaDgAAAA1ggAAxPMBAAAAAAAQCAA..."
- PROJECT_NUMBER: The numeric identifier for your Google Cloud project
HTTP method and URL:
POST https://videointelligence.googleapis.com/v1/videos:annotate
Request JSON body:
{ "inputContent": "BASE64_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, 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
- PROJECT_NUMBER: The numeric identifier for your Google Cloud project
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:
Go
Java
Node.js
To authenticate to Video Intelligence, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
Additional languages
C#: Please follow the C# setup instructions on the client libraries page and then visit the Video Intelligence reference documentation for .NET.
PHP: Please follow the PHP setup instructions on the client libraries page and then visit the Video Intelligence reference documentation for PHP.
Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the Video Intelligence reference documentation for Ruby.