Quellcode durchsuchen

21.04.2023
Работа над отображением подписи над лицом и удалением пользователя из системы

Вячеслав Терешенко vor 2 Jahren
Ursprung
Commit
60dcfed981

+ 25 - 0
ImpulseVision/FormGuard.cs

@@ -21,6 +21,7 @@ using System.Threading.Tasks;
 using System.Windows.Forms;
 using Timer = System.Windows.Forms.Timer;
 using System.Runtime.CompilerServices;
+using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
 
 namespace ImpulseVision
 {
@@ -55,6 +56,9 @@ namespace ImpulseVision
 
         private EigenFaceRecognizer recognizer;
         private Timer CaptureTimer;
+
+        public string UserName { get; set; } = "FACE NOT EXISTS";
+
         #region FaceName
         private string faceName;
         public string FaceName
@@ -65,6 +69,7 @@ namespace ImpulseVision
                 faceName = value.ToUpper();
 
                 this.Text = faceName;
+                UserName = faceName;
                 //PbxFaces.Invoke(DispatcherPriority.Normal, new Action(() => { lblFaceName.Content = faceName; }));
                 NotifyPropertyChanged();
             }
@@ -101,6 +106,7 @@ namespace ImpulseVision
                 NotifyPropertyChanged();
             }
         }
+
         #endregion
 
 
@@ -153,6 +159,7 @@ namespace ImpulseVision
                 Directory.CreateDirectory(Config.FacePhotosPath);
             }
             //
+            /*
             if (!File.Exists(Config.FaceListTextFile))
             {
                 string text = "Не удается найти файл с данными о лице:\n\n";
@@ -169,6 +176,7 @@ namespace ImpulseVision
                         break;
                 }
             }
+            */
             //
             //получить из БД инфо о пользователе (id, имя, фамилия, путь до фото)
             SCon.Open();
