Este tutorial mostra como usar o SDK Python para esbater rostos em vídeos. O exemplo esbate ficheiros de vídeo de um contentor do Cloud Storage e gera resultados de vídeo esbatidos. Estes vídeos de saída são armazenados no mesmo contentor do Cloud Storage que os vídeos de origem.
Objetivos
Este tutorial mostra como fazer o seguinte:
- Crie um contentor do Cloud Storage.
- Carregue um ficheiro de vídeo local para o contentor.
- Envie um pedido através do SDK Python.
- Veja vídeos com a saída esbatida.
Custos
Neste documento, usa os seguintes componentes faturáveis do Google Cloud:
- Vertex AI Vision (Models - Person / face blur)
- Cloud Storage
Para gerar uma estimativa de custos com base na sua utilização projetada,
use a calculadora de preços.
Quando terminar as tarefas descritas neste documento, pode evitar a faturação contínua eliminando os recursos que criou. Para mais informações, consulte o artigo Limpe.
Antes de começar
- 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.
-
Se estiver a usar um fornecedor de identidade (IdP) externo, tem primeiro de iniciar sessão na CLI gcloud com a sua identidade federada.
-
Para inicializar a CLI gcloud, execute o seguinte comando:
gcloud init
-
Create or select a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
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.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI Vision, Cloud Storage APIs:
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles.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.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
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 the following:
PROJECT_ID
: your project ID.USER_IDENTIFIER
: the identifier for your user account—for example,myemail@example.com
.ROLE
: the IAM role that you grant to your user account.
-
Install the Google Cloud CLI.
-
Se estiver a usar um fornecedor de identidade (IdP) externo, tem primeiro de iniciar sessão na CLI gcloud com a sua identidade federada.
-
Para inicializar a CLI gcloud, execute o seguinte comando:
gcloud init
-
Create or select a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
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.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI Vision, Cloud Storage APIs:
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles.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.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
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 the following:
PROJECT_ID
: your project ID.USER_IDENTIFIER
: the identifier for your user account—for example,myemail@example.com
.ROLE
: the IAM role that you grant to your user account.
- Obtenha o código-fonte do SDK Vertex AI Vision:
git clone https://github.com/google/visionai.git
Os exemplos de Python estão localizados no diretório
visionai/python/example/
. - Obtenha o SDK Python:
wget https://github.com/google/visionai/releases/download/v0.0.5/visionai-0.0.5-py3-none-any.whl
Crie um contentor do Cloud Storage:
gcloud storage buckets create gs://BUCKET_NAME
Carregue um ficheiro de vídeo local para o novo contentor:
gcloud storage cp LOCAL_FILE gs://BUCKET_NAME
Opcional. Configure o ambiente virtual:
Se não estiver instalada, instale a app
virtualenv
:sudo apt-get install python3-venv
Crie um novo ambiente virtual:
python3 -m venv vaivenv
Ative o ambiente virtual:
source vaivenv/bin/activate
Instalar dependências:
pip3 install visionai-0.0.5-py3-none-any.whl pip3 install google-cloud-storage
Envie o seu pedido com o SDK Python.
Faça as seguintes substituições de variáveis:
- PROJECT_ID: o ID do seu Google Cloud projeto.
- LOCATION_ID: o ID da sua localização. Por exemplo,
us-central1
. Mais informações. Regiões suportadas. - BUCKET_NAME: o contentor do Cloud Storage que criou.
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
Deverá ver uma saída semelhante à seguinte:
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! ```
Apresente uma lista de todos os objetos no seu contentor com o comando
gcloud storage ls
:gcloud storage ls gs://bucket
Deverá ver os ficheiros de origem e os ficheiros de saída semelhantes ao seguinte:
test1.mp4 test2.mp4 test1_deid_output.mp4 test2_deid_output.mp4
Opcional. Transfira os ficheiros de saída localmente com o comando
gcloud storage cp
e veja os vídeos com o efeito de esbatimento:gcloud storage cp gs://BUCKET_NAME/FILE_NAME .
- Leia mais acerca do modelo de esbatimento de pessoas.
- Explore arquiteturas de referência, diagramas e práticas recomendadas sobre o Google Cloud. Consulte o nosso Centro de arquitetura na nuvem.
Adicione ficheiros de entrada ao Cloud Storage
Antes de poder enviar um pedido através do SDK Python, crie um contentor do Cloud Storage e carregue um vídeo local para usar como entrada.
Instale as dependências e envie o pedido
Depois de criar o contentor do Cloud Storage para vídeos de entrada e saída e adicionar um vídeo local, instale as dependências necessárias e envie o seu pedido.
Examine a saída
Depois de o vídeo terminar o processamento, pode examinar o resultado no seu contentor do Cloud Storage. Os ficheiros de vídeo esbatidos gerados vão estar no mesmo contentor do Cloud Storage que o vídeo de origem.
Limpar
Para evitar incorrer em custos na sua conta do Google Cloud pelos recursos usados neste tutorial, elimine o projeto que contém os recursos ou mantenha o projeto e elimine os recursos individuais.