我正在尝试运行微软的“创建一个WPF应用程序来在图像中显示人脸数据”(https://docs.microsoft.com/en-us/azure/cognitive-services/face/tutorials/faceapiincsharptutorial),但是我尝试使用图像来检测人脸时,它将返回一个空错误(No faces found)。
我已经从github下载了Windows教程项目文件,并在这里尝试了一个简化版本:https://carldesouza.com/building-an-azure-cognitive-services-face-app-part-1-face-recognition/,每个文件都有相同的错误。我已经成功地创建了一些API应用程序,它们可以检测人脸,还可以使用相同的ASP.Net密钥和端点创建人员组来检测特定的人。
在这段代码中,程序似乎无法检测到人脸:
IList<DetectedFace> faceList =
await faceClient.Face.DetectWithStreamAsync(
imageFileStream, true, false, null);
[AsyncStateMachine(typeof(<DetectWithStreamAsync>d__6))]
public static Task<IList<DetectedFace>> DetectWithStreamAsync(this IFaceOperations operations, Stream image, bool? returnFaceId = true, bool? returnFaceLandmarks = false, IList<FaceAttributeType> returnFaceAttributes = null, CancellationToken cancellationToken = default);
我从调试中得到的唯一错误是,这段代码总是返回null,因此没有检测到任何face。
发布于 2019-10-21 10:05:06
尝试下面的代码:
static void Main(string[] args)
{
string persionPicPath = @"<image path>";
string endpoint = @"https://<your face service name>.cognitiveservices.azure.com/";
string subscriptionKey = "<your subscription key>";
IFaceClient faceClient = new FaceClient(
new ApiKeyServiceClientCredentials(subscriptionKey),
new System.Net.Http.DelegatingHandler[] { });
faceClient.Endpoint = endpoint;
using (Stream s = File.OpenRead(persionPicPath))
{
var facesResults = faceClient.Face.DetectWithStreamAsync(s, true, false, null).GetAwaiter().GetResult();
foreach (var faces in facesResults)
{
Console.WriteLine(faces.FaceId);
}
Console.ReadKey();
}
}
结果:
希望能有所帮助。
https://stackoverflow.com/questions/58452830
复制相似问题