【问题标题】:await faceClient.Face.DetectWithStreamAsync returning null等待 faceClient.Face.DetectWithStreamAsync 返回 null
【发布时间】:2020-02-15 13:37:21
【问题描述】:

我正在尝试运行 Microsoft 的“创建 WPF 应用程序以在图像中显示人脸数据”(https://docs.microsoft.com/en-us/azure/cognitive-services/face/tutorials/faceapiincsharptutorial),但我尝试使用图像检测人脸的所有操作都会返回 Null 错误(未找到人脸)。

我已经从 github 下载了 Windows 教程项目文件,并在此处尝试了一个简化版本:https://carldesouza.com/building-an-azure-cognitive-services-face-app-part-1-face-recognition/,每个都有相同的错误。我已经设法创建了一些 ASP.Net Web 应用程序,它们可以检测人脸,并使用相同的 API 密钥和端点创建人群来检测特定的人。

在这段代码中程序似乎无法检测到人脸:

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,因此没有检测到任何人脸。

【问题讨论】:

    标签: c# microsoft-cognitive azure-cognitive-services face-api


    【解决方案1】:

    试试下面的代码:

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

    结果:

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-22
      • 2020-04-01
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 2019-12-16
      • 2013-02-18
      • 2014-06-30
      相关资源
      最近更新 更多