首頁>技術>

先定義收集過濾器資訊的物件

FilterInfoCollection videoDevices;
定義影片源抓取類
VideoCaptureDevice videoSource;
定義下標
public int selectedDeviceIndex = 0;
連線攝像頭
 #region  點選按鈕連線攝像頭        private void btnSheXiang_Click(object sender, EventArgs e)        {            //例項化過濾類            //FilterCategory.VideoInputDevice影片輸入裝置類別。            videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);            //例項化下標            selectedDeviceIndex = 0;            //例項化影片源抓取類            //videoDevices[selectedDeviceIndex].MonikerString   過濾器的名字的字串。            videoSource = new VideoCaptureDevice(videoDevices[selectedDeviceIndex].MonikerString);//連線攝像頭            //影片分辨設定            //該屬性允許設定一個支援的影片解析度            //相機。使用AForge.Video.DirectShow.VideoCaptureDevice.VideoCapabilities            //屬性以獲得支援的影片解析度列表。            //在照相機開始生效之前必須設定好該屬性。            //屬性的預設值設定為null,這意味著預設的影片解析度            //使用。            videoSource.VideoResolution = videoSource.VideoCapabilities[selectedDeviceIndex];            //把例項化好的videosource類賦值到VideoSourcePlayer控制元件的VideoSource屬性            vspxianshi.VideoSource = videoSource;            //啟動VideoSourcePlayer控制元件            vspxianshi.Start();            //這樣就把攝像頭的影象獲取到了本地            System.Threading.Thread.Sleep(5000);            tmdengdai.Start();            btnSheXiang.Enabled = false;        }        #endregion
定義圖片路徑
        #region   定義圖片路徑        private void btnpto_Click(object sender, EventArgs e)        {            if (videoSource == null)            {                return;            }            else            {                //建立影象物件                Bitmap bitmap = vspxianshi.GetCurrentVideoFrame();                //定義圖片路徑                string filename = "jietu.jpg";                //建立圖片                bitmap.Save(filename, ImageFormat.Jpeg);                pbto.ImageLocation = filename;            }                    }        #endregion
建立影象物件
#region 建立影象物件        private void tmdengdai_Tick(object sender, EventArgs e)        {            if (videoSource == null)            {                return;            }            else            {                try                {                    //建立影象物件                    Bitmap bm1 = vspxianshi.GetCurrentVideoFrame();                    Bitmap bm2 = new Bitmap(bm1.Width, bm1.Height);                    Graphics g = Graphics.FromImage(bm2);                    g.DrawImageUnscaled(bm1, 0, 0);                    //get rid of the graphics                    g.Dispose();                    //and save a new gif                    bm2.Save("001.jpg", ImageFormat.Jpeg);                    //pbboxpot.ImageLocation = "001.jpg";                }                catch (Exception)                {                    MessageBox.Show("您的攝像頭有問題,請您重新試一次!");                }                            }        }        #endregion
還是老樣子,功能直接應用即可獲取方式:轉發+關注私信恢復:“影片”

15
  • BSA-TRITC(10mg/ml) TRITC-BSA 牛血清白蛋白改性標記羅丹明
  • ubuntu20 python3安裝tensorflow2