Answer the question
In order to leave comments, you need to log in
Why does FaceAttributes.Gender return null?
I don't know, maybe someone dealt with microsoft face api. The problem is that the Gender property of the FaceAttributes class instance returns null, while the photo is recognized normally on the site.
Method:
private async Task<FaceAttributes[]> UploadAndDetectFaces(string imageFilePath)
{
try
{
using (Stream imageFileStream = File.OpenRead(imageFilePath))
{
var faces = await faceServiceClient.DetectAsync(imageFileStream);
var faceRects = faces.Select(face => face.FaceAttributes);
return faceRects.ToArray();
}
}
catch (Exception)
{
return new FaceAttributes[0];
}
}
FaceAttributes[] faceAttributes;
for (int i = 0; i < fileNames.Length; i++)
{
StatusLabel.StringValue = string.Format("{0} из {1} ({2})", i + 1, fileNames.Length, fileNames[i]);
faceAttributes = await UploadAndDetectFaces(fileNames[i]);
try{
if (faceAttributes.Length != 0)
{
if(faceAttributes.Length > 1)
{
File.Move(fileNames[i], endDir + "/Couple/" + fileNames[0].Substring(fileNames[0].LastIndexOf('/') + 1));
if(File.Exists(fileNames[i]))
File.Delete(fileNames[i]);
}
else
{
if(faceAttributes[0]?.Gender == "male")// Это условия пропускается из-за того, что Gender = null
{
File.Move(fileNames[i], endDir + "/Men/" + fileNames[0].Substring(fileNames[0].LastIndexOf('/') + 1));
if(File.Exists(fileNames[i]))
File.Delete(fileNames[i]);
}
else if (faceAttributes[0]?.Gender == "female")//Это условия пропускается из-за того, что Gender = null
{
File.Move(fileNames[i], endDir + "/Women/" + fileNames[0].Substring(fileNames[0].LastIndexOf('/') + 1));
if(File.Exists(fileNames[i]))
File.Delete(fileNames[i]);
}
}
}
else
{
File.Move(fileNames[i], endDir + "/Not a human/" + fileNames[0].Substring(fileNames[0].LastIndexOf('/') + 1));
if(File.Exists(fileNames[i]))
File.Delete(fileNames[i]);
}
}
catch(Exception ex)
{
StatusLabel.StringValue = ex.Message;
}
Thread.Sleep(3000);
}
Answer the question
In order to leave comments, you need to log in
If the face is not found, what is returned?
(there is an overload where you can specify the necessary attributes)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question