Explorar o código

Добавление, Идентификация, Журнал

Вячеслав Терешенко %!s(int64=2) %!d(string=hai) anos
pai
achega
28dfdad3ab

+ 23 - 12
T FaceRecognizer/FormMain.Designer.cs

@@ -132,7 +132,7 @@
             // 
             // PanelMenu
             // 
-            this.PanelMenu.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(243)))), ((int)(((byte)(243)))), ((int)(((byte)(243)))));
+            this.PanelMenu.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(206)))), ((int)(((byte)(208)))), ((int)(((byte)(223)))));
             this.PanelMenu.Controls.Add(this.PanSettings);
             this.PanelMenu.Controls.Add(this.PanJournal);
             this.PanelMenu.Controls.Add(this.PanIdentification);
@@ -145,6 +145,7 @@
             this.PanelMenu.Name = "PanelMenu";
             this.PanelMenu.Size = new System.Drawing.Size(248, 389);
             this.PanelMenu.TabIndex = 3;
+            this.PanelMenu.Paint += new System.Windows.Forms.PaintEventHandler(this.PanelMenu_Paint);
             // 
             // PanSettings
             // 
@@ -162,7 +163,7 @@
             // 
             this.BtnSettings.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(58)))), ((int)(((byte)(166)))), ((int)(((byte)(64)))));
             this.BtnSettings.Dock = System.Windows.Forms.DockStyle.Fill;
-            this.BtnSettings.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
+            this.BtnSettings.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
             this.BtnSettings.ForeColor = System.Drawing.Color.White;
             this.BtnSettings.Location = new System.Drawing.Point(41, 0);
             this.BtnSettings.Name = "BtnSettings";
@@ -170,6 +171,7 @@
             this.BtnSettings.TabIndex = 1;
             this.BtnSettings.Text = "Настройки";
             this.BtnSettings.UseVisualStyleBackColor = false;
+            this.BtnSettings.Click += new System.EventHandler(this.BtnSettings_Click);
             // 
             // pictureBox4
             // 
@@ -181,6 +183,7 @@
             this.pictureBox4.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
             this.pictureBox4.TabIndex = 0;
             this.pictureBox4.TabStop = false;
+            this.pictureBox4.Click += new System.EventHandler(this.BtnSettings_Click);
             // 
             // PanJournal
             // 
@@ -198,7 +201,7 @@
             // 
             this.BtnJournal.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(58)))), ((int)(((byte)(166)))), ((int)(((byte)(64)))));
             this.BtnJournal.Dock = System.Windows.Forms.DockStyle.Fill;
-            this.BtnJournal.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
+            this.BtnJournal.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
             this.BtnJournal.ForeColor = System.Drawing.Color.White;
             this.BtnJournal.Location = new System.Drawing.Point(41, 0);
             this.BtnJournal.Name = "BtnJournal";
@@ -218,6 +221,7 @@
             this.pictureBox3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
             this.pictureBox3.TabIndex = 0;
             this.pictureBox3.TabStop = false;
+            this.pictureBox3.Click += new System.EventHandler(this.BtnJournal_Click);
             // 
             // PanIdentification
             // 
@@ -235,7 +239,7 @@
             // 
             this.BtnIdent.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(58)))), ((int)(((byte)(166)))), ((int)(((byte)(64)))));
             this.BtnIdent.Dock = System.Windows.Forms.DockStyle.Fill;
-            this.BtnIdent.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
+            this.BtnIdent.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
             this.BtnIdent.ForeColor = System.Drawing.Color.White;
             this.BtnIdent.Location = new System.Drawing.Point(41, 0);
             this.BtnIdent.Name = "BtnIdent";
@@ -255,6 +259,7 @@
             this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
             this.pictureBox2.TabIndex = 0;
             this.pictureBox2.TabStop = false;
+            this.pictureBox2.Click += new System.EventHandler(this.BtnIdent_Click);
             // 
             // PanAdd
             // 
@@ -272,7 +277,7 @@
             // 
             this.BtnAddUser.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(58)))), ((int)(((byte)(166)))), ((int)(((byte)(64)))));
             this.BtnAddUser.Dock = System.Windows.Forms.DockStyle.Fill;
-            this.BtnAddUser.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
+            this.BtnAddUser.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
             this.BtnAddUser.ForeColor = System.Drawing.Color.White;
             this.BtnAddUser.Location = new System.Drawing.Point(41, 0);
             this.BtnAddUser.Name = "BtnAddUser";
@@ -292,6 +297,7 @@
             this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
             this.pictureBox1.TabIndex = 0;
             this.pictureBox1.TabStop = false;
