none
I have a FaceAttributes array of null.

    Question

  • Method from msdn

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

    My method

            async partial void StartButton (Foundation.NSObject sender)
            {
                string endDir = EndFolderLabel.StringValue;
                Directory.CreateDirectory(endDir + "/Men/");
                Directory.CreateDirectory(endDir + "/Women/");
                Directory.CreateDirectory(endDir + "/Couple/");
                Directory.CreateDirectory(endDir + "/Not a human/");
    
                string[] fileNames = Directory.GetFiles(PicsFolderLabel.StringValue, "*?.jpg");
    
                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]);
    
                    if (faceAttributes.Length != 0)
                    {
                        if(faceAttributes.Length > 1)
                        {
                            File.Move(fileNames[i], endDir + "/Couple/" + fileNames[0].Substring(fileNames[0].LastIndexOf('/') + 1));
                        }
                        else
                        {
                            if(faceAttributes[0]?.Gender == "male")
                            {
                                File.Move(fileNames[i], endDir + "/Men/" + fileNames[0].Substring(fileNames[0].LastIndexOf('/') + 1));
                            }
                            else if (faceAttributes[0]?.Gender == "female")
                            {
                                File.Move(fileNames[i], endDir + "/Women/" + fileNames[0].Substring(fileNames[0].LastIndexOf('/') + 1));
                            }
                        }
                    }
                    else
                    {
                        File.Move(fileNames[i], endDir + "/Not a human/" + fileNames[0].Substring(fileNames[0].LastIndexOf('/') + 1));
                    }
                    Thread.Sleep(3000);
                }
                StatusLabel.StringValue = "Готово";
    
            }

    My code works only with no faces photos and multi faces photo. What i doing wrong?

    Thursday, May 19, 2016 8:48 PM

All replies