C# 等待faceClient.Face.DetectWithStreamAsync返回null

C# 等待faceClient.Face.DetectWithStreamAsync返回null,c#,microsoft-cognitive,azure-cognitive-services,face-api,C#,Microsoft Cognitive,Azure Cognitive Services,Face Api,我正在尝试运行Microsoft的“创建WPF应用程序以在图像中显示人脸数据”(Create a WPF app to display face data in a image)”(),但我尝试使用图像检测人脸的所有操作都将返回空错误(找不到人脸) 我从github下载了Windows教程项目文件,并在此处尝试了简化版本:,每个版本都有相同的错误。我已经成功地创建了一些ASP.NETWeb应用程序,这些应用程序可以检测人脸,还可以使用相同的API键和端点创建人员组来检测特定的人员 该程序似乎无法

我正在尝试运行Microsoft的“创建WPF应用程序以在图像中显示人脸数据”(Create a WPF app to display face data in a image)”(),但我尝试使用图像检测人脸的所有操作都将返回空错误(找不到人脸)

我从github下载了Windows教程项目文件,并在此处尝试了简化版本:,每个版本都有相同的错误。我已经成功地创建了一些ASP.NETWeb应用程序,这些应用程序可以检测人脸,还可以使用相同的API键和端点创建人员组来检测特定的人员

该程序似乎无法在此代码位检测人脸:

IList人脸列表=
等待faceClient.Face.DetectWithStreamAsync(
imageFileStream,true、false、null);
[AsyncStateMachine(typeof(d_uu6))]
公共静态任务DetectWithStreamAsync(此IFACEOOperations操作,流映像,bool?returnFaceId=true,bool?returnFaceLandmarks=false,IList returnFaceAttributes=null,CancellationToken CancellationToken=default);
我从调试中得到的唯一错误是,这段代码总是返回null,因此无法检测到任何面。

请尝试下面的代码:

    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();

        }
    }
static void Main(字符串[]args)
{
字符串personPicPath=@“”;
字符串端点=@“https://.cognitiveservices.azure.com/";
字符串subscriptionKey=“”;
IFaceClient faceClient=新faceClient(
新的ApiKeyServiceClientCredentials(subscriptionKey),
新系统.Net.Http.DelegatingHandler[]{});
faceClient.Endpoint=Endpoint;
使用(streams=File.OpenRead(personpicpath))
{
var facesResults=faceClient.Face.DetectWithStreamAsync(s,true,false,null).GetAwaiter().GetResult();
foreach(facesResults中的变量面)
{
Console.WriteLine(faces.FaceId);
}
Console.ReadKey();
}
}
结果:

希望能有帮助