Explorar el Código

Распознавание лица

Вячеслав Терешенко hace 2 años
padre
commit
fc204d2b86

+ 1 - 1
ImpulseVision/FormAutorize.cs

@@ -62,7 +62,7 @@ namespace ImpulseVision
 
         private void FormAutorize_FormClosing(object sender, FormClosingEventArgs e)
         {
-            
+            Application.ExitThread();
         }
 
         private void FormAutorize_Load(object sender, EventArgs e)

+ 29 - 29
ImpulseVision/FormGuard.cs

@@ -36,7 +36,6 @@ namespace ImpulseVision
 
             };
             CaptureTimer.Tick += CaptureTimer_Tick;
-
         }
 
         private void CaptureTimer_Tick(object sender, EventArgs e)
@@ -75,7 +74,7 @@ namespace ImpulseVision
                 {
                     IsRecognized = true;
                 }
-                this.Text = IsRecognized.ToString();
+                //this.Text = IsRecognized.ToString();
                 UserName = faceName;
                 NotifyPropertyChanged();
             }
@@ -191,9 +190,9 @@ namespace ImpulseVision
             SqlDataReader Res = Cmd.ExecuteReader();
             if(Res.HasRows)
             {
-                FaceItem = new FaceData();
                 while (Res.Read())
                 {
+                    FaceItem = new FaceData();
                     FaceItem.FaceImage = new Image<Gray, byte>(Application.StartupPath +"\\"+ Res["Picture"].ToString());
                     FaceItem.PersonName = Res["Firstname"].ToString();
                     FaceItem.LastName = Res["Lastname"].ToString();
@@ -257,8 +256,7 @@ namespace ImpulseVision
                 }
                 catch (Exception ex)
                 {
-
-                    //todo log
+                    MessageBox.Show(ex.Message);
                 }
 
             }
@@ -274,6 +272,8 @@ namespace ImpulseVision
                 //Eigen Face Algorithm
                 FaceRecognizer.PredictionResult result = recognizer.Predict(DetectedFace.Resize(100, 100, Inter.Cubic));
                 FaceName = NameList[result.Label];
+
+                this.Text = "UserID: " + FaceList[result.Label].UserID;
                 CameraCaptureFace = DetectedFace.ToBitmap();
             }
             else
@@ -638,35 +638,35 @@ namespace ImpulseVision
                 SelectedCameraID = 0;
             }
         }
