get faces from video file using API in Azure Video Indexer

95 Views Asked by At

how to get faces pictures using API from indexed file? I see only face detected green border, but want to extract face' pictures

1

There are 1 best solutions below

0
Rishabh Meshram On

Based on the documentation, to extract face pictures, you'll need to use the face thumbnails provided in the Video Indexer output.

To download the face thumbnails, you can use the Insight URL with the following format:

https://api.videoindexer.ai/{location}/Accounts/{account_id}/Videos/{video_id}/Index?accessToken={access_token}&language=English
import  requests
insights_url  =  f"https://api.videoindexer.ai/{location}/Accounts/{account_id}/Videos/{video_id}/Index?accessToken={access_token}&language=English"
insights_response  =  requests.get(insights_url)
insights_data  =  insights_response.json()

Once you have the insights_response, you can extract the thumbnail_IDs to get the pictures.


from io import BytesIO
from PIL import Image

faces=insights_data['summarizedInsights']['faces']
for x,face in enumerate(faces):
    thumbnail_id=(face['thumbnailId'])
    artifact_url = f"https://api.videoindexer.ai/{location}/Accounts/{account_id}/Videos/{video_id}/Thumbnails/{thumbnail_id}?accessToken={access_token}"
    thumbnail_response = requests.get(artifact_url)
    image = Image.open(BytesIO(thumbnail_response.content))
    image.save(str(x)+'.jpg', 'JPEG')
    image.show()

With above steps and code snippet I was able to get required results.