+            this.pictureBox1.Click += new System.EventHandler(this.BtnAddUser_Click);
             // 
             // PanHome
             // 
@@ -307,14 +313,16 @@
             // 
             // BtnMain
             // 
+            this.BtnMain.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
             this.BtnMain.Dock = System.Windows.Forms.DockStyle.Fill;
-            this.BtnMain.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
+            this.BtnMain.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
             this.BtnMain.ForeColor = System.Drawing.Color.White;
             this.BtnMain.Location = new System.Drawing.Point(41, 0);
             this.BtnMain.Name = "BtnMain";
             this.BtnMain.Size = new System.Drawing.Size(200, 35);
             this.BtnMain.TabIndex = 1;
             this.BtnMain.Text = "Главная";
+            this.BtnMain.TextImageRelation = System.Windows.Forms.TextImageRelation.TextBeforeImage;
             this.BtnMain.UseVisualStyleBackColor = true;
             this.BtnMain.Click += new System.EventHandler(this.BtnMain_Click);
             // 
@@ -328,13 +336,14 @@
             this.PbxLogoHome.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
             this.PbxLogoHome.TabIndex = 0;
             this.PbxLogoHome.TabStop = false;
+            this.PbxLogoHome.Click += new System.EventHandler(this.BtnMain_Click);
             // 
             // PbxMenu
             // 
             this.PbxMenu.Image = global::T_FaceRecognizer.Properties.Resources.menu_button_icon_icons_com_72989;
-            this.PbxMenu.Location = new System.Drawing.Point(4, 41);
+            this.PbxMenu.Location = new System.Drawing.Point(6, 46);
             this.PbxMenu.Name = "PbxMenu";
-            this.PbxMenu.Size = new System.Drawing.Size(40, 35);
+            this.PbxMenu.Size = new System.Drawing.Size(35, 30);
             this.PbxMenu.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
             this.PbxMenu.TabIndex = 0;
             this.PbxMenu.TabStop = false;
@@ -481,11 +490,11 @@
             this.tabPage2.Controls.Add(this.BtnIn);
             this.tabPage2.Controls.Add(this.BtnOut);
             this.tabPage2.Controls.Add(this.PbxIdentification);
-            this.tabPage2.Location = new System.Drawing.Point(4, 30);
+            this.tabPage2.Location = new System.Drawing.Point(4, 22);
             this.tabPage2.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
             this.tabPage2.Name = "tabPage2";
             this.tabPage2.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5);
-            this.tabPage2.Size = new System.Drawing.Size(429, 355);
+            this.tabPage2.Size = new System.Drawing.Size(429, 363);
             this.tabPage2.TabIndex = 1;
             this.tabPage2.Text = "Ident";
             this.tabPage2.UseVisualStyleBackColor = true;
@@ -535,9 +544,9 @@
             // tabPage3
             // 
             this.tabPage3.Controls.Add(this.DgbJournal);
-            this.tabPage3.Location = new System.Drawing.Point(4, 30);
+            this.tabPage3.Location = new System.Drawing.Point(4, 22);
             this.tabPage3.Name = "tabPage3";
-            this.tabPage3.Size = new System.Drawing.Size(429, 355);
+            this.tabPage3.Size = new System.Drawing.Size(429, 363);
             this.tabPage3.TabIndex = 2;
             this.tabPage3.Text = "Journal";
             this.tabPage3.UseVisualStyleBackColor = true;
@@ -657,12 +666,14 @@
             this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(243)))), ((int)(((byte)(243)))), ((int)(((byte)(243)))));
             this.ClientSize = new System.Drawing.Size(689, 389);
             this.Controls.Add(this.SplitContainer);
+            this.DoubleBuffered = true;
             this.Font = new System.Drawing.Font("Segoe UI Semibold", 12F, System.Drawing.FontStyle.Bold);
             this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
             this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
             this.Name = "FormMain";
             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
             this.Text = "FaceTrack профессиональный";
+            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FormMain_FormClosing);
             this.Load += new System.EventHandler(this.FormMain_Load);
             this.ResizeEnd += new System.EventHandler(this.FormMain_ResizeEnd);
             this.Resize += new System.EventHandler(this.FormMain_Resize);

+ 99 - 53
T FaceRecognizer/FormMain.cs

@@ -47,6 +47,8 @@ namespace T_FaceRecognizer
         /// тип операции 1 - вход, 0- выход 
         /// </summary>
         private int TypeOperation = 0;
+
+        private bool IsMenuOpened = true;
         #endregion
         #region <Свойства>
 
