我正在尝试使用Microsoft Azure认知服务面部检测。我做错了。我正在尝试使用C#SDK进行面部检测。我收到下面的错误。我不知道该如何调试此错误消息或告诉我什么。几乎就像我设置的东西一样,但我只是在猜测。
Microsoft.Azure.CognitiveServices.Vision.Face.Models.APIErrorException
HResult=0x80131500
Message=Operation returned an invalid status code 'BadRequest'
Source=Microsoft.Azure.CognitiveServices.Vision.Face
StackTrace:
at Microsoft.Azure.CognitiveServices.Vision.Face.FaceOperations.<DetectWithUrlWithHttpMessagesAsync>d__9.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Microsoft.Azure.CognitiveServices.Vision.Face.FaceOperationsExtensions.<DetectWithUrlAsync>d__4.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at BWD.ASPNET.Core.Services.FaceDetection.<DoWork>d__5.MoveNext() in
我拨打电话的代码是:
string faceEndpoint = "https://eastus.api.cognitive.microsoft.com";
FaceAttributeType[] faceAttributes =
{ FaceAttributeType.Age, FaceAttributeType.Gender, FaceAttributeType.Hair,
FaceAttributeType.Smile, FaceAttributeType.Gender, FaceAttributeType.Emotion, FaceAttributeType.FacialHair,
FaceAttributeType.Accessories };
FaceClient faceClient = new FaceClient( new ApiKeyServiceClientCredentials(connString), new System.Net.Http.DelegatingHandler[] { });
faceClient.Endpoint = faceEndpoint;
var ctx = new BWDContext();
var pics = await (from p in ctx.Picture where p.DateOfFacial == null select p).ToListAsync();
foreach(var pic in pics)
{
if(Uri.IsWellFormedUriString(pic.PicFileUrl, UriKind.Absolute))
{
IList<DetectedFace> faceList =
await faceClient.Face.DetectWithUrlAsync(pic.PicFileUrl, true, true, faceAttributes); // error occurs here
.....on and on .......
我还尝试了与提琴手打个电话,这确实有效。在提琴手的电话上,我只是在以下网址上发布了一个帖子:https://eastus.api.cognitive.microsoft.com/face/v1.0/detect?returnFaceId=true&returnFaceLandmarks=false&returnFaceAttributes=age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise
我的标题是:
User-Agent: Fiddler
Ocp-Apim-Subscription-Key: ....subscription key......
Content-Type: application/json
Host: eastus.api.cognitive.microsoft.com
Content-Length: 107
我的帖子正文为: {'url':'https://bwdpictures.blob.core.windows.net/bwdpictures/d916acdd-ab9f-429e-8b75-6d5f9206a9b4.jpg'}
我从提琴手的其余电话中得到了结果。
我确定问题出在我的代码中,但我不知道问题是什么。如果您有任何建议,我将不胜感激。
TIA, 沃利
答案 0 :(得分:0)
宾果。问题是我在face属性中两次拥有了Gender属性。我只是注意到了。当我拿出第二个时,问题解决了。抱歉,该帖子。