@@ -231,6 +239,14 @@ namespace ImpulseVision
         {
             BgrFrame = Capture.QueryFrame().ToImage<Bgr, Byte>().Flip(FlipType.Horizontal);
 
+            Pen PenForFace = new Pen(Brushes.Red, 5);
+            Brush BrushForFace = Brushes.White;
+            Font MyFont = new Font("Segoe UI Variable Small Semibol; 14pt; style=Bold", 14, FontStyle.Regular);
+
+            Brush BrushInfo = Brushes.White;
+            Pen PenInfo = new Pen(Brushes.White, 4);
+
+
             if (BgrFrame != null)
             {
                 try
@@ -245,6 +261,15 @@ namespace ImpulseVision
                     {
                         BgrFrame.Draw(face, new Bgr(53, 23, 247), 2);
                         DetectedFace = BgrFrame.Copy(face).Convert<Gray, byte>();
+
+                        Point PointInfo = new Point(face.Width - face.Width, 0);
+                        Graphics GraphInfo = Graphics.FromImage(BgrFrame.ToBitmap());
+                        Graphics Graph = Graphics.FromImage(BgrFrame.ToBitmap());
+                        Graph.DrawRectangle(PenForFace, face.X, face.Y, face.Width, face.Height);
+                        //позиция отрисовки имени человека
+                        Point PointName = new Point(face.X, face.Y - 25);
+                        Graph.DrawString($"{UserName}", MyFont, BrushForFace, PointName);
+
                         FaceRecognition();
                         break;
                     }

+ 21 - 12
ImpulseVision/FormMain.cs

@@ -33,7 +33,7 @@ namespace ImpulseVision
         public event PropertyChangedEventHandler PropertyChanged;
         private VideoCapture Capture;
         private CascadeClassifier HaarCascade;
-        private Image<Bgr, Byte> bgrFrame = null;
+        private Image<Bgr, Byte> BgrFrame = null;
         private Image<Gray, Byte> DetectedFace = null;
         private List<FaceData> FaceList = new List<FaceData>();
         private VectorOfMat ImageList = new VectorOfMat();
@@ -43,6 +43,7 @@ namespace ImpulseVision
         private EigenFaceRecognizer recognizer;
         private Timer CaptureTimer;
         #region FaceName
+        private string UserName = string.Empty;
         private string faceName;
         public string FaceName
         {
@@ -51,7 +52,7 @@ namespace ImpulseVision
             {
                 faceName = value.ToUpper();
 
-                this.Text = faceName;
+                UserName = faceName;
                 //PbxFaces.Invoke(DispatcherPriority.Normal, new Action(() => { lblFaceName.Content = faceName; }));
                 NotifyPropertyChanged();
             }
@@ -150,13 +151,21 @@ namespace ImpulseVision
         /// </summary>
         private void ProcessFrame()
         {
-            bgrFrame = Capture.QueryFrame().ToImage<Bgr, Byte>().Flip(FlipType.Horizontal);
+            BgrFrame = Capture.QueryFrame().ToImage<Bgr, Byte>().Flip(FlipType.Horizontal);
 
-            if (bgrFrame != null)
+            Pen PenForFace = new Pen(Brushes.Red, 5);
+            Brush BrushForFace = Brushes.White;
+            Font MyFont = new Font("Segoe UI Variable Small Semibol; 14pt; style=Bold", 14, FontStyle.Regular);
+
+            Brush BrushInfo = Brushes.White;
+            Pen PenInfo = new Pen(Brushes.White, 4);
+
+
+            if (BgrFrame != null)
             {
                 try
                 {//for emgu cv bug
-                    Image<Gray, byte> grayframe = bgrFrame.Convert<Gray, byte>();
+                    Image<Gray, byte> grayframe = BgrFrame.Convert<Gray, byte>();
 
                     Rectangle[] Faces = HaarCascade.DetectMultiScale(grayframe, 1.2, 10, new System.Drawing.Size(50, 50), new System.Drawing.Size(200, 200));
 
@@ -164,12 +173,12 @@ namespace ImpulseVision
                     FaceName = "No face detected";
                     foreach (var face in Faces)
                     {
-                        bgrFrame.Draw(face, new Bgr(53, 23, 247), 2);
-                        DetectedFace = bgrFrame.Copy(face).Convert<Gray, byte>();
+                        BgrFrame.Draw(face, new Bgr(53, 23, 247), 2);
+                        DetectedFace = BgrFrame.Copy(face).Convert<Gray, byte>();
                         FaceRecognition();
                         break;
                     }
-                    CameraCapture = bgrFrame.ToBitmap();
+                    CameraCapture = BgrFrame.ToBitmap();
                 }
                 catch (Exception ex)
                 {
@@ -338,18 +347,18 @@ where ID = '{IdUser}'";
 
             SCon.Close();
 
-            string FolderNameForUser = string.Empty;
+            string PhotoName = string.Empty;
             for (int i = 0; i < LstUsers.Count; i++)
             {
                 if (LstUsers[i].UserID == IdUser)
                 {
-                    FolderNameForUser = LstUsers[i].FIO.Split(' ')[1] + LstUsers[i].PassportSeria + LstUsers[i].PassportNum;
+                    PhotoName = LstUsers[i].FIO.Split(' ')[1] + LstUsers[i].PassportSeria + LstUsers[i].PassportNum;
                 }
             }
             try
             {
                 //удалить из папки фотографию пользователя
-                File.Delete(Application.StartupPath + "\\TrainedImages\\" + $"{FolderNameForUser}.bmp");
+                File.Delete(Application.StartupPath + Config.FacePhotosPath + $"{PhotoName}.bmp");
             }
             catch
             {
@@ -626,7 +635,7 @@ where ID = '{IdUser}'";
 
             if (Capture != null)
             {
-                bgrFrame = null;
+                BgrFrame = null;
                 Capture.Stop();
                 Capture.Dispose();
                 Capture = null;

BIN
ImpulseVision/bin/Debug/ImpulseVision.exe


BIN
ImpulseVision/bin/Debug/Source/TrainedImages/Вячеслав8549854996.bmp


BIN
ImpulseVision/bin/Debug/Source/TrainedImages/Петр8932219679.bmp