【问题标题】:How can we show name with face id from azure face api?我们如何从 azure face api 显示带有人脸 ID 的姓名?
【发布时间】:2020-10-12 03:39:21
【问题描述】:

我有一个人组,其中存储了所有用户的 ID 和名称。我查看了有关 face api 的 azure 文档,但我没有得到任何根据 face id 显示名称的信息。不久之前,我曾经将名称和 ID 存储在与我用来显示名称的地方不同的 python 文件中。但后来我认为我们已经将名称和 ID 存储在 azure 中,为什么要创建另一个文件并将数据存储 2 次,而不是直接从 face api 显示名称。谁能指导我如何显示带有 id 的名称?

def face_identify(faceId):
    global person
    KEY = parser.get('AzCognitiveServices','Ocp-Apim-Subscription-Key')
 

    headers = {
        # Request headers
        'Content-Type': 'application/json',
        'Ocp-Apim-Subscription-Key': KEY,
    }

    params = urllib.urlencode({
    })


    if faceId is None:
        person = ""
        return

    group = parser.get('AzCognitiveServices','PersonGroupId')
    candidatesreturned = list(parser.get('AzCognitiveServices','maxNumOfCandidatesReturned'))
    threshold = parser.get('AzCognitiveServices','confidenceThreshold')

        
    body = "{'personGroupId' : '" + group + "','faceIds' : [%s],'maxNumOfCandidatesReturned' : 1,'confidenceThreshold': 0.5}" % str("'%s'"%faceId)
    logger.info(body)
    
    try:
        uri_base = parser.get('AzCognitiveServices','BaseURL')
        path_to_face_api = "/face/v1.0/identify"
        response = requests.post(uri_base + path_to_face_api,
                                 data=body,
                                 headers=headers,
                                 params=params,timeout=int(parser.get('AzCognitiveServices','Timeout')))
                       
        #response = conn.getresponse()
        data = response.json()
        logger.info('face id %s',data)
    
        candidates = data[0]["candidates"]
        
        if len(candidates) > 0:
            person = str(candidates[0]["personId"])
        else:
            person = ""

        print(person)
    except Exception as e:
        print("[Errno {0}] {1}".format(e.errno, e.strerror))

【问题讨论】:

    标签: azure microsoft-cognitive face-recognition azure-cognitive-services face-api


    【解决方案1】:

    如果您在创建这些项目时存储了人员的姓名,则只需在找到人员时通过 id 获取您的 PersonGroup。

    所以在你的代码中,就是在这一步:

    person = str(candidates[0]["personId"])
    

    这里有找到的人的 personId。将它与来自 PersonGroup Person 的 GET 方法一起使用,请参阅文档 here。它需要您的 PersonGroupId 和 PersonId。

    您将检索到您要查找的名称

    【讨论】:

      猜你喜欢
      • 2020-02-02
      • 1970-01-01
      • 2014-03-02
      • 2019-10-05
      • 1970-01-01
      • 2020-10-20
      • 1970-01-01
      • 2019-04-29
      • 2020-10-15
      相关资源
      最近更新 更多