Esempio n. 1
0
        private void Verify(Bitmap bitmap)
        {
            var features = _processor.LocateExtract(bitmap);

            //var features = _processor.LocateExtract(bitmap, LocateOperation.IncludeAge | LocateOperation.IncludeGender); //采用此方式抽取的特征,将包含性别和年龄信息
            if (features != null)
            {
                var names = MatchAll(features);
                var index = 0;

                using (var g = Graphics.FromImage(bitmap))
                {
                    foreach (var feature in features)
                    {
                        g.DrawRectangle(new Pen(Color.Crimson, 2), feature.FaceLoaction);
                        g.DrawString(names[index], new Font(new FontFamily("SimSun"), 12),
                                     new SolidBrush(Color.Crimson), feature.FaceLoaction.Right, feature.FaceLoaction.Bottom);

                        feature.Dispose(); //feature中的特征数据从托管内存复制到非托管,必须释放,否则内存泄露

                        index++;
                    }
                }
            }
        }
Esempio n. 2
0
        private static void TestMatching()
        {
            using (var proccesor = new FaceProcessor("appId",
                                                     "ftKey", "frKey", true))
            {
                var image1 = Image.FromFile("test2.jpg");
                var image2 = Image.FromFile("test.jpg");

                var result1 = proccesor.LocateExtract(new Bitmap(image1));
                var result2 = proccesor.LocateExtract(new Bitmap(image2));

                if ((result1 != null) & (result2 != null))
                {
                    Console.WriteLine(proccesor.Match(result1[0].FeatureData, result2[0].FeatureData, true));
                }
            }
        }
Esempio n. 3
0
        private void Verify(Bitmap bitmap)
        {
            //var features = _processor.LocateExtract(bitmap);
            var features = _processor.LocateExtract(bitmap, LocateOperation.IncludeAge | LocateOperation.IncludeGender); //采用此方式抽取的特征,将包含性别和年龄信息

            if (features != null)
            {
                var names = MatchAll(features);
                var index = 0;

                using (var g = Graphics.FromImage(bitmap))
                {
                    foreach (var feature in features)
                    {
                        g.DrawRectangle(new Pen(Color.Crimson, 2), feature.FaceLocation);
                        var sexText = "未知";
                        if (feature.Gender == 0)
                        {
                            sexText = "男";
                        }

                        if (feature.Gender == 1)
                        {
                            sexText = "女";
                        }

                        var text = $"姓名:{names[index]}  年龄:{feature.Age}  性别:{sexText}";
                        g.DrawString(text, new Font(new FontFamily("SimSun"), 16),
                                     new SolidBrush(Color.White), feature.FaceLocation.Left, feature.FaceLocation.Top);

                        feature.Dispose(); //feature中的特征数据从托管内存复制到非托管,必须释放,否则内存泄露

                        index++;
                    }
                }
            }
        }