【问题标题】:Azure face verify resource not found未找到 Azure 人脸验证资源
【发布时间】:2021-05-18 17:05:46
【问题描述】:

我正在尝试使用 azure face api 来验证人脸,但下面的代码给了我一个 404 资源未找到错误。我究竟做错了什么?使用相同的订阅密钥和端点,我能够从 url 中检测到面部并进行匹配。但我的需要是从网络摄像头读取图像并将其与模板图像匹配。

from azure.cognitiveservices.vision.face import FaceClient
from msrest.authentication import CognitiveServicesCredentials

import cv2
import requests

# This key will serve all examples in this document.
KEY = "d06a1f0aae344d7cac11f78eef5abf37"

# This endpoint will be used in all examples in this quickstart.
ENDPOINT = "https://neurohome-facerecognition.cognitiveservices.azure.com/face/v1.0/detect/"
ENDPOINT_verify = "https://neurohome-facerecognition.cognitiveservices.azure.com/face/v1.0/verify"

# Create an authenticated FaceClient.
face_client = FaceClient(ENDPOINT, CognitiveServicesCredentials(KEY))
face_client_verify = FaceClient(ENDPOINT_verify, CognitiveServicesCredentials(KEY))

headers = {
    'Content-Type':'application/octet-stream',
    'Ocp-Apim-Subscription-Key':KEY}
headers_verify = {'Content-Type':'application/json',
                  'Ocp-Apim-Subscription-Key':KEY}

api_url = ENDPOINT

params = {
    'returnFaceLandmarks':True,
    'returnFaceAttributes':'emotion,age,gender' }

# Base url for the Verify and Facelist/Large Facelist operations
IMAGE_BASE_PATH = 'C:/FaceRecognition/template/'
# Create a list to hold the target photos of the same person
#target_image_file_names = ['Family1-Dad1.jpg', 'Family1-Dad2.jpg']
# The source photos contain this person
source_image_file_name = 'template_viswa.jpg'

local_image = cv2.imread(IMAGE_BASE_PATH + source_image_file_name)
img = cv2.imencode('.jpg', local_image)[1].tobytes()

# Detect face(s) from source image 1, returns a list[DetectedFaces]
# We use detection model 3 to get better performance.
#detected_faces = face_client.face.detect_with_stream(img)
detected_faces = requests.post(api_url,params=params,headers=headers,data=img)
faceId_source = detected_faces.json()[0]['faceId']
# Add the returned face's face ID
cap = cv2.VideoCapture(0)
while True:
    ret,frame = cap.read()
    imgnew = cv2.imencode('.jpg',frame)[1].tobytes()
    detected_faces_dest = requests.post(ENDPOINT,params = params,headers=headers,data=imgnew)
    faceId_dest = detected_faces_dest.json()[0]['faceId']
    `face_client_verify.face.verify_face_to_face(faceId_source, faceId_dest)`

【问题讨论】:

    标签: azure face-api


    【解决方案1】:

    如果您使用 Azure face SDK for python 来验证人脸,FaceClientENDPOINT_verify 应该是:

    https://neurohome-facerecognition.cognitiveservices.azure.com/

    而不是https://neurohome-facerecognition.cognitiveservices.azure.com/face/v1.0/verify

    只需尝试以下代码创建人脸客户端进行验证:

    face_client_verify = FaceClient('https://neurohome-facerecognition.cognitiveservices.azure.com/', CognitiveServicesCredentials(KEY))
    

    尝试代码打击以进行快速测试:

    from azure.cognitiveservices.vision.face import FaceClient
    from msrest.authentication import CognitiveServicesCredentials
    
    
    ENDPOINT = "https://neurohome-facerecognition.cognitiveservices.azure.com/"
    Key = "<your key here>"
    
    face_client = FaceClient(ENDPOINT, CognitiveServicesCredentials(Key))
    face1 = face_client.face.detect_with_url("https://ichef.bbci.co.uk/news/976/cpsprodpb/7A8E/production/_118547313_gettyimages-1174968719.jpg")[0].face_id
    face2= face_client.face.detect_with_url("https://images.moneycontrol.com/static-mcnews/2018/05/Bill-gates-770x433.jpg")[0].face_id
    
    result = face_client.face.verify_face_to_face(face1,face2)
    print(result.is_identical)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-16
      • 1970-01-01
      • 2016-11-26
      • 2023-04-06
      • 1970-01-01
      • 2020-03-18
      • 1970-01-01
      相关资源
      最近更新 更多