首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Microsoft Azure认知服务-面部检测失败在景观(脸)模式

问Microsoft Azure认知服务-面部检测失败在景观(脸)模式
EN

Stack Overflow用户
提问于 2018-10-22 16:29:26
回答 1查看 3.9K关注 0票数 0

我正在通过it API使用MS认知服务来分析图像,并注意到当图像处于景观模式(“脸不是垂直对齐的”)时,它返回一个空的结果。我很困惑,我想知道我是否做错了什么,或者这就是MS服务的工作方式。这里有一个简单的例子来重现这个问题。

您应该拥有MS Face订阅密钥才能使用服务!

代码语言:javascript
复制
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)

这是一张图片:

​

​

然后进行MS人脸识别分析:

代码语言:javascript
复制
    # save image into a buffer
    buf = io.BytesIO()
    plt.imsave(buf, image_np, format='jpg')


    response = requests.post(face_api_url, params=params, headers=headers, data=buf.getvalue())
    faces = response.json()
    print(faces)

具有正确的输出:

代码语言:javascript
复制
[{'faceId': '56afb612-f737-44da-8b62-511070527e18',   'faceRectangle': {'top': 209, 'left': 229, 'width': 91, 'height': 91},   'faceAttributes': {'smile': 1.0,    'headPose': {'pitch': 0.0, 'roll':
3.7, 'yaw': 1.2},    'gender': 'female',    'age': 29.0,    'facialHair': {'moustache': 0.0, 'beard': 0.0, 'sideburns': 0.0},    'glasses': 'NoGlasses',    'emotion': {'anger': 0.0,
    'contempt': 0.0,
    'disgust': 0.0,
    'fear': 0.0,
    'happiness': 1.0,
    'neutral': 0.0,
    'sadness': 0.0,
    'surprise': 0.0},    'blur': {'blurLevel': 'low', 'value': 0.02},    'exposure': {'exposureLevel': 'goodExposure', 'value': 0.65},    'noise': {'noiseLevel': 'medium', 'value': 0.31},    'makeup': {'eyeMakeup': True, 'lipMakeup': True},    'accessories': [],    'occlusion': {'foreheadOccluded': False,
    'eyeOccluded': False,
    'mouthOccluded': False},    'hair': {'bald': 0.05,
    'invisible': False,
    'hairColor': [{'color': 'brown', 'confidence': 1.0},
     {'color': 'blond', 'confidence': 0.48},
     {'color': 'black', 'confidence': 0.35},
     {'color': 'red', 'confidence': 0.27},
     {'color': 'gray', 'confidence': 0.19},
     {'color': 'other', 'confidence': 0.03}]}}},  {'faceId': 'dfb667ba-3fe7-42fc-b9ba-06a86619e94d',   'faceRectangle': {'top': 110, 'left': 125, 'width': 76, 'height': 76},   'faceAttributes': {'smile': 1.0,    'headPose': {'pitch': 0.0, 'roll': 2.3, 'yaw': 2.2}, 'gender': 'male',    'age': 32.0,    'facialHair': {'moustache': 0.4, 'beard': 0.4, 'sideburns': 0.1},    'glasses': 'NoGlasses',    'emotion': {'anger': 0.0,
    'contempt': 0.0,
    'disgust': 0.0,
    'fear': 0.0,
    'happiness': 1.0,
    'neutral': 0.0,
    'sadness': 0.0,
    'surprise': 0.0},    'blur': {'blurLevel': 'low', 'value': 0.02},    'exposure': {'exposureLevel': 'goodExposure', 'value': 0.72},    'noise': {'noiseLevel': 'low', 'value': 0.01},    'makeup': {'eyeMakeup': False, 'lipMakeup': True},    'accessories': [],    'occlusion': {'foreheadOccluded': False,
    'eyeOccluded': False,
    'mouthOccluded': False},    'hair': {'bald': 0.02,
    'invisible': False,
    'hairColor': [{'color': 'brown', 'confidence': 1.0},
     {'color': 'blond', 'confidence': 0.92},
     {'color': 'red', 'confidence': 0.66},
     {'color': 'gray', 'confidence': 0.25},
     {'color': 'other', 'confidence': 0.02},
     {'color': 'black', 'confidence': 0.01}]}}}]

然而,如果我交换轴(转置图像),我得到一个零的结果(‘空’)

代码语言:javascript
复制
# save image into a buffer
buf = io.BytesIO()
plt.imsave(buf, np.swapaxes(image_np, 0,1), format='jpg')

​

​

代码语言:javascript
复制
response = requests.post(face_api_url, params=params, headers=headers, data=buf.getvalue())
faces = response.json()
print(faces)

结果将是一个空列表:

代码语言:javascript
复制
[]

我想知道是否有人解决了这个问题,以及如何使MS服务正常工作,而不管图像的旋转或位置如何。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-23 14:11:13

它实际上声明这里,有些情况下人脸可能无法被检测,包括错误的图像方向。

人脸检测器倾向于正面和近正面的人脸.有些情况下,人脸可能无法被检测到,例如非常大的人脸角度(头部姿态)或被遮挡,或图像方向错误。

你可以通过检测脸部的方向来处理这一点,然后根据这个方向旋转图片,然后发送出去!

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52933853

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档