瀏覽代碼

Переключение между камерами

Вячеслав Терешенко 2 年之前
父節點
當前提交
013d5a1757
共有 3 個文件被更改,包括 42 次插入49 次删除
  1. 25 28
      ImpulseVision/FormGuard.cs
  2. 17 21
      ImpulseVision/FormMain.cs
  3. 二進制
      ImpulseVision/bin/Debug/ImpulseVision.exe

+ 25 - 28
ImpulseVision/FormGuard.cs

@@ -378,30 +378,29 @@ namespace ImpulseVision
         
         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);
-            //}
-
-            //SelectedCameraID = CmbCams.SelectedIndex;
-
-            //Capture = new VideoCapture(SelectedCameraID);
-            ////настройка кадров
-            //Capture.SetCaptureProperty(CapProp.Fps, 30);
-            //Capture.SetCaptureProperty(CapProp.FrameHeight, 450);
-            //Capture.SetCaptureProperty(CapProp.FrameWidth, 370);
-            //CaptureTimer.Start();
+            try
+            {
+                if (BgrFrame != null)
+                {
+                    BgrFrame = null;
+                    Capture.Dispose();
+                    CaptureTimer.Tick -= CaptureTimer_Tick;
+                }
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(ex.Message, "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
+            }
+
+            SelectedCameraID = CmbCams.SelectedIndex;
+
+            Capture = new VideoCapture(SelectedCameraID);
+            //настройка кадров
+            Capture.SetCaptureProperty(CapProp.Fps, 30);
+            Capture.SetCaptureProperty(CapProp.FrameHeight, 450);
+            Capture.SetCaptureProperty(CapProp.FrameWidth, 370);
+            CaptureTimer.Tick += CaptureTimer_Tick;
+            CaptureTimer.Start();
         }
         
         private void TimerCam_Tick(object sender, EventArgs e)
@@ -430,14 +429,12 @@ namespace ImpulseVision
             if (BgrFrame != null)
             {
                 BgrFrame = null;
-                //Capture.Stop();
-                //Capture.Dispose();
                 Capture.Dispose();
+                CaptureTimer.Tick -= CaptureTimer_Tick;
             }
-            //CaptureTimer.Stop();
-            CaptureTimer.Tick -= CaptureTimer_Tick;
 
             PbxEther.Image = Properties.Resources._9110852_video_no_icon;
+            CaptureTimer.Tick -= CaptureTimer_Tick;
         }
         private void DgbOutput_CellContentClick(object sender, DataGridViewCellEventArgs e)
         {

+ 17 - 21
ImpulseVision/FormMain.cs

@@ -510,32 +510,28 @@ values ({AddingUserID},'{PhotoPath}')";
         {
             try
             {
-                //если захват видео уже идёт
-                //if(VideoCapture != null)
-                //{
-                //    VideoCapture.Pause();
-                //    VideoCapture.Stop();
-                //    VideoCapture.Dispose();
-                //    VideoCapture = null;
-                //    PbxEther.Image = null;
-                //    SelectedCameraID = -1;
-                //}
+                if (BgrFrame != null)
+                {
+                    BgrFrame = null;
+                    Capture.Dispose();
+                    CaptureTimer.Tick -= CaptureTimer_Tick;
+                }
             }
-            catch(Exception ex)
+            catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             }
-
-            SelectedCameraID = CmbCams.SelectedIndex;
-
-            if (IsWorking)
+            if (TabPages.SelectedIndex == 1)
             {
-                //VideoCapture = new VideoCapture(SelectedCameraID);
-                //////VideoCapture.ImageGrabbed += VideoCapture_ImageGrabbed;
-                //VideoCapture.Start();
-
-                //FacesDetectionEnabled = true;//включить распознавание
-                //CvInvoke.UseOpenCL = true;
+                SelectedCameraID = CmbCams.SelectedIndex;
+
+                Capture = new VideoCapture(SelectedCameraID);
+                //настройка кадров
+                Capture.SetCaptureProperty(CapProp.Fps, 30);
+                Capture.SetCaptureProperty(CapProp.FrameHeight, 450);
+                Capture.SetCaptureProperty(CapProp.FrameWidth, 370);
+                CaptureTimer.Tick += CaptureTimer_Tick;
+                CaptureTimer.Start();
             }
         }
 

二進制
ImpulseVision/bin/Debug/ImpulseVision.exe