关于在 C# 项目中使用 Face API

About using Face API in C# project

我使用了 github 中的这个项目: https://github.com/jernejk/RealTimeFaceApi , 但结果总是显示 "Getting identity failed."

我的密钥和终结点是正确的,但我不确定 "FaceGroupId" 的值是否表示 persongroupId?(我在这里使用 personGroupId。)

我想知道前面的步骤是否有错误?

以下代码显示需要用户更改的 3 个地方:

public static class Program
    {
        // TODO: Add Face API subscription key.
        private static string FaceSubscriptionKey = "myFaceAPIkey";

        // TODO: Add face group ID.
        private static string FaceGroupId = "XXX";//I use persongroupId here.

        private static readonly Scalar _faceColorBrush = new Scalar(0, 0, 255);
        private static FaceClient _faceClient;
        private static Task _faceRecognitionTask = null;

        public static void Main(string[] args)
        {
            _faceClient = new FaceClient(new ApiKeyServiceClientCredentials(FaceSubscriptionKey))
            {
                Endpoint = "https://myendpoint.cognitiveservices.azure.com/face/v1.0"
            };

            string filename = args.FirstOrDefault();
            Run(filename);
        }

我运行那个项目在我这边成功了。是的,FaceGroupId应该是你在faceAPI服务中创建的persongroupId。出现错误的原因:Getting identity failed._faceClient 中的 Endpoint 值有问题,这里的值应该是:

https://<yourEndpoint>.cognitiveservices.azure.com

会好的。如果您使用识别模型 02 创建和训练您的人员组,您应该知道一件事,请将 Program.cs 中的代码修改为:

var detectedFaces = await _faceClient.Face.DetectWithStreamAsync(stream, true, true);

至:

var detectedFaces = await _faceClient.Face.DetectWithStreamAsync(stream,true,true,null, "recognition_02");

如果你用的是识别模型01,就不用改了(我这边用的是02模型)

此处代码的结果:

希望对您有所帮助。