public Form1() { InitializeComponent(); CheckForIllegalCrossThreadCalls = false; label2.Text = Thread.CurrentThread.ManagedThreadId.ToString(); videPlayer = new VideoSourcePlayer(); try { //枚举所有视频输入设备 videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); if (videoDevices.Count == 0) { throw new ApplicationException(); } foreach (FilterInfo device in videoDevices) { comboBox1.Items.Add(device.Name); } } catch (ApplicationException) { MessageBox.Show("没有摄像头"); } }
public CameraCaptureHelper(VideoSourcePlayer videoSourcePlayer) { this.videoSourcePlayer = videoSourcePlayer; // enumerate video devices videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); if (videoDevices.Count == 0) { throw new Exception("没有找到摄像头"); } videoDevice = new VideoCaptureDevice(videoDevices[0].MonikerString); videoCapabilities = videoDevice.VideoCapabilities; snapshotCapabilities = videoDevice.SnapshotCapabilities; foreach (VideoCapabilities capabilty in videoCapabilities) { VideoResolutions.Add(new Size(capabilty.FrameSize.Width, capabilty.FrameSize.Height)); } foreach (VideoCapabilities capabilty in snapshotCapabilities) { SnapshotResolutions.Add(new Size(capabilty.FrameSize.Width, capabilty.FrameSize.Height)); } }
private async Task InitializeVideoDevice(string videoDeviceSourceId) { await this.ReleaseVideoDevice(); if (string.IsNullOrEmpty(videoDeviceSourceId)) { return; } try { if (!GetVideoDevices.Any(item => item.UsbId.Equals(videoDeviceSourceId))) { return; } this.SelectedCamera = new VideoCaptureDevice(videoDeviceSourceId); SelectedCamera.ProvideSnapshots = true; SelectedCamera.NewFrame += SelectedCamera_NewFrame; this.VideoSourcePlayer = new VideoSourcePlayer() { VideoSource = this.SelectedCamera }; this.VideoSourcePlayer.Start(); this.isVideoSourceInitialized = true; } catch { } }
private void Setup() { player = new VideoSourcePlayer(); player.Location = new System.Drawing.Point(0, 24); player.Size = new Size(1280, 720); player.NewFrame += PlayerNewFrame; this.Controls.Add(player); FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString); foreach (VideoCapabilities vc in videoSource.VideoCapabilities) { if (vc.FrameSize.Height == 720) { videoSource.VideoResolution = vc; } } player.VideoSource = videoSource; player.Start(); redLower.Value = rL; redUpper.Value = rU; greenLower.Value = gL; greenUpper.Value = gU; blueLower.Value = bL; blueUpper.Value = bU; brightnessCorrectionNUM.Value = brightnessCorrection; }
public Form1() { InitializeComponent(); hookTool.Hook_Start(); tscbxCameras = new List <string>(); initCamera(); width = Screen.PrimaryScreen.Bounds.Width; height = Screen.PrimaryScreen.Bounds.Height; widthUnit = width / 16; heightUnit = height / 9; showResult = false; showPicture = false; rm = new Random(); videPlayer = new VideoSourcePlayer(); timer1.Interval = 2000; this.FormBorderStyle = FormBorderStyle.None; this.WindowState = FormWindowState.Maximized; this.TopMost = true; this.DoubleBuffered = true; getCodeRandom(); getSudokuRandom(); imgArr = new Image[] { Properties.Resources._1, Properties.Resources._2, Properties.Resources._3, Properties.Resources._4, Properties.Resources._5, Properties.Resources._6, Properties.Resources._7, Properties.Resources._8, Properties.Resources._9 }; }
//打开相机 public VideoCaptureDevice open(int selectIndex) { if (DeviceExist) { close(); try { //启动USB相机 if (selectIndex < videoDevices.Count) { this.videoSource = new VideoCaptureDevice(videoDevices[selectIndex].MonikerString);//连接摄像头 videoSourcePlayer = new VideoSourcePlayer(); videoSource.NewFrame += new NewFrameEventHandler(callBackHandler);//捕获画面事件 videoSourcePlayer.NewFrame += new Accord.Controls.VideoSourcePlayer.NewFrameHandler(videoSourcePlayerCallBackHandler); videoSourcePlayer.VideoSource = videoSource; videoSourcePlayer.Start(); timer.Enabled = true; timer.Start(); //videoSourcePlayer.Start(); } else { throw new ApplicationException("打开相机失败!"); } } catch { MessageBox.Show("打开相机失败!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } } return(this.videoSource); }
//打开摄像头 private void activeCamara_btn_Click(object sender, EventArgs e) { if (videoDevices.Count == 0) { return; } if (CurrentVideoSourcePlayer != null && CurrentVideoSourcePlayer.IsRunning) { CurrentVideoSourcePlayer.SignalToStop(); CurrentVideoSourcePlayer.WaitForStop(); videoSource = null; } switch (UserFace_Page.SelectedIndex) { case 2: break; case 0: CurrentVideoSourcePlayer = videoSourcePlayer_UserCheckIn; break; } videoSource = new VideoCaptureDevice(videoDevices[selectedDeviceIndex].MonikerString);//连接摄像头。 videoSource.VideoResolution = videoSource.VideoCapabilities[selectedDeviceIndex]; CurrentVideoSourcePlayer.VideoSource = videoSource; CurrentVideoSourcePlayer.Start(); }
private void CloseCurrentVideoSource() { if (VideoSourcePlayer.VideoSource != null) { VideoSourcePlayer.SignalToStop(); // wait ~ 3 seconds for (int i = 0; i < 30; i++) { if (!VideoSourcePlayer.IsRunning) { break; } Thread.Sleep(100); } if (VideoSourcePlayer.IsRunning) { VideoSourcePlayer.Stop(); } VideoSourcePlayer.VideoSource = null; } }
public ChangeVideoFormatCommand(VideoSourcePlayer videoPlayer, ComboBox videoSourceCombo, ComboBox videoFormatCombo, MainForm mainForm) { this.videoPlayer = videoPlayer; this.videoFormatCombo = videoFormatCombo; this.videoSourceCombo = videoSourceCombo; this.mainForm = mainForm; }
private void Form1_Load(object sender, EventArgs e) { listView1.Columns.Add("NUA", this.listView1.Width / 5); listView1.Columns.Add("Nombre", this.listView1.Width / 5); listView1.Columns.Add("A. Paternod", this.listView1.Width / 3); listView1.Columns.Add(" A. Materno", this.listView1.Width / 3); listView1.Columns.Add(" Carrera ", this.listView1.Width / 5); listView1.View = View.Details; // conseguir todos los dispositivos de video this.ColeccionDisp = new FilterInfoCollection(FilterCategory.VideoInputDevice); //MessageBox.Show(this.rutaGuardado); // desplegar dispositivos en el combo foreach (FilterInfo disp in ColeccionDisp) { comboBox1.Items.Add(disp.Name); } // agregar control VideoSourcePlayer ControlVideo = new VideoSourcePlayer(); ControlVideo.BackColor = Color.Red; ControlVideo.Size = new Size(panel2.Width, panel2.Height); ControlVideo.Name = "ControlVideo"; panel2.Controls.Add(ControlVideo); }
/// <summary> /// Call back function for take snapshot command dependency property, /// when no video device source selected show appropriate message /// or message currently display in user-control based on user input. /// </summary> /// <exception cref="InvalidOperationException">Wraps and throws <see cref="InvalidOperationException"/> when any exception is thrown from this method.</exception> public void TakeSnapshotCallback() { try { var playerPoint = new System.Drawing.Point(); //// Get the position of the source video device player. if (string.IsNullOrWhiteSpace(VideoSourceId)) { var noVideoDeviceSourcePoint = NoVideoSourceGrid.PointToScreen(new Point(0, 0)); playerPoint.X = (int)noVideoDeviceSourcePoint.X; playerPoint.Y = (int)noVideoDeviceSourcePoint.Y; } else { playerPoint = VideoSourcePlayer.PointToScreen(new System.Drawing.Point(VideoSourcePlayer.ClientRectangle.X, VideoSourcePlayer.ClientRectangle.Y)); } if (double.IsNaN(VideoPreviewWidth) || double.IsNaN(VideoPreviewHeight)) { using ( var bitmap = new Bitmap((int)VideoSourceWindowsFormsHost.ActualWidth, (int)VideoSourceWindowsFormsHost.ActualHeight)) { using (var graphicsFromImage = Graphics.FromImage(bitmap)) { graphicsFromImage.CopyFromScreen(playerPoint, System.Drawing.Point.Empty, new System.Drawing.Size((int)VideoSourceWindowsFormsHost.ActualWidth, (int)VideoSourceWindowsFormsHost.ActualHeight)); } SnapshotBitmap = new Bitmap(bitmap); } } else { using (var bitmap = new Bitmap((int)VideoPreviewWidth, (int)VideoPreviewHeight)) { using (var graphicsFromImage = Graphics.FromImage(bitmap)) { graphicsFromImage.CopyFromScreen(playerPoint, System.Drawing.Point.Empty, new System.Drawing.Size((int)VideoPreviewWidth, (int)VideoPreviewHeight)); } SnapshotBitmap = new Bitmap(bitmap); } } } catch (Exception exception) { throw new InvalidOperationException( "Error occurred while trying to take snapshot from currently selected source video device", exception); } }
public static VideoSourcePlayer restart(this VideoSourcePlayer videoPlayer) { videoPlayer.invokeOnThread( () => { videoPlayer.Start(); }); return(videoPlayer); }
// botonApagar private void button7_Click(object sender, EventArgs e) { timer1.Enabled = false; VideoSourcePlayer Reproductor = (VideoSourcePlayer)this.panel2.Controls["ControlVideo"]; Reproductor.SignalToStop(); }
public CheckInTool(VideoSourcePlayer videoSource, DataGridView hasCome, DataGridView unCome) { db = new SQLDBHelper(); camera = new CameraTool.CameraTool(videoSource); FCTool = new FaceCompareTools(); this.DGV_HasCome = hasCome; this.DGV_UnCome = unCome; }
public CameraTool(VideoSourcePlayer videoSourcePlayer) { videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); selectedDeviceIndex = 0; videoSource = new VideoCaptureDevice(videoDevices[selectedDeviceIndex].MonikerString);//连接摄像头。 videoSource.VideoResolution = videoSource.VideoCapabilities[selectedDeviceIndex]; this.videoSourcePlayer = videoSourcePlayer; this.videoSourcePlayer.VideoSource = videoSource; }
/// <summary> /// 录像线程初始化 /// </summary> private static void thread_init() { videoSourcePlayer = new AForge.Controls.VideoSourcePlayer(); videoSource = new VideoCaptureDevice(); writer = new VideoFileWriter(); timer_rec = new System.Timers.Timer(); timer_rec.Elapsed += new System.Timers.ElapsedEventHandler(rec_count); timer_rec.AutoReset = true; timer_rec.Interval = 40; timer_rec.Start(); try { // 枚举所有视频输入设备 videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); if (videoDevices.Count == 0) { throw new ApplicationException(); //没有找到摄像头设备 } } catch (ApplicationException ex) { videoDevices = null; DialogResult drdiv = MessageBox.Show(ex.Message + "没有找到摄像头设备,程序即将关闭", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); if (drdiv == DialogResult.OK) { Environment.Exit(0); } } int temp_capdiv = 0; int temp_capsiz = 0; Size capsize = new Size(1280, 960); foreach (FilterInfo item in videoDevices) { if (item.Name == "LRCP USB2.0") { videoSource = new VideoCaptureDevice(videoDevices[temp_capdiv].MonikerString); temp_capsiz = 0; foreach (VideoCapabilities capab in videoSource.VideoCapabilities)/*(FilterInfoCollection[capdiv].MonikerString).VideoCapabilities[i])*/ { if (capab.FrameSize == capsize) { capset = temp_capdiv * 100 + temp_capsiz; } temp_capsiz++; } } temp_capdiv++; } }
public static string createAndPlay(this VideoSourcePlayer videoPlayer, List <string> pathToImages) { "in VideoSourcePlayer createAndPlay, creating a video from {0} WPF images".info(pathToImages.size()); var aforgeVideo = new API_AForge_Video(); aforgeVideo.add_Images(pathToImages); aforgeVideo.saveAndClose(); videoPlayer.play(aforgeVideo.PathToAviVideo); return(aforgeVideo.PathToAviVideo); }
// load cameras, viddeo players, tabs void LoadCameras() { try { // enumerate video devices FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); if (videoDevices.Count == 0) { throw new ApplicationException(); } players = new Dictionary <VideoSourcePlayer, string>(); // add all devices to combo foreach (FilterInfo device in videoDevices) { // create tabs and source players DevComponents.DotNetBar.SuperTabControlPanel superTabControlPanel1 = new DevComponents.DotNetBar.SuperTabControlPanel(); DevComponents.DotNetBar.SuperTabItem superTabItem1 = new DevComponents.DotNetBar.SuperTabItem(); superTabItem1.AttachedControl = superTabControlPanel1; superTabItem1.GlobalItem = false; superTabItem1.Name = "CAMTAB" + (superTabControl1.Tabs.Count).ToString(); superTabItem1.Text = "CAM " + (superTabControl1.Tabs.Count).ToString(); superTabControlPanel1.Dock = System.Windows.Forms.DockStyle.Fill; superTabControlPanel1.Location = new System.Drawing.Point(0, 23); superTabControlPanel1.Name = "CAM" + (superTabControl1.Tabs.Count).ToString(); superTabControlPanel1.Size = new System.Drawing.Size(898, 348); superTabControlPanel1.TabIndex = 0; superTabControlPanel1.TabItem = superTabItem1; this.superTabControl1.Controls.Add(superTabControlPanel1); this.superTabControl1.Tabs.AddRange(new DevComponents.DotNetBar.BaseItem[] { superTabItem1 }); VideoSourcePlayer p = new VideoSourcePlayer(); p.Name = "VP" + superTabControl1.Tabs.Count.ToString(); p.Dock = DockStyle.Fill; p.Size = new Size(800, 300); p.Location = new Point(0, 23); p.NewFrame += new VideoSourcePlayer.NewFrameHandler(p_NewFrame); superTabControlPanel1.Controls.Add(p); players.Add(p, device.Name); } } catch (ApplicationException) { MessageBox.Show("No capture device"); } }
public Form1() { InitializeComponent(); videoSourcePlayer = new VideoSourcePlayer(); videoSourcePlayer.Size = new Size(100, 100); videoSourcePlayer.Dock = DockStyle.Fill; videoSourcePlayer.KeepAspectRatio = true; videoSourcePlayer.NewFrame += VideoSourcePlayer_NewFrame; this.Controls.Add(videoSourcePlayer); }
public static VideoSourcePlayer play(this VideoSourcePlayer videoPlayer, string aviFile) { videoPlayer.invokeOnThread( () => { var videoSource = new FileVideoSource(aviFile); videoPlayer.SignalToStop( ); videoPlayer.WaitForStop( ); videoPlayer.VideoSource = videoSource; videoPlayer.Start( ); }); return(videoPlayer); }
/// <summary> /// Initialize video device. /// </summary> /// <param name="videoDeviceSourceId">Video device source Id.</param> /// <exception cref="InvalidOperationException">Throws invalid operation exception if video device source setup fails.</exception> private void InitializeVideoDevice(string videoDeviceSourceId) { if (isVideoSourceInitialized) { return; } var errorAction = new Action(() => SetVideoPlayer(false, "Unable to set video device source")); ReleaseVideoDevice(); if (string.IsNullOrEmpty(videoDeviceSourceId)) { return; } if (videoDeviceSourceId.StartsWith("Message:", StringComparison.OrdinalIgnoreCase)) { var splitString = videoDeviceSourceId.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (splitString.Length == 2) { SetVideoPlayer(false, splitString[1]); } else { SetVideoPlayer(false); } } else { try { if (!VideoDevices.Any(item => item.UsbId.Equals(videoDeviceSourceId))) { return; } videoCaptureDevice = new VideoCaptureDevice(videoDeviceSourceId); VideoSourcePlayer.VideoSource = videoCaptureDevice; VideoSourcePlayer.Start(); isVideoSourceInitialized = true; SetVideoPlayer(true); } catch (ArgumentNullException) { errorAction(); } catch (ArgumentException) { errorAction(); } } }
public VideoRecorder(Logger logger, Settings settings, VideoSourcePlayer videoSourcePlayer, ISynchronizeInvoke iSynchronizeInvoke) { _Logger = logger; _Settings = settings; _VideoSourcePlayer = videoSourcePlayer; _VideoFileWriter = new VideoFileWriter(); _Timer = new Timer(); _Timer.SynchronizingObject = iSynchronizeInvoke; _Timer.Interval = 1000; _Timer.Elapsed += _Timer_Elapsed; }
private void OpenVideoSource(VideoSourcePlayer player, IVideoSource source) { // set busy cursor this.Cursor = Cursors.WaitCursor; // stop current video source CloseCurrentVideoSource(player); // start new video source player.VideoSource = source; player.Start(); this.Cursor = Cursors.Default; }
public HomeForm() { InitializeComponent(); Control.CheckForIllegalCrossThreadCalls = false; //1、获取摄像头,并打开 videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); if (videoDevices.Count == 0) { MessageBox.Show("没有可用摄像头!"); } else { CurrentVideoSourcePlayer = videoSourcePlayer_UserCheckIn; videoSource = new VideoCaptureDevice(videoDevices[selectedDeviceIndex].MonikerString);//连接摄像头。 videoSource.VideoResolution = videoSource.VideoCapabilities[selectedDeviceIndex]; CurrentVideoSourcePlayer.VideoSource = videoSource; CurrentVideoSourcePlayer.Start(); } if (Userinfolist == null) { Userinfolist = new List <UserInfo>(); } //2、展示当前识别用户的历史刷脸情况 users_dataGridView.DataSource = Userinfolist; List <List <string> > infor = MysqlUtil.listInfor(); foreach (List <string> l in infor) { //作为一行输出 string line = ""; for (int i = 0; i < l.Count; i++) { //姓名:reader[1],时间:reader[2] if (i == 0) { line += "姓名:" + l[i]; } else { line += ",签到时间:" + l[i]; } } CheckResult_rtb.Text += line + System.Environment.NewLine; } }
private void Form1_Load(object sender, EventArgs e) { this.label5.Visible = false; this.videoSourcePlayer = new AForge.Controls.VideoSourcePlayer(); this.videoSource = new VideoCaptureDevice(); this.writer = new VideoFileWriter(); //设置视频编码格式 this.comboBox_videoecode.Items.Add("Raw"); this.comboBox_videoecode.Items.Add("MPEG2"); this.comboBox_videoecode.Items.Add("FLV1"); this.comboBox_videoecode.Items.Add("H263p"); this.comboBox_videoecode.Items.Add("MSMPEG4v3"); this.comboBox_videoecode.Items.Add("MSMPEG4v2"); this.comboBox_videoecode.Items.Add("WMV2"); this.comboBox_videoecode.Items.Add("WMV1"); this.comboBox_videoecode.Items.Add("MPEG4"); this.comboBox_videoecode.SelectedIndex = 1; //设置视频来源 try { // 枚举所有视频输入设备 videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); if (videoDevices.Count == 0) { throw new ApplicationException(); //没有找到摄像头设备 } foreach (FilterInfo device in videoDevices) { this.comboBox_camera.Items.Add(device.Name); } //this.comboBox_camera.SelectedIndex = 0; //注释掉,选择摄像头来源的时候才会才会触发显示摄像头信息 } catch (ApplicationException) { videoDevices = null; MessageBox.Show("没有找到摄像头设备", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } //秒表 this.timer_count = new System.Timers.Timer(); //实例化Timer类,设置间隔时间为10000毫秒; this.timer_count.Elapsed += new System.Timers.ElapsedEventHandler(tick_count); //到达时间的时候执行事件; this.timer_count.AutoReset = true; //设置是执行一次(false)还是一直执行(true); this.timer_count.Interval = 1000; }
private void OpenVideoSource(IVideoSource source) { Cursor = Cursors.WaitCursor; CloseCurrentVideoSource(); VideoSourcePlayer.VideoSource = source; VideoSourcePlayer.Start(); stopWatch = null; Timer.Start(); Cursor = Cursors.Default; }
private void button8_Click(object sender, EventArgs e) { AForge.Controls.VideoSourcePlayer playerControl = new VideoSourcePlayer(); // set new frame event handler if we need processing of new frames playerControl.NewFrame += new VideoSourcePlayer.NewFrameHandler(playerControl_NewFrame); // create nested video source, for example JPEGStream AForge.Video.JPEGStream stream = new JPEGStream("some url"); // create video source IVideoSource videoSource = new AsyncVideoSource(stream); // start playing it playerControl.VideoSource = videoSource; playerControl.Start( ); }
/// <summary> /// 打开摄像头 /// </summary> public virtual void OpenDevice(string device) { Console.WriteLine($">>>>Open device:[{device}]"); if (String.IsNullOrEmpty(device)) { throw new Exception("Open with null device name."); } if (VideoSource != null) { VideoSource.Stop(); VideoSource = null; } //重置播放器 if (Player != null) { Player.Dispose(); } Player = new VideoSourcePlayer(); Player.NewFrame += OnNewFrame; VideoSource = new VideoCaptureDevice(device); VideoSourceName = device; VideoCapabilities videoResolution; if (CustomResolution == null) { videoResolution = GetMaxVideoCapabilities();//获取最大分辨率 if (videoResolution == null) { VideoSourceName = null; throw new Exception("Failed to get video resolution,please set it in configuration manually"); } VideoSource.VideoResolution = videoResolution; actualResolution = videoResolution.FrameSize; } else { videoResolution = GetCustomVideoCapabilities(CustomResolution.Value); if (videoResolution != null) { VideoSource.VideoResolution = videoResolution; actualResolution = videoResolution.FrameSize; } else { actualResolution = new Size(0, 0); } } }
public PhotoWindow(MainWindow mainWindow) { InitializeComponent( ); this.mainWindow = mainWindow; var videoSourcePlayer = new VideoSourcePlayer( ); wfhVideoPlayer.Child = videoSourcePlayer; videodevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); var videoCaptureDevice = new VideoCaptureDevice(videodevices [0].MonikerString); videoSource = videoCaptureDevice; videoSourcePlayer.VideoSource = videoSource; videoSource.NewFrame += videoSource_NewFrame; videoSource.Start( ); }
/* * Default constructor */ public VideoStream(String url) { InitializeComponent(); // instantiate picture box for video showing _videoPlayer = new VideoSourcePlayer { Name = "_videoPlayer", Size = new Size(640, 480), Location = new Point(0, 0), Visible = true }; // add the video player to the form this.Controls.Add(this._videoPlayer); StartVideo(url); }