Example #1
0
 private static void TestFaceCompare2()
 {
     var faceA  = new Bitmap(@"d:\face.jpg");
     var faceB  = new Bitmap(@"d:\face2.jpg");
     var faceC  = new Bitmap(@"d:\face3.jpg");
     var faceR1 = new Bitmap(@"d:\faceR1a.jpg");
     var faceR2 = new Bitmap(@"d:\faceR2b.jpg");
     var tm     = new Accord.Imaging.ExhaustiveTemplateMatching(0);
     var m1     = tm.ProcessImage(faceA, faceB).Max(x => x.Similarity);
     var m2     = tm.ProcessImage(faceA, faceC).Max(x => x.Similarity);
     var m3     = tm.ProcessImage(faceR1, faceR2).Max(x => x.Similarity);
 }
Example #2
0
        public static List <Point> TemplateMatch(Bitmap bitmap, float Similarity = 0.99f)
        {
            Bitmap BigImage = ImageUtils.ConvertPixelFormat(bitmap, PixelFormat.Format24bppRgb);

            // Lock image bytes (Speed up)
            BitmapData data = BigImage.LockBits(new Rectangle(0, 0, BigImage.Width, BigImage.Height), ImageLockMode.ReadOnly, BigImage.PixelFormat);

            // create template matching algorithm's instance
            Accord.Imaging.ExhaustiveTemplateMatching tm = new Accord.Imaging.ExhaustiveTemplateMatching(Similarity);

            // find all matchings with specified above similarity
            Accord.Imaging.TemplateMatch[] matchings = tm.ProcessImage(BigImage, GetBitmap());

            List <Point> Result = matchings.ToList().Select(s => s.Rectangle.Location).ToList();

            // Unlock image bytes
            BigImage.UnlockBits(data);

            return(Result);
        }
Example #3
0
        private async static void TestFaceCompare()
        {
            var facesA = (App.Core.PeopleM.All.Single(x => x.Id == 479)).Segments.ToArray();
            var facesB = App.Core.SegmentsM.All.Where(x => x.PersonId == -44).ToArray();
            var tm     = new Accord.Imaging.ExhaustiveTemplateMatching(0);

            foreach (var face in facesA)
            {
                face.Similar?.Clear();
                face.SimMax = 0;
            }

            foreach (var faceA in facesA)
            {
                await faceA.SetPictureAsync(100);

                await faceA.SetComparePictureAsync(32);

                faceA.Similar ??= new();

                foreach (var faceB in facesB)
                {
                    await faceB.SetPictureAsync(100);

                    await faceB.SetComparePictureAsync(32);

                    var matchings = tm.ProcessImage(faceB.ComparePicture, faceA.ComparePicture);
                    var sim       = Math.Round(matchings.Max(x => x.Similarity) * 100, 1);
                    if (sim < 80)
                    {
                        continue;
                    }

                    faceA.Similar.Add(faceB, sim);
                    if (faceA.SimMax < sim)
                    {
                        faceA.SimMax = sim;
                    }
                }
            }
        }