Comprehensive Detailed Explanation
You’re adding multiple images for each person into a PersonGroup using the Face API SDK.
File.OpenRead(imagePath) returns a Stream, so the using declaration must declare Stream t = File.OpenRead(imagePath) .
To upload an image from a stream to a person in a person group, call
faceClient.PersonGroupPerson.AddFaceFromStreamAsync(personGroupId, personId, t);
Putting it together:
Parallel.For( 0 , PersonCount, async i = >
{
Guid personId = persons[i].PersonId;
string personImageDir = $ " /path/to/person/ {i} /images " ;
foreach ( string imagePath in Directory.GetFiles(personImageDir, " *.jpg " ))
{
using (Stream t = File.OpenRead(imagePath))
{
await faceClient.PersonGroupPerson.AddFaceFromStreamAsync(
personGroupId, personId, t);
}
}
});
This loops the images for each person, opens each as a stream, and adds the face to the specified person in the person group.
References
Microsoft Docs – Face API: Add a face to a person ( AddFaceFromStreamAsync , AddFaceFromUrlAsync ) in PersonGroupPerson operations.
https://learn.microsoft.com/azure/ai-services/face/ (see SDK/PersonGroupPerson methods)
NET File.OpenRead returns Stream .
https://learn.microsoft.com/dotnet/api/system.io.file.openread
Submit