S
S
Sasha Pleshakov2016-05-20 19:06:28
API
Sasha Pleshakov, 2016-05-20 19:06:28

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];
            }
        }

Call:
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);
            }

f9245fa1a8824fe690bb1ce4a00fb22a.png
Image example:
cbd7d9941bc046449cf2ce019b0c2885.jpg
Everything is ok on the site, but the property still returns null.
a54427510cfc43a69ec98d0017c61d7f.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
#
#algooptimize #bottize, 2016-05-20
@mnepoh

If the face is not found, what is returned?
(there is an overload where you can specify the necessary attributes)
c641c353f951400c92b6d8d70c258b25.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question