如何 运行 对存储在 Azure blob 中的图像进行 faceapi 查询?

how to run a faceapi query on images stored in Azure blobs?

我在 Azure 容器中有一些图像作为 blob,我想使用 faceapi 检测图像中是否有任何人脸,并在 python 中创建一个包含不同人物的人物组。我不想将图像下载到本地目录。使用以下代码,我能够 运行 从 blob 中读取图像,但 faceapi 不接受它作为输入。

from azure.storage.blob import BlobClient

blob = BlobClient(account_url="https://****.blob.core.windows.net/",
       container_name="demo",credential="**" )

data = blob.download_blob()

如果有办法可以做到这一点,请告诉我。

根据您提供的代码,当您创建 BlobClient 时,您没有提供 blobName。请将代码更新为 BlobClient(account_url="", container_name="", blob_name="", credential="account key")

例如

from azure.cognitiveservices.vision.face import FaceClient
from msrest.authentication import CognitiveServicesCredentials
from azure.cognitiveservices.vision.face.models import TrainingStatusType, Person
import os
import io
import json
import uuid
import time
import sys
from azure.storage.blob import BlobClient
account_key = ''
blob = BlobClient(account_url="https://*.blob.core.windows.net/",
                  container_name="image",
                  blob_name='my.jpg',
                  credential=account_key)
image = blob.download_blob()
endpoint = 'https://*.cognitiveservices.azure.com/'
key = ''
face_client = FaceClient(endpoint, CognitiveServicesCredentials(key))
PERSON_GROUP_ID = str(uuid.uuid4())
face_client.person_group.create(
    person_group_id=PERSON_GROUP_ID, name=PERSON_GROUP_ID)
woman = face_client.person_group_person.create(PERSON_GROUP_ID, "Woman")
face_client.person_group_person.add_face_from_stream(
    PERSON_GROUP_ID, woman.person_id, io.BytesIO(image.content_as_bytes(max_concurrency=3)))
face_client.person_group.train(PERSON_GROUP_ID)
while (True):
    training_status = face_client.person_group.get_training_status(
        PERSON_GROUP_ID)
    print("Training status: {}.".format(training_status.status))
    print()
    if (training_status.status is TrainingStatusType.succeeded):
        break
    elif (training_status.status is TrainingStatusType.failed):
        sys.exit('Training the person group has failed.')
    time.sleep(5)