我正在通过它的 API 使用 MS 认知服务来分析图像,并注意到当图像处于横向模式(“面部未垂直对齐”)时,它返回一个空结果。我很困惑,想知道是我做错了什么,还是 MS 服务的工作方式。这是一个重现问题的简单示例。
您应该拥有 MS Face 订阅密钥才能使用该服务!
import requests
# If you are using a Jupyter notebook, uncomment the following line.
#%matplotlib inline
import matplotlib.pyplot as plt
from PIL import Image
from matplotlib import patches
from io import BytesIO
# send request to MS, use YOUR subscription key
subscription_key = "982374kwhXXXxxxx"
assert subscription_key
face_api_url ='https://westus.api.cognitive.microsoft.com/face/v1.0/detect'
header = {'Ocp-Apim-Subscription-Key': face_api_url }
headers = {'Ocp-Apim-Subscription-Key': subscription_key, "Content-Type": "application/octet-stream" }
params = {
'returnFaceId': 'true',
'returnFaceLandmarks': 'false',
'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses,' +
'emotion,hair,makeup,occlusion,accessories,blur,exposure,noise'
}
# get a random image and convert to numpy array
image_url = 'https://how-old.net/Images/faces2/main007.jpg'
image = Image.open(BytesIO(requests.get(image_url).content))
image_np = np.array(image)
这是图像:
牧羊人nacy
相关分类