private void Findface(Bitmap bitmap)
        {
            var img = 0;

            var image = bitmap;

            image.Save("test.png");
            FSDK.LoadImageFromFile(ref img, "test.png");

            Face.Source = new BitmapImage(new Uri("test.png", UriKind.Relative));

            FSDK.TPoint[] array;
            FSDK.DetectFacialFeatures(img, out array);
            if (array != null)
            {
                Face.Source = DrawPoints(image, array);
            }


            FSDK.TFacePosition[] faces;
            int faceCount = 0;

            FSDK.DetectMultipleFaces(img, ref faceCount, out faces, 10000);


            if (faces != null)
            {
                foreach (var f in faces)
                {
                    Face.Source = DrawCircle(image, f.xc, f.yc, f.w);
                }
            }
        }
Beispiel #2
0
 public void DetectFeatures()
 {
     if (FacePosition == null)
     {
         FSDK.DetectFacialFeatures(ImageHandle, out Features);
     }
     else
     {
         FSDK.DetectFacialFeaturesInRegion(ImageHandle, ref FacePosition, out Features);
     }
 }
        public static Face FacePreparation(String picDir, String _name, String _folderName, int _index, Face twarz, int _folderIndex)
        {
            int Image = 0;

            if (FSDK.LoadImageFromFile(ref Image, picDir) != FSDK.FSDKE_OK)
            {
                Console.WriteLine("addSingleFace error ! ###############################################");
            }
            FSDK.TFacePosition FacePosition = new FSDK.TFacePosition();

            if (FSDK.DetectFace(Image, ref FacePosition) != FSDK.FSDKE_OK)
            {
                Console.WriteLine("addSingleFace error ! ###############################################");
            }

            FSDK.TPoint[] FacialFeatures;

            if (FSDK.DetectFacialFeatures(Image, out FacialFeatures) == FSDK.FSDKE_OK)
            {
                twarz.name       = _name;
                twarz.folderName = _folderName;
                Console.WriteLine(twarz.name);
                twarz.index        = _index;
                twarz.networkIndex = _folderIndex;
                List <float> faceFeatures = FeatureConverter.GetFeatures(FacialFeatures);
                twarz.features = faceFeatures;

                if (twarz.ValidateFace() == 1)
                {
                    Console.WriteLine("Wygenerowano dane twarzy");
                }
                else
                {
                    Console.WriteLine("Blad twarzy " + twarz.name + " ###############################################");
                }
            }
            else
            {
                Console.WriteLine("addSingleFace error ! ###############################################");
            }
            return(twarz);
        }
Beispiel #4
0
        private void matchesFace()
        {
            if (dataGridView1.Rows.Count > 0)
            {
                this.dataGridView1.Invoke(new MethodInvoker(() =>
                                                            this.dataGridView1.Rows.Clear()));
                this.dataGridView1.Invoke(new MethodInvoker(() =>
                                                            this.dataGridView1.Refresh()));
            }

            for (int i = 0; i < SubjectList.Count; i++)
            {
                if (SubjectList.Count >= 1)
                {
                    FSDK.GetMatchingThresholdAtFAR(FARValue / 100, ref FaceDetectionThreshold);

                    TFaceRecord DbSubject    = SubjectList[i];
                    int         MatchedCount = 0;
                    int         FaceCount    = FaceSearchList.Count;
                    float[]     Similarities = new float[FaceCount];
                    float[]     Smile        = new float[FaceCount];
                    float[]     EyesOpen     = new float[FaceCount];
                    float[]     Male         = new float[FaceCount];
                    float[]     Female       = new float[FaceCount];

                    int[] Numbers = new int[FaceCount];

                    for (int k = 0; k < FaceSearchList.Count; k++)
                    {
                        float Similarity         = 0.0f;
                        float ConfidenceSmile    = 0.0f;
                        float ConfidenceEyesOpen = 0.0f;
                        float ConfidenceMale     = 0.0f;
                        float ConfidenceFemale   = 0.0f;

                        TFaceRecord SearchFace = FaceSearchList[k];
                        FSDK.MatchFaces(ref DbSubject.Template, ref SearchFace.Template, ref Similarity);

                        long          MaxSizeInBytes   = 100000;
                        string        ExpressionValues = "";
                        string        GenderValues     = "";
                        FSDK.CImage   CurrentImage     = SearchFace.image;
                        FSDK.TPoint[] Facefeatures     = null;

                        FSDK.DetectFacialFeatures(SearchFace.faceImage.ImageHandle, out Facefeatures);

                        if (Facefeatures != null)
                        {
                            FSDK.DetectFacialAttributeUsingFeatures(SearchFace.faceImage.ImageHandle, ref Facefeatures, "Expression", out ExpressionValues, MaxSizeInBytes);
                            FSDK.GetValueConfidence(ExpressionValues, "Smile", ref ConfidenceSmile);
                            FSDK.GetValueConfidence(ExpressionValues, "EyesOpen", ref ConfidenceEyesOpen);

                            FSDK.DetectFacialAttributeUsingFeatures(SearchFace.faceImage.ImageHandle, ref Facefeatures, "Gender", out GenderValues, MaxSizeInBytes);
                            FSDK.GetValueConfidence(GenderValues, "Male", ref ConfidenceMale);
                            FSDK.GetValueConfidence(GenderValues, "Female", ref ConfidenceFemale);

                            if (Similarity >= FaceDetectionThreshold)
                            {
                                Similarities[MatchedCount] = Similarity;
                                Smile[MatchedCount]        = ConfidenceSmile;
                                EyesOpen[MatchedCount]     = ConfidenceEyesOpen;
                                Male[MatchedCount]         = ConfidenceMale;
                                Female[MatchedCount]       = ConfidenceFemale;

                                Numbers[MatchedCount] = k;
                                ++MatchedCount;
                            }
                        }
                        else
                        {
                            if (Similarity >= FaceDetectionThreshold)
                            {
                                Similarities[MatchedCount] = Similarity;
                                Smile[MatchedCount]        = 0;
                                EyesOpen[MatchedCount]     = 0;
                                Male[MatchedCount]         = 0;
                                Female[MatchedCount]       = 0;

                                Numbers[MatchedCount] = k;
                                ++MatchedCount;
                            }
                        }
                    }

                    if (MatchedCount == 0)
                    {
                        MessageBox.Show("No matches found. You can try to increase the FAR parameter in the Options dialog box.", "No matches");
                    }
                    else
                    {
                        for (int j = 0; j < MatchedCount; j++)
                        {
                            if ((Similarities[j] * 100.0f) >= 30.0f)
                            {
                                resultImagelist.Images.Add(FaceSearchList[j].faceImage.ToCLRImage());

                                Image img1 = FaceSearchList[Numbers[j]].faceImage.ToCLRImage();
                                img1 = (Image)(new Bitmap(img1, new Size(100, 100)));

                                Image img2 = Image.FromFile(SubjectList[i].ImageFileName);
                                img2 = (Image)(new Bitmap(img2, new Size(100, 100)));

                                string feature = DbSubject.suspectName + " \r\n\nSimilarity = " + (Similarities[j] * 100).ToString() + " Smile:" + Smile[j] * 100 + " Eyes Open: " + EyesOpen[j] * 100
                                                 + " Male:" + Male[j] * 100 + " Female: " + Female[j] * 100;
                                Object[] row = new Object[] { img1, img2, feature };

                                this.dataGridView1.Invoke(new MethodInvoker(() =>
                                                                            this.dataGridView1.Rows.Add(row)));
                            }
                        }
                    }
                }
            }
        }