问题描述
我正在尝试使用 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,data=imgnew)
faceId_dest = detected_faces_dest.json()[0]['faceId']
`face_client_verify.face.verify_face_to_face(faceId_source,faceId_dest)`
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)