@@ -152,8 +154,14 @@ namespace T_FaceRecognizer
         /// </summary>
         private void ProcessFrame()
         {
-            BgrFrame = Capture.QueryFrame().ToImage<Bgr, Byte>().Flip(FlipType.Horizontal);
-
+            try
+            {
+                BgrFrame = Capture.QueryFrame().ToImage<Bgr, Byte>().Flip(FlipType.Horizontal);
+            }
+            catch
+            {
+                return;
+            }
             if (BgrFrame != null)
             {
                 try
@@ -163,10 +171,10 @@ namespace T_FaceRecognizer
                     Rectangle[] faces = HaarCascade.DetectMultiScale(grayframe, 1.2, 10, new System.Drawing.Size(50, 50), new System.Drawing.Size(200, 200));
 
                     //detect face
-                    FaceName = "No face detected";
+                    FaceName = "Лицо не обнаружено";
                     foreach (var face in faces)
                     {
-                        BgrFrame.Draw(face, new Bgr(255, 255, 0), 2);
+                        BgrFrame.Draw(face, new Bgr(0, 0, 255), 2);
                         DetectedFace = BgrFrame.Copy(face).Convert<Gray, byte>();
                         FaceRecognition();
                         break;
@@ -202,31 +210,7 @@ namespace T_FaceRecognizer
             }
         }
 
-        /// <summary>
-        /// Convert bitmap to bitmap image for image control
-        /// </summary>
-        /// <param name="bitmap">Bitmap image</param>
-        /// <returns>Image Source</returns>
-        private Bitmap BitmapToImageSource(Bitmap bitmap)
-        {
-            using (MemoryStream memory = new MemoryStream())
-            {
-                bitmap.Save(memory, System.Drawing.Imaging.ImageFormat.Bmp);
-                memory.Position = 0;
-                BitmapImage bitmapimage = new BitmapImage();
-                bitmapimage.BeginInit();
-                bitmapimage.StreamSource = memory;
-                bitmapimage.CacheOption = BitmapCacheOption.OnLoad;
-                bitmapimage.EndInit();
-                //конвертация BitmapImage в Bitmap
-                BitmapEncoder Enc = new BmpBitmapEncoder();
-                Enc.Frames.Add(BitmapFrame.Create(bitmapimage));
-                Enc.Save(memory);
-                Bitmap Btm = new Bitmap(memory);
 
-                return new Bitmap(Btm);
-            }
-        }
         /// <summary>
         /// добавление лица в систему
         /// </summary>
@@ -293,12 +277,11 @@ values (@last,@first,@patr,@phone,@snils,@photo)
         /// </summary>
         public void GetFacesList()
         {
-            //haar cascade classifier
             if (!File.Exists(Config.HaarCascadePath))
             {
                 string text = "Файл каскада Хаара не обнаружен:\n\n";
                 text += Config.HaarCascadePath;
-                DialogResult result = MessageBox.Show(text, "Error",
+                DialogResult result = MessageBox.Show(text, "Ошибка",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
 
@@ -338,14 +321,15 @@ values (@last,@first,@patr,@phone,@snils,@photo)
 
         private void PbxMenu_Click(object sender, EventArgs e)
         {
+            IsMenuOpened = !IsMenuOpened;
             if(SplitContainer.Panel1.Width != 45)
             {
                 SplitContainer.SplitterDistance = 45;
-                PanHome.BackColor = Color.FromArgb(243, 243, 243);
-                PanAdd.BackColor = Color.FromArgb(243, 243, 243);
-                PanIdentification.BackColor = Color.FromArgb(243, 243, 243);
-                PanJournal.BackColor = Color.FromArgb(243, 243, 243);
-                PanSettings.BackColor = Color.FromArgb(243, 243, 243);
+                PanHome.BackColor = Color.FromArgb(206, 208, 223);
+                PanAdd.BackColor = Color.FromArgb(206, 208, 223);
+                PanIdentification.BackColor = Color.FromArgb(206, 208, 223);
+                PanJournal.BackColor = Color.FromArgb(206, 208, 223);
+                PanSettings.BackColor = Color.FromArgb(206, 208, 223);
             }
             else
             {
@@ -358,10 +342,25 @@ values (@last,@first,@patr,@phone,@snils,@photo)
 
             }
         }
+        /// <summary>
+        /// котроль размеров меню
+        /// </summary>
+        /// <param name="isMenuOpened">открыто меню или нет</param>
+        private void ControlSizeMenu(bool isMenuOpened)
+        {
+            if (isMenuOpened)
+            {
+                SplitContainer.SplitterDistance = 250;
+            }
+            else
+            {
+                SplitContainer.SplitterDistance = 45;
+            }
+        }
 
         private void FormMain_Resize(object sender, EventArgs e)
         {
-            //PbxMenu_Click(sender, e);
+            ControlSizeMenu(IsMenuOpened);
         }
 
         private void FormMain_ResizeEnd(object sender, EventArgs e)
@@ -371,6 +370,11 @@ values (@last,@first,@patr,@phone,@snils,@photo)
 
         private void BtnMain_Click(object sender, EventArgs e)
         {
+            Task.Factory.StartNew(() =>
+            {
+                RecognizeOff();
+            });
+
             TabPages.SelectTab(4);
         }
 
@@ -384,14 +388,18 @@ values (@last,@first,@patr,@phone,@snils,@photo)
             };
             CaptureTimer.Tick += CaptureTimer_Tick;
 
-            GetFacesList();
-            Capture = new VideoCapture(Config.ActiveCameraIndex);
+            if (ImageList.Size == 0)
+            {
+                GetFacesList();
+            }
+            TabPages.SelectTab(0);
+
+            Capture = new VideoCapture(SelectedCameraID);
             Capture.SetCaptureProperty(CapProp.Fps, 30);
             Capture.SetCaptureProperty(CapProp.FrameHeight, 450);
             Capture.SetCaptureProperty(CapProp.FrameWidth, 370);
             CaptureTimer.Start();
 
-            TabPages.SelectTab(0);
         }
 
         private void BtnIdent_Click(object sender, EventArgs e)
@@ -402,14 +410,14 @@ values (@last,@first,@patr,@phone,@snils,@photo)
             };
             CaptureTimerIdent.Tick += CaptureTimerIdent_Tick;
 
-            try
-            {
-                RecognizeOff();
-            }
-            catch (Exception ex)
-            {
-                MessageBox.Show(ex.Message, "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
-            }
+            //try
+            //{
+            //    RecognizeOff();
+            //}
+            //catch (Exception ex)
+            //{
+            //    MessageBox.Show(ex.Message, "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
+            //}
 
             GetFacesListForIdentification();
 
@@ -430,11 +438,19 @@ values (@last,@first,@patr,@phone,@snils,@photo)
         {
             if (BgrFrame != null)
             {
-                BgrFrame = null;
-                Capture.Dispose();
+                if (Capture != null)
+                {
+                    Capture.Dispose();
+                    Capture = null;
+                }
+                //BgrFrame = null;
                 if (CaptureTimer != null)
                 {
-                    CaptureTimer.Tick -= CaptureTimer_Tick;
+                    CaptureTimer.Enabled = false;
+                }
+                if(CaptureTimerIdent != null)
+                {
+                    CaptureTimerIdent.Enabled = false;
                 }
             }
         }
@@ -449,8 +465,14 @@ values (@last,@first,@patr,@phone,@snils,@photo)
         /// </summary>
         private void ProcessFrameIndentification()
         {
-            BgrFrame = Capture.QueryFrame().ToImage<Bgr, Byte>().Flip(FlipType.Horizontal);
-
+            try
+            {
+                BgrFrame = Capture.QueryFrame().ToImage<Bgr, Byte>().Flip(FlipType.Horizontal);
+            }
+            catch
+            {
+                return;
+            }
             if (BgrFrame != null)
             {
                 try
@@ -626,7 +648,10 @@ where UsersID = '{CurrentUserID}' and [Date] = cast(GETDATE() as date)";
 
         private void BtnJournal_Click(object sender, EventArgs e)
         {
-            RecognizeOff();
+            Task.Factory.StartNew(() =>
+            {
+                RecognizeOff();
+            });
             GetInformationAboutVisiting();
             TabPages.SelectTab(2);
         }
@@ -672,5 +697,26 @@ from Users";
             FVisiting.ShowDialog();
             this.Show();
         }
+
+        private void BtnSettings_Click(object sender, EventArgs e)
+        {
+            Task.Factory.StartNew(() =>
+            {
+                RecognizeOff();
+            });
+
+            TabPages.SelectTab(3);
+        }
+
+        private void PanelMenu_Paint(object sender, PaintEventArgs e)
+        {
+            Invalidate();
+        }
+
+        private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
+        {
+            RecognizeOff();
+            Application.ExitThread();
+        }
     }
 }

BIN=BIN
T FaceRecognizer/bin/Debug/Source/Faces/Ирина74859619634.bmp


BIN=BIN
T FaceRecognizer/bin/Debug/T FaceRecognizer.exe