Search code examples
c#azure-cognitive-servicesface-api

await client.Face.DetectWithStreamAsync not responding


I want to perform face recognition in Unity using Microsoft.Azure.CognitiveServices.Vision.Face for the Hololens 2.

I basically followed this Face Client Tutorial and tried using await faceClient.Face.DetectWithUrlAsync as well as await faceClient.Face.DetectWithStreamAsync with local images, but the program does not get past this line of code (no response at all, Unity also shows no response). However, when investigating the azure resources metrics, it shows successful calls and output data. The only output I get in Visual Studio is "Loaded: Modul: Anonymously Hosted DynamicMethods Assembly".

This is the problematic code snippet:

using (Stream faceimagestream = File.OpenRead(filepath))
        {
            detectedFaces = await client.Face.DetectWithStreamAsync(faceimagestream, returnFaceAttributes: features);
        }

Solution

  • The solution was to use await according to the Task-based Asynchronous Pattern (TAP) instead of method.Wait(), which was used in the tutorial's example (which was obviously not built for Unity). The Wait() call blocks the whole thread, therefore Unity does not respond.