首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >等待faceClient.Face.DetectWithStreamAsync返回null

等待faceClient.Face.DetectWithStreamAsync返回null
EN

Stack Overflow用户
提问于 2019-10-18 22:24:59
回答 1查看 839关注 0票数 1

我正在尝试运行微软的“创建一个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密钥和端点创建人员组来检测特定的人。

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

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-21 10:05:06

尝试下面的代码:

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

        }
    }

结果:

希望能有所帮助。

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

https://stackoverflow.com/questions/58452830

复制
相关文章

相似问题

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