-
+        
         private void CmbCams_SelectedIndexChanged(object sender, EventArgs e)
         {
-            try
-            {
-                //если захват видео уже идёт
-                if (Capture != null)
-                {
-                    //captureTimer.Stop();
-                    Capture.Dispose();
-                    Capture = null;
-                    PbxEther.Image = null;
-                }
-            }
-            catch (Exception ex)
-            {
-                MessageBox.Show(ex.Message, "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
-            }
+            //try
+            //{
+            //    //если захват видео уже идёт
+            //    if (Capture != null)
+            //    {
+            //        //captureTimer.Stop();
+            //        Capture.Dispose();
+            //        Capture = null;
+            //        PbxEther.Image = null;
+            //    }
+            //}
+            //catch (Exception ex)
+            //{
+            //    MessageBox.Show(ex.Message, "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
+            //}
 
-            SelectedCameraID = CmbCams.SelectedIndex;
+            //SelectedCameraID = CmbCams.SelectedIndex;
 
-            Capture = new VideoCapture(SelectedCameraID);
-            //настройка кадров
-            Capture.SetCaptureProperty(CapProp.Fps, 30);
-            Capture.SetCaptureProperty(CapProp.FrameHeight, 450);
-            Capture.SetCaptureProperty(CapProp.FrameWidth, 370);
-            CaptureTimer.Start();
+            //Capture = new VideoCapture(SelectedCameraID);
+            ////настройка кадров
+            //Capture.SetCaptureProperty(CapProp.Fps, 30);
+            //Capture.SetCaptureProperty(CapProp.FrameHeight, 450);
+            //Capture.SetCaptureProperty(CapProp.FrameWidth, 370);
+            //CaptureTimer.Start();
         }
-
+        
         private void TimerCam_Tick(object sender, EventArgs e)
         {
             DsDevice[] Cams = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);

+ 16 - 20
ImpulseVision/FormMain.cs

@@ -133,12 +133,6 @@ namespace ImpulseVision
         public FormMain()
         {
             InitializeComponent();
-            CaptureTimer = new Timer()
-            {
-                Interval = Config.TimerResponseValue
-
-            };
-            CaptureTimer.Tick += CaptureTimer_Tick;
         }
 
         private void CaptureTimer_Tick(object sender, EventArgs e)
@@ -153,14 +147,6 @@ 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
@@ -403,8 +389,10 @@ where ID = '{IdUser}'";
         /// </summary>
         private void ShowAdding()
         {
-            TableLayoutWorks.ColumnStyles[0].Width = 250;
-            TableLayoutWorks.BackColor = Color.White;
+            this.TableLayoutWorks.BeginInvoke((MethodInvoker)(() => this.TableLayoutWorks.ColumnStyles[0].Width = 250));
+            this.TableLayoutWorks.BeginInvoke((MethodInvoker)(() => this.TableLayoutWorks.BackColor = Color.White));
+            //TableLayoutWorks.ColumnStyles[0].Width = 250;
+            //TableLayoutWorks.BackColor = Color.White;
         }
         /// <summary>
         /// скрытие окна добавления
@@ -437,7 +425,13 @@ where ID = '{IdUser}'";
             TbxPasportNum.Text = "";
 
             TabPages.SelectTab(1);
+            PbxEther.Image = Properties.Resources.loading_7;
 
+            CaptureTimer = new Timer()
+            {
+                Interval = Config.TimerResponseValue
+            };
+            CaptureTimer.Tick += CaptureTimer_Tick;
 
             if (IsWorking)
                 return;
@@ -632,14 +626,16 @@ where ID = '{IdUser}'";
             HideAdding();
 
             BtnDelUser.Enabled = true;
-
-            if (Capture != null)
+            if (BgrFrame != null)
             {
                 BgrFrame = null;
-                Capture.Stop();
+                //Capture.Stop();
+                //Capture.Dispose();
                 Capture.Dispose();
-                Capture = null;
             }
+            //CaptureTimer.Stop();
+            CaptureTimer.Tick -= CaptureTimer_Tick;
+
             PbxEther.Image = Properties.Resources._9110852_video_no_icon;
 
             TableLayoutWorks.BackColor = Color.Gray;

+ 2 - 0
ImpulseVision/ImpulseVision.csproj

@@ -267,6 +267,8 @@
     <None Include="App.config" />
   </ItemGroup>
   <ItemGroup>
+    <None Include="Resources\loading-7.gif" />
+    <None Include="Resources\AnimLoading.gif" />
     <None Include="Resources\haarcascade_frontalface_default.xml">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>

+ 10 - 0
ImpulseVision/Properties/Resources.Designer.cs

@@ -203,6 +203,16 @@ namespace ImpulseVision.Properties {
             }
         }
         
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
+        internal static System.Drawing.Bitmap loading_7 {
+            get {
+                object obj = ResourceManager.GetObject("loading_7", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
         /// <summary>
         ///   Looks up a localized resource of type System.Drawing.Bitmap.
         /// </summary>

+ 3 - 0
ImpulseVision/Properties/Resources.resx

@@ -160,4 +160,7 @@
   <data name="haarcascade_frontalface_default" type="System.Resources.ResXFileRef, System.Windows.Forms">
     <value>..\Resources\haarcascade_frontalface_default.xml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;windows-1251</value>
   </data>
+  <data name="loading_7" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Resources\loading-7.gif;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
 </root>

BIN
ImpulseVision/Resources/AnimLoading.gif


BIN
ImpulseVision/Resources/loading-7.gif


BIN
ImpulseVision/bin/Debug/ImpulseVision.exe


BIN
ImpulseVision/bin/Debug/Source/TrainedImages/Вера8519496857.bmp


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


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