Questo tutorial mostra come utilizzare l'SDK Python per sfocare i volti nei video. L'esempio sfoca i file video di un bucket Cloud Storage e genera output video sfocati. Questi video di output vengono archiviati nello stesso bucket Cloud Storage dei video di origine.
Obiettivi
Questo tutorial illustra come:
- Creare un bucket Cloud Storage.
- Carica un file video locale nel bucket.
- Invia una richiesta utilizzando l'SDK Python.
- Visualizzare i video di output sfocati.
Costi
In questo documento utilizzi i seguenti componenti fatturabili di Google Cloud:
- Vertex AI Vision (Models - Person / face blur)
- Cloud Storage
Per generare una stima dei costi in base all'utilizzo previsto,
utilizza il Calcolatore prezzi.
Al termine delle attività descritte in questo documento, puoi evitare la fatturazione continua eliminando le risorse che hai creato. Per ulteriori informazioni, consulta la sezione Pulizia.
Prima di iniziare
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_ID
with your Google Cloud project name.
-
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI Vision, Cloud Storage APIs:
gcloud services enable visionai.googleapis.com
storage.googleapis.com -
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
-
Grant roles to your user account. Run the following command once for each of the following IAM roles:
roles/visionai.editor, roles/storage.objectAdmin
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE
- Replace
PROJECT_ID
with your project ID. -
Replace
USER_IDENTIFIER
with the identifier for your user account. For example,user:myemail@example.com
. - Replace
ROLE
with each individual role.
- Replace
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_ID
with your Google Cloud project name.
-
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI Vision, Cloud Storage APIs:
gcloud services enable visionai.googleapis.com
storage.googleapis.com -
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
-
Grant roles to your user account. Run the following command once for each of the following IAM roles:
roles/visionai.editor, roles/storage.objectAdmin
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE
- Replace
PROJECT_ID
with your project ID. -
Replace
USER_IDENTIFIER
with the identifier for your user account. For example,user:myemail@example.com
. - Replace
ROLE
with each individual role.
- Replace
- Recupera il codice sorgente dell'SDK Vertex AI Vision:
git clone https://github.com/google/visionai.git
Gli esempi di Python si trovano nella directory
visionai/python/example/
. - Ottieni l'SDK Python:
wget https://github.com/google/visionai/releases/download/v0.0.5/visionai-0.0.5-py3-none-any.whl
Aggiungi i file di input a Cloud Storage
Prima di poter inviare una richiesta utilizzando l'SDK Python, crea un bucket Cloud Storage e carica un video locale da utilizzare come input.
Crea un bucket Cloud Storage:
gcloud storage buckets create gs://BUCKET_NAME
Carica un file video locale nel nuovo bucket:
gcloud storage cp LOCAL_FILE gs://BUCKET_NAME
Installa le dipendenze e invia la richiesta
Dopo aver creato il bucket Cloud Storage per i video di input e di output e aver aggiunto un video locale, installa le dipendenze necessarie e invia la richiesta.
Facoltativo. Configura l'ambiente virtuale:
Se non è installato, installa
virtualenv
:sudo apt-get install python3-venv
Crea un nuovo ambiente virtuale:
python3 -m venv vaivenv
Attiva l'ambiente virtuale:
source vaivenv/bin/activate
Installa le dipendenze:
pip3 install visionai-0.0.5-py3-none-any.whl pip3 install google-cloud-storage
Invia la richiesta con l'SDK Python.
Apporta le seguenti sostituzioni delle variabili:
- PROJECT_ID: il tuo ID progetto Google Cloud .
- LOCATION_ID: il tuo ID posizione. Ad esempio,
us-central1
. Scopri di più. Regioni supportate. - BUCKET_NAME: il bucket Cloud Storage che hai creato.
python3 visionai/python/example/blur_gcs_video.py \ --project_id=PROJECT_ID –cluster_id=application-cluster-0 \ –location_id=LOCATION_ID –bucket_name=BUCKET_NAME
Dovresti vedere un output simile al seguente:
Listing mp4 files... test1.mp4 test2.mp4 Creating deid processes... process vnluvxgl is created process rvrdoucx is created Waiting for processes to finish... process vnluvxgl state is COMPLETED process rvrdoucx state is COMPLETED All processes have finished, please check the GCS bucket! ```
Esamina l'output
Una volta completata l'elaborazione del video, puoi esaminare l'output nel tuo bucket Cloud Storage. I file video sfocati generati saranno nello stesso bucket Cloud Storage del video di origine.
Elenca tutti gli oggetti nel bucket con il comando
gcloud storage ls
:gcloud storage ls gs://bucket
Dovresti vedere i file di origine e di output simili ai seguenti:
test1.mp4 test2.mp4 test1_deid_output.mp4 test2_deid_output.mp4
Facoltativo. Scarica i file di output localmente con il comando
gcloud storage cp
e visualizza i video sfocati:gcloud storage cp gs://BUCKET_NAME/FILE_NAME .
Esegui la pulizia
Per evitare che al tuo account Google Cloud vengano addebitati costi relativi alle risorse utilizzate in questo tutorial, elimina il progetto che contiene le risorse oppure mantieni il progetto ed elimina le singole risorse.
Passaggi successivi
- Scopri di più sul modello di sfocatura delle persone.
- Esplora architetture di riferimento, diagrammi e best practice su Google Cloud. Consulta il nostro Cloud Architecture Center.