乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      winform 加載AForge.dll中的videoSourcePlayer。

       鴻蛟家平 2020-06-30

      公司最近在做人臉識別,用到了videoSourcePlayer 但是引入了AForge.dll之后,工具箱中并沒有videoSourcePlayer,這時就需要自己添加選項卡了。很簡單幾步就能完成。

      首先右鍵工具箱--->添加選項卡

       

       

       名字隨便起,我里就叫AForge,然后選中選項卡右鍵選擇項

       

       

       選擇dll,點擊OK 

       

       

       再次點擊添加到選項卡中

       

       

       就OK了。

      然后是控件的使用。將videoSourcePlayer拖到winform中。進入后臺代碼中

       

      復(fù)制代碼
       private FilterInfoCollection videoDevices;
      
      //獲取攝像頭
      
      private void Form1_Load(object sender, EventArgs e)
      {
      try
      {
      // 枚舉所有視頻輸入設(shè)備
      videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
      
      if (videoDevices.Count == 0)
      throw new ApplicationException();
      
      foreach (FilterInfo device in videoDevices)
      {
      comboBox1.Items.Add(device.Name);
      }
      //下拉框用來更換攝像頭
      comboBox1.SelectedIndex = 0;
      
      }
      catch (ApplicationException)
      {
      comboBox1.Items.Add("未發(fā)現(xiàn)攝像頭");
      comboBox1.SelectedIndex = 0;
      videoDevices = null;
      }
      }
      復(fù)制代碼

       

      復(fù)制代碼
       //關(guān)閉攝像頭
              private void button2_Click(object sender, EventArgs e)
              {
                  if (videoSourcePlayer != null && videoSourcePlayer.IsRunning)
                  {
                      videoSourcePlayer.SignalToStop();
                      videoSourcePlayer.WaitForStop();
                  }
      
              }
              //打開攝像頭
              private void button1_Click(object sender, EventArgs e)
              {
                  button2_Click(null, null);
                  if (comboBox1.SelectedItem.ToString() == "未發(fā)現(xiàn)攝像頭")
                  {
                      MessageBox.Show("未發(fā)現(xiàn)攝像頭", "錯誤提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                      return;
                  }
      
                  VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[comboBox1.SelectedIndex].MonikerString);
                  videoSource.VideoResolution = videoSource.VideoCapabilities[comboBox2.SelectedIndex];
      
                  videoSourcePlayer.VideoSource = videoSource;
                  videoSourcePlayer.Start();
              }

      復(fù)制代碼
      復(fù)制代碼
       //換攝像頭
              private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
              {
                  if (comboBox1.SelectedItem.ToString() == "未發(fā)現(xiàn)攝像頭")
                  {
                      comboBox2.Items.Add("未發(fā)現(xiàn)攝像頭");
                      comboBox2.SelectedIndex = 0;
                      return;
                  }
                  VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[comboBox1.SelectedIndex].MonikerString);
                  if (videoSource.VideoCapabilities.Count() == 0)
                  {
                      comboBox2.Items.Add("攝像頭異常");
                      comboBox2.SelectedIndex = 0;
                      return;
                  }
                  comboBox2.Items.Clear();
                  foreach (AForge.Video.DirectShow.VideoCapabilities FBL in videoSource.VideoCapabilities)
                  {
                      comboBox2.Items.Add(FBL.FrameSize.Width + "*" + FBL.FrameSize.Height);
                  }
      
                  comboBox2.SelectedIndex = 0;
                  button1_Click(null, null);
      
              }
      復(fù)制代碼

      總共就4個方法,首先獲取攝像頭,然后 打開攝像頭 ,關(guān)閉攝像頭,在更換攝像頭中有獲取分辨率的方法,這樣就能打攝像頭并在videoSourcePlayer中看到視頻了

      需要獲取當(dāng)前畫面,就調(diào)用

      Bitmap bitmap = videoSourcePlayer.GetCurrentVideoFrame();

      基本上在videoSourcePlayer的方法中都有,就不贅敘了。

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多