Microsoft Project Oxford (Face API) - Add a Person Face

0

I am new to C # and also on this site. I am testing the Microsoft API called Face API , however, I can not do the following program in C #, which is in the following web page .

I created the group, and I have also created three people, and the next step is Add a Person Face , could you please help me with an example of the method.

This is the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http.Headers;
using System.Net.Http;
using System.Web;
using Microsoft.ProjectOxford.Face;
using Microsoft.ProjectOxford.Face.Contract;
using System.IO;

namespace Add_person_face
{
    class Program
    {
        static void Main(string[] args)
        {
            MakeRequest();
            Console.WriteLine("Presione enter para salir una vez reciba una respuesta...");
            Console.ReadLine();
        }
        static async void MakeRequest()
        {
            var client = new HttpClient();
            var personGroupId = "equipocinco-si";
            string personId = "b2d1bdbb-71b5-4ef5-bf4b-44eaed66effd";
            string persona = "PersonaPrueba";

            // Request headers
            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "14ddaee113114f23bf3b541480107a3c");

            Stream s = File.OpenRead(@"C:\Users\S\Desktop\prueba.jpg");
            string json = "{\"url\":\"" + s + "}";
            var uri = "https://westus.api.cognitive.microsoft.com/face/v1.0/persongroups/" + personGroupId + "/persons/" + personId + "/persistedFaces?" + json;

            // Request body

            // Request parameters

            // Request body

            //string persistedFaceId = "";
            //string json2 = "{\"persistedFaceId\":\"}";

            HttpContent content = new StringContent(json);
            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            HttpResponseMessage response = await client.PostAsync(uri, content);
        }
    }
}
    
asked by Sca 03.04.2017 в 20:54
source

1 answer

0

If you are programming from c # use the libraries that it provides

Getting Started with Face API in C # Tutorial

As you will see from nuget, you add the reference to Microsoft.ProjectOxford.Face to use the method

    using (Stream imageFileStream = File.OpenRead(imageFilePath))
    {
        var faces = await faceServiceClient.DetectAsync(imageFileStream);
        var faceRects = faces.Select(face => face.FaceRectangle);
        return faceRects.ToArray();
    }

implement the exercise of the article and see how it works

    
answered by 03.04.2017 в 21:31