private void button1_Click(object sender, EventArgs e) { FrmVideoSrcSelect webcamSelector = new FrmVideoSrcSelect(); if (webcamSelector.ShowDialog(this) == DialogResult.OK) { bOpsStopped = false; //set the source //VideoCaptureDevice videoSource = new VideoCaptureDevice("@device:pnp:\\\\?\\usb#vid_0c45&pid_6270#5&2e042cf2&0&2#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\\global"); VideoCaptureDevice videoSource = new VideoCaptureDevice(webcamSelector.device); this.videoPlayer.AutoSizeControl = true; videoPlayer.VideoSource = (IVideoSource)videoSource; videoPlayer.Start(); this.button2.Enabled = true; this.lblInfotext.Text = "Webcam selected. Rendering video stream..."; this.pnlMagicCursor.Enabled = true; this.pnlMagicCursor.Visible = true; this.pnlOne.BackColor = Color.FromKnownColor(KnownColor.ButtonFace); this.pnlTwo.BackColor = Color.FromKnownColor(KnownColor.ButtonFace); this.pnlThree.BackColor = Color.FromKnownColor(KnownColor.ButtonFace); this.pnlFour.BackColor = Color.FromKnownColor(KnownColor.ButtonFace); this.pnlFive.BackColor = Color.FromKnownColor(KnownColor.ButtonFace); this.pnlSix.BackColor = Color.FromKnownColor(KnownColor.ButtonFace); this.pnlSeven.BackColor = Color.FromKnownColor(KnownColor.ButtonFace); } }
//打开摄像头 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 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; }
/// <summary> /// 打开/关闭视频事件 /// </summary> private static void video_event_func() { if (NCVM_Form.isopen) { try { videoSource = new VideoCaptureDevice(videoDevices[capset / 100].MonikerString); videoSource.DesiredFrameSize = videoSource.VideoCapabilities[capset % 100].FrameSize; videoSource.NewFrame += show_video; videoSource.Start(); videoSourcePlayer.VideoSource = videoSource; videoSourcePlayer.Start(); timer_rec.Start(); } catch (Exception ex) { MessageBox.Show("错误:" + ex.Message); } } else { stop_flag = true; videoSource.Stop(); videoSourcePlayer.Stop(); } }
public bool Connect() { if (!_Settings.HasCameraMonikerString()) { _Logger.InformUser(Strings.PasDeCameraConfig); return(false); } _VideoCaptureDevice = new VideoCaptureDevice(_Settings.CameraMonikerString); if (_VideoCaptureDevice == null) { _Logger.InformUser(Strings.ImpossibleCreerVCDevice); return(false); } VideoCapabilities[] videoCapabilities = _VideoCaptureDevice.VideoCapabilities; if (videoCapabilities == null || videoCapabilities.Length == 0) { _Logger.InformUser(Strings.NoVCapabilitiesFound); return(false); } if (!_Settings.HasResolutionCamera()) { _Logger.InformUser(Strings.PasDeResolutionCamConfig); return(false); } int indexResolution = 0; bool found = false; while (indexResolution < videoCapabilities.Length && found == false) { VideoCapabilities capability = videoCapabilities[indexResolution]; if (capability.FrameSize.Equals(_Settings.ResolutionCamera)) { found = true; } else { indexResolution++; } } if (!found) { _Logger.InformUser(Strings.PasDeResolutionCorrespondante); return(false); } _VideoCaptureDevice.VideoResolution = videoCapabilities[indexResolution]; _VideoSourcePlayer.VideoSource = _VideoCaptureDevice; _VideoSourcePlayer.Start(); _Timer.Start(); return(true); }
//打开相机 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); }
public static VideoSourcePlayer restart(this VideoSourcePlayer videoPlayer) { videoPlayer.invokeOnThread( () => { videoPlayer.Start(); }); return(videoPlayer); }
private void buttonItem2_Click(object sender, EventArgs e) { try{ currentplayer.Start(); } catch { } }
/// <summary> /// Starts playing the preview screen, grabbing /// frames, but not recording to a video file. /// </summary> /// public void StartPlaying() { if (IsPlaying) { return; } // Checks if we were already waiting for a window // to be selected, in case the user had chosen to // capture from a fixed window. if (IsWaitingForTargetWindow) { // Yes, we were. We will not be waiting anymore // since the user should have selected one now. IsWaitingForTargetWindow = false; } else { // No, this is the first time the user starts the // frame grabber. Let's check what the user wants if (CaptureMode == CaptureRegionOption.Window) { // The user wants to capture from a window. So we // need to ask which window we have to keep a look. // We will return here and wait the user to respond; // when he finishes selecting he should signal back // by calling SelectWindowUnderCursor(). IsWaitingForTargetWindow = true; OnTargetWindowRequested(); return; } } // All is well. Keep configuring and start CaptureRegion = Screen.PrimaryScreen.Bounds; double framerate = Settings.Default.FrameRate; int interval = (int)Math.Round(1000 / framerate); int height = CaptureRegion.Height; int width = CaptureRegion.Width; clickCapture.Enabled = true; keyCapture.Enabled = true; screenStream = new ScreenCaptureStream(CaptureRegion, interval); screenStream.VideoSourceError += ScreenStream_VideoSourceError; videoPlayer.VideoSource = screenStream; videoPlayer.Start(); IsPlaying = true; }
private void openCamera() { if (videoSource == null) { tip = "请先设置摄像头!"; return; } videPlayer.Start(); videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame); tip = "摄像头开启成功..."; }
public void SetVideoResource(IVideoSource videoSource) { if (videoSource is ScreenCaptureStream) { var source = videoSource as ScreenCaptureStream; _windowsFormsHost.Width = CommonHelper.GetWidth(source.Region.Width, source.Region.Height, 210);; _windowsFormsHost.Height = 210; _videoSourcePlayer.VideoSource = videoSource; _videoSourcePlayer.Start(); } else if (videoSource is VideoCaptureDevice) { var source = videoSource as VideoCaptureDevice; source.VideoResolution = source.VideoCapabilities[0]; _windowsFormsHost.Width = CommonHelper.GetWidth(source.VideoResolution.FrameSize.Width, source.VideoResolution.FrameSize.Height, 210); _windowsFormsHost.Height = 210; _videoSourcePlayer.VideoSource = videoSource; _videoSourcePlayer.Start(); } }
/// <summary> /// 连接开启摄像头 /// </summary> private void CameraConn() { videoSource = new VideoCaptureDevice(videoDevices[comboBox1.SelectedIndex].MonikerString); //videoSource.DesiredFrameSize = new Size(640, 480); videoSource.DesiredFrameSize = new Size(int.Parse(textBox1.Text), int.Parse(textBox2.Text)); //videoSource.DesiredFrameRate = 10000; //videoSource.VideoCapabilities[0].MaxFrameRate = 1; videPlayer.VideoSource = videoSource; videPlayer.Start(); videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame); }
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(); } } }
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; }
//视频源选择下拉框选择之后的响应函数 private void comboBox_camera_SelectedIndexChanged(object sender, EventArgs e) { int selected_index = this.comboBox_camera.SelectedIndex; this.videoSource = new VideoCaptureDevice(videoDevices[selected_index].MonikerString); // set NewFrame event handler videoSource.NewFrame += new NewFrameEventHandler(show_video); videoSource.Start(); videoSourcePlayer.VideoSource = videoSource; videoSourcePlayer.Start(); this.label5.Text = "连接中..."; this.label5.Visible = true; isshowed = true; }
/// <summary> /// 连接摄像头 /// </summary> /// <param name="videoResolutionIndex"></param> /// <param name="snapshotResolutionIndex"></param> public void Connect(int videoResolutionIndex = 0, int snapshotResolutionIndex = 0) { videoDevice.ProvideSnapshots = true; videoDevice.SnapshotResolution = snapshotCapabilities[snapshotResolutionIndex]; videoDevice.SnapshotFrame += VideoDevice_SnapshotFrame; if (videoSourcePlayer != null) { videoSourcePlayer.VideoSource = videoDevice; videoSourcePlayer.Start(); } OnConnect?.Invoke(); }
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 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( ); }
private void OpenVideoSource(IVideoSource source) { Cursor = Cursors.WaitCursor; CloseCurrentVideoSource(); VideoSourcePlayer.VideoSource = source; VideoSourcePlayer.Start(); stopWatch = null; Timer.Start(); Cursor = Cursors.Default; }
private void openCapture() { this.videoSourcePlayer = new AForge.Controls.VideoSourcePlayer(); this.videoSource = new VideoCaptureDevice(); this.writer = new VideoFileWriter(); //设置视频来源 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; //注释掉,选择摄像头来源的时候才会才会触发显示摄像头信息 int selected_index = 0; this.videoSource = new VideoCaptureDevice(videoDevices[selected_index].MonikerString); // set NewFrame event handler videoSource.NewFrame += new NewFrameEventHandler(show_video); videoSource.Start(); videoSourcePlayer.VideoSource = videoSource; videoSourcePlayer.Start(); isOpen = true; } catch (ApplicationException) { videoDevices = null; MessageBox.Show("没有找到摄像头设备", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } tick_num = 0; //秒表 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; }
public override bool StartScanner() { colorPendingForSave = false; depthPendingForSave = false; //prepareSave = false; isScanning = true; if (this.DevicesDepth.Count == 0) { System.Windows.Forms.MessageBox.Show("No Scanner connected to computer"); return(false); } else { VideoCaptureDevice videoCaptureDepth = this.DevicesDepth[ScannerID]; videoSourcePlayerDepth = new VideoSourcePlayer(); videoSourcePlayerDepth.VideoSource = videoCaptureDepth; // SetFrameSize(videoCaptureDepth, this.depthFrameSize); videoCaptureDepth.SourceType = VideoSourceType.Depth; videoCaptureDepth.NewFrame += new AForge.Video.NewFrameEventHandler(OnNewFrameDepth); videoSourcePlayerColor = new VideoSourcePlayer(); VideoCaptureDevice videoCaptureColor = this.DevicesColor[ScannerID]; videoSourcePlayerColor.VideoSource = videoCaptureColor; videoCaptureColor.NewFrame += new AForge.Video.NewFrameEventHandler(OnNewFrameColor); SetFrameSize(videoCaptureColor, this.colorFrameSize); // videoSource1.DesiredPixelFormat = System.Drawing.Imaging.PixelFormat.Format8bppIndexed; videoSourcePlayerColor.Start(); videoSourcePlayerDepth.Start(); // reset stop watch stopWatch = null; // start timer timer.Start(); return(true); } }
// Open video source private void OpenVideoSource(IVideoSource source, VideoSourcePlayer videoSourcePlayer) { // set busy cursor this.Cursor = Cursors.WaitCursor; // close previous video source CloseVideoSource(); // start new video source videoSourcePlayer.VideoSource = source; videoSourcePlayer.Start(); // reset statistics statIndex = statReady = 0; videoSource = source; this.Cursor = Cursors.Default; currentplayer = videoSourcePlayer; }
private void button4_Click(object sender, EventArgs e) { timer1.Enabled = true; // conseguir todos los dispositivos de video this.ColeccionDisp = new FilterInfoCollection(FilterCategory.VideoInputDevice); // desplegar dispositivos en el combo foreach (FilterInfo disp in ColeccionDisp) { comboBox1.Items.Add(disp.Name); } comboBox1.SelectedIndex = 0; // conseguir el control de video del form VideoSourcePlayer Reproductor = (VideoSourcePlayer)this.panel2.Controls["ControlVideo"]; Reproductor.VideoSource = new VideoCaptureDevice(this.ColeccionDisp[comboBox1.SelectedIndex].MonikerString); Reproductor.Start(); }
private void OpenVideoSource(IVideoSource source) { // set busy cursor this.Cursor = Cursors.WaitCursor; // stop current video source // CloseCurrentVideoSource(); // start new video source // videoSourcePlayer1.VideoSource = source; //videoSourcePlayer1.Start(); pla.VideoSource = source; pla.Start(); // reset stop watch // stopWatch = null; // start timer //timer.Start(); this.Cursor = Cursors.Default; }
/// <summary> /// 设置使用的摄像头设备 /// </summary> /// <param name="index">设备在CameraDevices中的索引</param> /// <returns><see cref="bool"/></returns> public static bool SetCameraDevice(int index) { if (!isSet) { _isDisplay = false; } //无设备,返回false if (CameraDevices.Count <= 0 || index < 0) { return(false); } if (index > CameraDevices.Count - 1) { return(false); } // 设定初始视频设备 div = new VideoCaptureDevice(CameraDevices[index].MonikerString); sourcePlayer.VideoSource = div; div.Start(); sourcePlayer.Start(); return(true); }
public void ValidateDection() { _path = Path.GetTempPath(); Console.WriteLine("Motion Detector"); Console.WriteLine("Detects motion in the integrated laptop webcam"); Console.WriteLine("Threshold level: " + _motionAlarmLevel); _motionDetector = new MotionDetector(new TwoFramesDifferenceDetector(), new MotionAreaHighlighting()); if (new FilterInfoCollection(FilterCategory.VideoInputDevice).Count > 0) { var videoDevice = new FilterInfoCollection(FilterCategory.VideoInputDevice)[0]; var videoCaptureDevice = new VideoCaptureDevice(videoDevice.MonikerString); videoSourcePlayer = new VideoSourcePlayer(); videoSourcePlayer.NewFrame += VideoSourcePlayer_NewFrame; videoSourcePlayer.VideoSource = new AsyncVideoSource(videoCaptureDevice); videoSourcePlayer.Start(); } }
// Open video source public static void OpenVideoSource(Control control, VideoSourcePlayer videoSourcePlayer, IVideoSource source, Timer timer, out Stopwatch stopWatch) { // set busy cursor control.Cursor = Cursors.WaitCursor; // stop current video source CloseCurrentVideoSource(videoSourcePlayer); // start new video source videoSourcePlayer.VideoSource = source; videoSourcePlayer.Start(); // reset stop watch stopWatch = null; // start timer timer.Start(); control.Cursor = Cursors.Default; }
private void OpenVideoSource(VideoCaptureDevice device) { // Close Old Video Source and writer if (videoSourcePlayer.IsRunning) { videoSourcePlayer.Stop(); } CloseVideoSource(); // Close the writer if it is already open so it can be re-opened with the new source if (vwriter != null && vwriter.IsOpen) { vwriter.Close(); } // Open New Video Source videoSourcePlayer.VideoSource = device; videoSourcePlayer.Start(); // Create new video file // Video file is .avi file. Title has "M-Fly Flight Video" followed by date and time vwriter = new VideoFileWriter(); vwriter.Open("M-Fly Flight Video " + DateTime.Now.ToString("yyyy MMMM dd hh mm") + ".avi", device.VideoResolution.FrameSize.Width, device.VideoResolution.FrameSize.Height, device.VideoResolution.AverageFrameRate); }
private void startToolStripMenuItem_Click(object sender, EventArgs e) { FrmSelectWebcam webcam = new FrmSelectWebcam(); if (DialogResult.OK == webcam.ShowDialog(this)) { VideoCaptureDevice videoSource = new VideoCaptureDevice(webcam.device); this.videoPlayer.AutoSizeControl = true; videoPlayer.VideoSource = (IVideoSource)videoSource; videoPlayer.Start(); this.startDrawingToolStripMenuItem.Enabled = true; Thread.Sleep(100); /* * this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); * this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); * this.SuspendLayout(); * this.ResumeLayout(true); * */ } }