This tutorial shows you how to use the Python SDK to blur faces in video. The example blurs video files from a Cloud Storage bucket and generates blurred video outputs. These output videos are stored to the same Cloud Storage bucket as the source videos.
Add input files to Cloud Storage
Before you can send a request using the Python SDK, create a Cloud Storage bucket and upload a local video to use as input.
Create a Cloud Storage bucket:
gcloud storage buckets create gs://BUCKET_NAME
Upload a local video file to the new bucket:
gcloud storage cp LOCAL_FILE gs://BUCKET_NAME
Install dependencies and send the request
After you create your Cloud Storage bucket for input and output videos and add a local video, install the necessary dependencies and send your request.
Optional. Set up your virtual environment:
If not installed, install
virtualenv
:sudo apt-get install python3-venv
Create a new virtual environment:
python3 -m venv vaivenv
Activate your virtual environment:
source vaivenv/bin/activate
Install dependencies:
pip3 install visionai-0.0.5-py3-none-any.whl pip3 install google-cloud-storage
Send your request with the Python SDK.
Make the following variable substitutions:
- PROJECT_ID: Your Google Cloud project ID.
- LOCATION_ID: Your location ID. For example,
us-central1
. More information. Supported regions. - BUCKET_NAME: The Cloud Storage bucket you created.
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
You should see output similar to the following:
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! ```
Examine output
After your video has finished processing you can examine the output in your Cloud Storage bucket. The generated blurred video files will be in the same Cloud Storage bucket as the source video.
List all objects in your bucket with the
gcloud storage ls
command:gcloud storage ls gs://bucket
You should see the source files and output files similar to the following:
test1.mp4 test2.mp4 test1_deid_output.mp4 test2_deid_output.mp4
Optional. Download the output files locally with the
gcloud storage cp
command and view the blurred videos:gcloud storage cp gs://BUCKET_NAME/FILE_NAME .