Il monitoraggio degli oggetti consente di monitorare gli oggetti rilevati in un video di input. Per effettuare
una richiesta di monitoraggio degli oggetti, chiama il
metodo
annotate
e specifica OBJECT_TRACKING
nel campo features
.
Per le entità e le posizioni spaziali rilevate in un video o in segmenti di video, una richiesta di monitoraggio degli oggetti annota il video con le etichette appropriate per queste entità e posizioni spaziali. Ad esempio, un video di veicoli che attraversano un segnale dei semafori potrebbe produrre etichette come "auto", "camion", "bici", "pneumatici", "luci", "finestra" e così via. Ogni etichetta può includere una serie di riquadri di delimitazione, ciascuno associato a un segmento di tempo contenente un offset temporale che indica l'offset della durata dall'inizio del video. L'annotazione contiene anche altre informazioni sull'entità, tra cui un ID entità che puoi per trovare ulteriori informazioni sull'entità API Google Knowledge Graph Search.
Confronto tra monitoraggio di oggetti e rilevamento di etichette
Il monitoraggio degli oggetti è diverso dal rilevamento delle etichette. Etichetta il rilevamento fornisce etichette senza riquadri di delimitazione, mentre il tracciamento degli oggetti fornisce le etichette dei singoli oggetti presenti in un determinato video insieme con il riquadro di delimitazione di ciascuna istanza dell'oggetto in ogni passo temporale.
Più istanze dello stesso tipo di oggetto sono assegnate a istanze diverse
di ObjectTrackingAnnotation
messaggio in cui tutte le occorrenze di un
vengono conservate nella propria istanza di ObjectTrackingAnnotation
. Ad esempio, se in un video appaiono un'auto rossa e un'auto blu per 5 secondi, la richiesta di monitoraggio deve restituire due istanze di ObjectTrackingAnnotation
. La prima istanza conterrà
la posizione di una delle due auto, ad esempio l'auto rossa, mentre
e il secondo conterrà le posizioni dell'altra auto.
Richiedi il monitoraggio degli oggetti per un video su Cloud Storage
I seguenti esempi dimostrano il monitoraggio degli oggetti su un file che si trova in di archiviazione ideale in Cloud Storage.
REST
Invia la richiesta di processo
Di seguito viene mostrato come inviare una richiesta POST
al metodo
annotate
.
L'esempio utilizza il token di accesso per un account di servizio configurato per il progetto utilizzando Google Cloud CLI. Per istruzioni sull'installazione di Google Cloud CLI:
per configurare un progetto con un servizio
di accesso all'account e ottenere un token di accesso, consulta
Guida rapida di Video Intelligence.
Prima di utilizzare i dati della richiesta, effettua le seguenti sostituzioni:
- INPUT_URI: STORAGE_URI
Ad esempio:
"inputUri": "gs://cloud-videointelligence-demo/assistant.mp4",
- PROJECT_NUMBER: l'identificatore numerico del tuo progetto Google Cloud
Metodo HTTP e URL:
POST https://videointelligence.googleapis.com/v1/videos:annotate
Corpo JSON della richiesta:
{ "inputUri": "STORAGE_URI", "features": ["OBJECT_TRACKING"] }
Per inviare la richiesta, espandi una delle seguenti opzioni:
Dovresti ricevere una risposta JSON simile alla seguente:
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/operations/OPERATION_ID" }
Se la richiesta ha esito positivo, l'API Video Intelligence restituisce name
del tuo
operativa. Quanto sopra mostra un esempio di risposta di questo tipo, dove PROJECT_NUMBER
è il numero del progetto e OPERATION_ID
è l'ID della configurazione
dell'operazione creata per la richiesta.
Ottieni i risultati
Per ottenere i risultati della richiesta, invia un GET
utilizzando il nome dell'operazione restituito
a videos:annotate
, come illustrato nell'esempio seguente.
Prima di utilizzare i dati della richiesta, apporta le seguenti sostituzioni:
- OPERATION_NAME: il nome dell'operazione come fornito dall'API Video Intelligence. Il nome dell'operazione ha il formato
projects/PROJECT_NUMBER/locations/LOCATION_ID/operations/OPERATION_ID
- PROJECT_NUMBER: l'identificatore numerico del tuo progetto Google Cloud
Metodo HTTP e URL:
GET https://videointelligence.googleapis.com/v1/OPERATION_NAME
Per inviare la richiesta, espandi una di queste opzioni:
Dovresti ricevere una risposta JSON simile alla seguente:
Scarica i risultati delle annotazioni
Copia l'annotazione dal bucket di origine a quello di destinazione: (vedi Copiare file e oggetti)
gcloud storage cp gcs_uri gs://my-bucket
Nota: se l'URI GCS di output è fornito dall'utente, l'annotazione viene archiviata nell'URI GCS.
Go
Java
Node.js
Per autenticarti a Video Intelligence, configura Credenziali predefinite dell'applicazione. Per ulteriori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.
Python
Linguaggi aggiuntivi
C#: Segui le Istruzioni per la configurazione di C# Nella pagina delle librerie client e poi visita Documentazione di riferimento di Video Intelligence per .NET.
PHP: segui le istruzioni di configurazione di PHP riportate nella pagina delle librerie client e consulta la documentazione di riferimento di Video Intelligence per PHP.
Ruby: segui le istruzioni di configurazione di Ruby riportate nella pagina delle librerie client e consulta la documentazione di riferimento di Video Intelligence per Ruby.
Richiedere il monitoraggio degli oggetti per un video da un file locale
I seguenti esempi dimostrano il monitoraggio degli oggetti in un file archiviato localmente.
REST
Invia la richiesta di processo
Per eseguire l'annotazione su un file video locale, esegui la codifica in base64 dei contenuti del file video.
Includi i contenuti con codifica Base64 nel campo inputContent
della richiesta.
Per informazioni su come codificare in base64 i contenuti di un file video, consulta
Codifica Base64.
Di seguito viene mostrato come inviare una richiesta POST
al metodo
videos:annotate
. L'esempio utilizza il token di accesso per un account di servizio configurato per il progetto utilizzando Google Cloud CLI. Per
Istruzioni sull'installazione di Google Cloud CLI, sulla configurazione di un progetto con un servizio
di accesso all'account e ottenere un token di accesso, consulta
Guida rapida di Video Intelligence.
Prima di utilizzare i dati della richiesta, effettua le seguenti sostituzioni:
- inputContent: BASE64_ENCODED_CONTENT
Ad esempio:"UklGRg41AwBBVkkgTElTVAwBAABoZHJsYXZpaDgAAAA1ggAAxPMBAAAAAAAQCAA..."
- PROJECT_NUMBER: l'identificatore numerico del tuo progetto Google Cloud
Metodo HTTP e URL:
POST https://videointelligence.googleapis.com/v1/videos:annotate
Corpo JSON della richiesta:
{ "inputContent": "BASE64_ENCODED_CONTENT", "features": ["OBJECT_TRACKING"] }
Per inviare la richiesta, espandi una delle seguenti opzioni:
Dovresti ricevere una risposta JSON simile alla seguente:
Se la richiesta ha esito positivo, Video Intelligence utilizzerà name
per la tua operazione. La
seguente mostra un esempio di risposta di questo tipo, in cui PROJECT_NUMBER
è il numero del progetto e OPERATION_ID
è l'ID dell'operazione a lunga esecuzione creata per la richiesta.
Visualizza i risultati
Per ottenere i risultati della richiesta, devi inviare un GET
utilizzando il nome dell'operazione restituito dalla chiamata a videos:annotate
, come mostrato nell'esempio seguente.
Prima di utilizzare i dati della richiesta, effettua le seguenti sostituzioni:
- OPERATION_NAME: il nome dell'operazione come fornito dall'API Video Intelligence. Il nome dell'operazione ha il formato
projects/PROJECT_NUMBER/locations/LOCATION_ID/operations/OPERATION_ID
- PROJECT_NUMBER: l'identificatore numerico del tuo progetto Google Cloud
Metodo HTTP e URL:
GET https://videointelligence.googleapis.com/v1/OPERATION_NAME
Per inviare la richiesta, espandi una di queste opzioni:
Dovresti ricevere una risposta JSON simile alla seguente:
Go
Java
Node.js
Per autenticarti a Video Intelligence, configura le credenziali predefinite dell'applicazione. Per ulteriori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.
Python
Linguaggi aggiuntivi
C#: Segui le Istruzioni per la configurazione di C# Nella pagina delle librerie client e poi visita Documentazione di riferimento di Video Intelligence per .NET.
PHP Segui le Istruzioni per la configurazione dei file PHP Nella pagina delle librerie client e poi visita Documentazione di riferimento di Video Intelligence per PHP.
Ruby: Segui le Istruzioni per la configurazione di Ruby Nella pagina delle librerie client e poi visita Documentazione di riferimento di Video Intelligence per Ruby.