public void start() { if (captureSource == null) { // Create the VideoRecorder objects. captureSource = new CaptureSource(); fileSink = new FileSink(); videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); // Add eventhandlers for captureSource. captureSource.CaptureFailed += new EventHandler<ExceptionRoutedEventArgs>(OnCaptureFailed); // Initialize the camera if it exists on the device. if (videoCaptureDevice != null) { // Create the VideoBrush for the viewfinder. videoRecorderBrush = new VideoBrush(); videoRecorderBrush.SetSource(captureSource); videoRecorderBrush.RelativeTransform = new CompositeTransform() { CenterX = 0.5, CenterY = 0.5, Rotation = 90 }; viewfinderRectangle.Fill = videoRecorderBrush; // Start video capture and display it on the viewfinder. captureSource.Start(); System.Diagnostics.Debug.WriteLine("Started"); _isRunning = true; } } }
public Form1() :base("GDI Video", 10, 10, 640, 480) { // Show a dialog box on the screen so the user // can select which camera to use if they have // multiple attached. CaptureDeviceDescription capDescription = new CaptureDeviceDescription(); CameraSelection camForm = new CameraSelection(); camForm.ShowDialog(); //// Get the chosen configuration from the dialog //// and use it to create a capture device. object config = camForm.SetupPage.GetConfiguration(); m_CaptureDevice = (VideoCaptureDevice)capDescription.CreateVideoSource(config); // Another way to get a hold of a capture device //m_CaptureDevice = VideoCaptureDevice.CreateCaptureDeviceFromIndex(0, 320, 240); m_CamControl = new CameraControl(m_CaptureDevice); //Console.WriteLine("Capabilities: {0}", m_CaptureDevice.Capabilities.Count); // Let the capture device know what function to call // whenever a frame is received. m_CaptureDevice.NewFrame += OnFrameReceived; // Start the capture device on its own thread m_CaptureDevice.Start(); fStick = new Joystick(winmm.JOYSTICKID1); dispatcher = new TimedDispatcher(1.0 / 2, OnJoystickDispatch, null); dispatcher.Start(); }
void InitializeVideoRecorder(Rectangle viewfinderRectangle) { if (captureSource == null) { // Create the VideoRecorder objects. captureSource = new CaptureSource(); fileSink = new FileSink(); videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); // Add eventhandlers for captureSource. captureSource.CaptureFailed += new EventHandler<ExceptionRoutedEventArgs>(OnCaptureFailed); // Initialize the camera if it exists on the device. if (videoCaptureDevice != null) { // Create the VideoBrush for the viewfinder. videoRecorderBrush = new VideoBrush(); videoRecorderBrush.SetSource(captureSource); // Display the viewfinder image on the rectangle. viewfinderRectangle.Fill = videoRecorderBrush; // Start video capture and display it on the viewfinder. captureSource.Start(); } else { // A camera is not supported on this device } } }
public SilverlightWebcamService() { captureSource = new CaptureSource(); captureSource.CaptureImageCompleted += (o, e) => { if (CaptureImageCompleted != null) CaptureImageCompleted(this, e); }; webcam = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); }
public CaptureDevice(VideoCaptureDevice device) { _device = device; lock(this.GetType()) { if (!sources.ContainsKey(device)) { sources[_device] = new CaptureSource {VideoCaptureDevice = device}; } } }
public VideoSender(int deviceIndex, PayloadChannel channel) { fChannel = channel; fImageStream = new MemoryStream(1024); fCamera = VideoCaptureDevice.CreateCaptureDeviceFromIndex(0, -1, -1); PrintCamera(fCamera); fCamera.NewFrame += new CameraEventHandler(ReceiveFrameFromCamera); }
void PrintCamera(VideoCaptureDevice device) { List<VideoCapability> caps = fCamera.Capabilities; foreach (VideoCapability vCap in caps) { Console.WriteLine("Major Type: {0} - {1}", vCap.MajorTypeString, vCap.SubTypeString); Console.WriteLine(" Input Size: {0}", vCap.InputSize); Console.WriteLine(" Frame Size: {0} - {1}", vCap.MinFrameSize, vCap.MaxFrameSize); Console.WriteLine(" Frame Rate: {0} - {1}", vCap.MinFrameRate, vCap.MaxFrameRate); Console.WriteLine(""); } }
private void DisposeVideoRecorder() { if (_captureSource != null) { if (_captureSource.VideoCaptureDevice != null && _captureSource.State == CaptureState.Started) _captureSource.Stop(); _captureSource.CaptureFailed -= OnCaptureSourceOnCaptureFailed; _captureSource = null; _videoCaptureDevice = null; _fileSink = null; _videoBrush = null; } }
public void InitializeVideoRecorder() { try { //fileName = string.Format(@"\Purposecode\Video{0}.mp4", DateTime.Now.ToString("yyyyMMddHHmmss")); fileName = string.Format("Video{0}.mp4", DateTime.Now.ToString("yyyyMMddHHmmss")); if (captureSource == null) { // Create the VideoRecorder objects. captureSource = new CaptureSource(); fileSink = new FileSink(); videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); // Add eventhandlers for captureSource. captureSource.CaptureFailed += new EventHandler<ExceptionRoutedEventArgs>(OnCaptureFailed); // Initialize the camera if it exists on the device. if (videoCaptureDevice != null) { // Create the VideoBrush for the viewfinder. videoRecorderBrush = new VideoBrush(); videoRecorderBrush.SetSource(captureSource); // Display the viewfinder image on the rectangle. viewfinderRectangle.Fill = videoRecorderBrush; StopPlaybackRecording.IsEnabled = false; // Start video capture and display it on the viewfinder. captureSource.Start(); // Set the button state and the message. UpdateUI(ButtonState.Initialized, "Tap record to start recording..."); } else { // Disable buttons when the camera is not supported by the device. UpdateUI(ButtonState.CameraNotSupported, "Camera is not supported.."); } } } catch (Exception ex) { var test = ex.Message; } } //InitializeVideoRecorder()
protected override void OnNavigatedFrom(NavigationEventArgs e) { if (captureSource != null) { captureSource.CaptureImageCompleted -= captureSource_CaptureImageCompleted; if (captureSource.VideoCaptureDevice != null && captureSource.State == CaptureState.Started) { captureSource.Stop(); } captureSource = null; fileSink = null; videoCaptureDevice = null; } base.OnNavigatedFrom(e); }
public override void AddedToDocument(GH_Document document) { frameHandler = new NewFrameEventHandler(video_NewFrame); bitmap = null; // enumerate video devices FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); // create video source videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString); videoSource.VideoResolution = videoSource.VideoCapabilities[0]; // set NewFrame event handler videoSource.NewFrame += frameHandler; // start the video source videoSource.Start(); // ... // signal to stop when you no longer need capturing //videoSource.SignalToStop(); // ... base.AddedToDocument(document); }
private void button1_Click(object sender, EventArgs e) { if (cbx_mayanh.Text != "") { cam = new VideoCaptureDevice(dscamera[cbx_mayanh.SelectedIndex].MonikerString); //Initialize the capture device grabber = new Capture(kiemtra(cbx_mayanh.Text)); grabber.QueryFrame(); //Initialize the FrameGraber event Application.Idle += new EventHandler(FrameGrabber); button1.Enabled = false; cohieu = true; cbx_mayanh.Enabled = false; button1.Visible = false; btn_dung.Visible = true; btn_tieptuc.Visible = true; button2.Visible = true; } }
private void RSI_Load(object sender, EventArgs e) { //加载所有摄像头 //FilterCategory.VideoInputDevice视频输入设备类别7 this.videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);//实例化过滤类 //打开该摄像头 if (null != cameraDevice) { videoSourcePlayer1.SignalToStop(); videoSourcePlayer1.WaitForStop(); } //实例化视频源抓取类 cameraDevice = new VideoCaptureDevice(this.videoDevices[0].MonikerString);//连接摄像头 //cameraDevice.DesiredFrameSize = new Size(320, 240); //cameraDevice.DesiredFrameRate = 1; //把实例化好的cameraDevice类赋值到VideoSourcePlayer控件的VideoSource属性 videoSourcePlayer1.VideoSource = cameraDevice; videoSourcePlayer1.Start(); }
// ----- Live private void RunCameraAndGetLiveImage() { webcam = new FilterInfoCollection(FilterCategory.VideoInputDevice); StopCam(); cam = new VideoCaptureDevice(webcam[0].MonikerString); cam.NewFrame += Cam_NewFrame; // cam.VideoResolution = cam.VideoCapabilities[3]; if (cam != null) { if (cam.IsRunning == false) { cam.Start(); //kamerayı başlatıyoruz. } } //yüklenirken görüntü akışı alınmaya başlanıyor _timer.Interval = 200; //timer'in tick olayının çalışması için gereken süre (ms) _timer.Enabled = true; //timer varsayılan olarak devre dışı halde olur, program açılışında etkindeştiriyoruz }
void Start() { try { foreach (KeyValuePair <VideoSourcePlayer, string> vp in players) { VideoCaptureDevice videoSource = new VideoCaptureDevice(vp.Value); OpenVideoSource(videoSource, vp.Key); } // open it buttonItem1.Enabled = true; buttonItem2.Enabled = true; } catch { } finally { } }
public static void HandleGetWebcams(GetWebcams command, Client client) { var deviceInfo = new Dictionary <string, List <Size> >(); var videoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); foreach (FilterInfo videoCaptureDevice in videoCaptureDevices) { List <Size> supportedResolutions = new List <Size>(); var device = new VideoCaptureDevice(videoCaptureDevice.MonikerString); foreach (var resolution in device.VideoCapabilities) { supportedResolutions.Add(resolution.FrameSize); } deviceInfo.Add(videoCaptureDevice.Name, supportedResolutions); } if (deviceInfo.Count > 0) { new GetWebcamsResponse(deviceInfo).Execute(client); } }
private void button1_Click(object sender, EventArgs e) { if (button1.Text == "打开摄像头") { videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); videoSource = new VideoCaptureDevice(videoDevices[txtCamera.SelectedIndex].MonikerString);//连接摄像头 //videoSource.VideoResolution = videoSource.VideoCapabilities[txtCamera.SelectedIndex]; vspMember.VideoSource = videoSource; // set NewFrame event handler vspMember.Start(); button1.Text = "关闭摄像头"; } else { vspMember.SignalToStop(); vspMember.WaitForStop(); button1.Text = "打开摄像头"; } }
private void InitializeWebcam() { if (video_device_list.Count > 0) { video_device = new VideoCaptureDevice(video_device_list[videoSources.SelectedIndex].MonikerString); video_device.NewFrame += (s, args) => { var frame = args.Frame.Clone() as Bitmap; tokenBox.Image = frame; }; video_device.Start(); videoSources.Visible = true; tokenWebcamButton.Text = "Capture Frame"; } else { MessageBox.Show("No webcam found", "Shark Cage", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/*打开摄像头*/ private Boolean OpenCamera() { FilterInfoCollection m_videoDevices = this.GetCamList(); if (m_videoDevices.Count == 0) { return(false); } VideoCaptureDevice m_videoSource = new VideoCaptureDevice(m_videoDevices[0].MonikerString); m_videoSource.DesiredFrameRate = 1; m_videoSource.DesiredFrameSize = new System.Drawing.Size(320, 240); this.sourcePlayer.NewFrame += new AForge.Controls.VideoSourcePlayer.NewFrameHandler(sourcePlayer_NewFrame); this.sourcePlayer.VideoSource = m_videoSource; this.sourcePlayer.Start(); m_OpenTime = DateTime.Now; return(true); }
private void Form1_Load(object sender, EventArgs e) { FilterInfoCollection fic = new FilterInfoCollection(FilterCategory.VideoInputDevice); videoDevice = new VideoCaptureDevice(fic[0].MonikerString); videoDevice.DisplayPropertyPage(IntPtr.Zero); videoDevice.NewFrame += VideoDevice_NewFrame; videoDevice.Start(); baiduAi = FaceAi.GetInstance(); voiceAi = VoiceAi.GetInstance(); Thread mythread = new Thread(ThreadMain); mythread.Start(); string voiceFilePath = voiceAi.Tts("百度AI"); voiceAi.Play(voiceFilePath); }
private void frmRegistroVisitantes_Load(object sender, EventArgs e) { Conectar(); if (f.fb == true) { BtNuevo_Click_1(null, null); f.fb = false; } if (existenDispositivos) { fuenteDeVideo = new VideoCaptureDevice(dispositivosDeVideo[0].MonikerString); fuenteDeVideo.NewFrame += new NewFrameEventHandler(MostrarImagen); fuenteDeVideo.Start(); } else { MessageBox.Show("No se encuentra nngun dispostivo de video en el sistema", "Información", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); CerrarFormulario(); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (captureSource == null) { captureSource = new CaptureSource(); captureSource.CaptureImageCompleted += captureSource_CaptureImageCompleted; fileSink = new FileSink(); videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); if (videoCaptureDevice != null) { videoBrush.SetSource(captureSource); videoBrush.RelativeTransform = new CompositeTransform() { CenterX = 0.5, CenterY = 0.5, Rotation = 90 }; captureSource.Start(); } } }
////////////////////////////////////////////////////////////////////////////////////////////////////////////// void ConnectLocalCamera() { if (cbWebcam.Items.Count == 0 || cbWebcam.SelectedIndex == -1) { return; } if (m_videoSource != null) { m_videoSource.Stop(); } else { FilterInfoCollection videosources = new FilterInfoCollection(FilterCategory.VideoInputDevice); m_videoSource = new VideoCaptureDevice(videosources[cbWebcam.SelectedIndex].MonikerString); } m_videoSource.NewFrame += new NewFrameEventHandler(OnCameraFrame); m_videoSource.Start(); btnSnapshot.Visibility = Visibility.Visible; }
private AForgeCapture(string name, string deviceMoniker) { this.Name = name; this.Uuid = deviceMoniker; var width = Picture.Width; var height = Picture.Height; device = new VideoCaptureDevice(deviceMoniker); var caps = device.VideoCapabilities .Where(c => c.FrameSize.Width == width && c.FrameSize.Height == height) .OrderByDescending(c => c.FrameSize.Width * c.FrameSize.Height * c.MaxFrameRate).First(); this.Width = caps.FrameSize.Width; this.Height = caps.FrameSize.Height; device.DesiredFrameRate = caps.MaxFrameRate; device.DesiredFrameSize = caps.FrameSize; device.NewFrame += new NewFrameEventHandler(OnNewFrameEvent); device.Start(); }
private void button1_Click(object sender, EventArgs e) { if (button1.Text == "打开") { comboBox2.Enabled = false; this.button1.Text = "关闭"; this.device = new VideoCaptureDevice(this.cameraDict[comboBox1.SelectedItem.ToString()]); this.device.NewFrame += new NewFrameEventHandler(videoNewFrame); this.device.DesiredFrameSize = new Size(CameraWidth, CameraHeight); device.Start(); //Start Device } else { comboBox2.Enabled = true; this.StopCamera(); button1.Text = "打开"; this.pictureBox1.Image = null; } }
public VideoCaptureDevice ConnectVideo() { if (videoDevies.Count <= 0) { return(null); } if (this.comboBox1.SelectedIndex == -1) { MessageBox.Show("请选择一个设备!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } int deviceIndex = this.comboBox1.SelectedIndex; videoSource = new VideoCaptureDevice(videoDevies[deviceIndex].MonikerString); videoSource.DesiredFrameRate = 1; videoSource.DesiredFrameSize = new System.Drawing.Size(this.pictureBox1.Width, this.pictureBox1.Height); videoSource.Start(); return(videoSource); }
private void FrmScaner_Load(object sender, EventArgs e) { btnCheck.Visible = false; label1.Visible = true; comboBox1.Visible = true; pictureBox1.Visible = false; btnLog.Visible = true; CaptureDevice = new FilterInfoCollection(FilterCategory.VideoInputDevice); foreach (FilterInfo Device in CaptureDevice) { comboBox1.Items.Add(Device.Name); } comboBox1.SelectedIndex = 0; FinalFrame = new VideoCaptureDevice(); FinalFrame = new VideoCaptureDevice(CaptureDevice[comboBox1.SelectedIndex].MonikerString); FinalFrame.NewFrame += new NewFrameEventHandler(FinalFrame_NewFrame); FinalFrame.Start(); }
//-------------------------------------------------- // カメラ処理 //-------------------------------------------------- /// <summary> /// カメラのデバイス初期化 /// </summary> private bool InitVideoDevice() { try { // デバイス一覧取得 FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); // 使えるデバイスチェック if (videoDevices.Count == 0) { // 使えるデバイス無し MessageBox.Show(QRFormMessage.QR_0001); // カメラデバイスの初期化失敗 return(false); } else { if (VideoSource == null) { // 一旦最初の1つを使用することとする VideoSource = new VideoCaptureDevice(videoDevices[0].MonikerString); // フレームごとに呼ばれるイベントに登録 VideoSource.NewFrame += new NewFrameEventHandler(VideoRendering); } // 一旦ストップ処理を行う VideoCaptureStop(); // QR読取り初期設定 QRCordRead(); } } catch { throw; } return(true); }
public void Start(int Idx) { if (videosources == null) { return; } if (Idx >= videosources.Count) { return; } //For example use first video device. You may check if this is your webcam. VCD = new VideoCaptureDevice(videosources[Idx].MonikerString); try { //Check if the video device provides a list of supported resolutions if (VCD.VideoCapabilities.Length > 0) { string highestSolution = "0;0"; //Search for the highest resolution for (int i = 0; i < VCD.VideoCapabilities.Length; i++) { if (VCD.VideoCapabilities[i].FrameSize.Width > Convert.ToInt32(highestSolution.Split(';')[0])) { highestSolution = VCD.VideoCapabilities[i].FrameSize.Width.ToString() + ";" + i.ToString(); } } //Set the highest resolution as active VCD.VideoResolution = VCD.VideoCapabilities[Convert.ToInt32(highestSolution.Split(';')[1])]; } } catch { } //Create NewFrame event handler //(This one triggers every time a new frame/image is captured VCD.NewFrame += new AForge.Video.NewFrameEventHandler(videoSource_NewFrame); //Start recording VCD.Start(); }
private void Form1_Load(object sender, EventArgs e) { if (searchFace.Visible == true) { searchFace.Visible = false; } try { // 枚举所有视频输入设备 videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); if (videoDevices.Count == 0) { throw new ApplicationException(); } foreach (FilterInfo device in videoDevices) { tscbxCameras.Items.Add(device.Name); VideoCaptureDevice videoSource = new VideoCaptureDevice(device.MonikerString); foreach (VideoCapabilities videoResolution in videoSource.VideoCapabilities) { string info = videoResolution.FrameSize.Width + "*" + videoResolution.FrameSize.Height; if (resolutionBox.Items.Count == 0 || !resolutionBox.Items.Contains(info)) { resolutionBox.Items.Add(info); } } } resolutionBox.SelectedIndex = 0; tscbxCameras.SelectedIndex = 0; userBox.SelectedIndex = 0; } catch (ApplicationException) { tscbxCameras.Items.Add("No local capture devices"); videoDevices = null; userBox.SelectedIndex = 1; } loadFaceData(); }
private void StartStop_button_Click(object sender, EventArgs e) { scans.Clear(); //очищаем коллекцию сканов //запускаем поток установки флага сканирования Task.Factory.StartNew(() => { while (!isExit) { isCan = true; Thread.Sleep(1000); } }); if (!StartClickState) { // start camera stream videoSource = new VideoCaptureDevice(videoDevice[Device_listBox.SelectedIndex].MonikerString); videoSource.NewFrame += new NewFrameEventHandler(stream); videoSource.Start(); StartStop_button.Text = "Stop scan"; StartClickState = true; } else { //флаг закрытия потока isExit = true; if (videoSource != null) { // stop camera stream videoSource.SignalToStop(); videoSource.WaitForStop(); StartClickState = false; StartStop_button.Text = "Start scan"; Stream_pictureBox.Image = null; QrDecode_textBox.Text = null; } } }
private void frmCapturarFoto_Load(object sender, EventArgs e) { //btnGuardarFoto.Enabled = false; //btnActivarCamara.Enabled = false; lblNombre.Text = Nombre_Empleado.ToString(); // Cargamos los dispositivos de video ListaDispositivos = new FilterInfoCollection(FilterCategory.VideoInputDevice); if (ListaDispositivos.Count > 0) { // Y por cada dispositivo detectado, lo agregamos a un combobox (ahora ya no es visible para el usuario) foreach (FilterInfo Dispositivo in ListaDispositivos) { cmbDispositivos.Items.Add(Dispositivo.Name); } // Seleccionamos el primer dispositivo cmbDispositivos.SelectedIndex = 0; // Inicializamos el dispositivo FrameFinal = new VideoCaptureDevice(); // Y creamos el handler para comenzar a hacer el stream de video try { FrameFinal = new VideoCaptureDevice(ListaDispositivos[cmbDispositivos.SelectedIndex].MonikerString); FrameFinal.NewFrame += FrameFinal_NewFrame; FrameFinal.Start(); } catch (Exception ex) { MessageBox.Show("Error " + ex.Message); } } else { frmListaEmpleados listaEmpleados = new frmListaEmpleados(); listaEmpleados.MessageBoxShow("Conecte el Dispositivo", "Alerta"); this.Close(); } }
public Webcam(String name, VideoCaptureDevice cam) { this.camera = cam; this.src = new CaptureSource(); this.lastImageTaken = DateTime.Now; this.nextImgName = ""; this.nextImgNum = 0; try { // if we found a camera and successfully connected if (camera != null) { // set the camera to its maximum resolution (allow choice in future?) camera.DesiredFormat = (from VideoFormat f in camera.SupportedFormats orderby f.PixelWidth * f.PixelHeight descending select f).FirstOrDefault<VideoFormat>(); // reset the preview source CaptureSource source = new CaptureSource(); // set the global CaptureSource to the selected camera source.VideoCaptureDevice = camera; source.AudioCaptureDevice = null; // set the callback function for this camera's async capture source.CaptureImageCompleted += new EventHandler<CaptureImageCompletedEventArgs>(_src_srcImageCompleted); this.src = source; src.Start(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); throw new Exception("Prepare source failed: " + ex.ToString()); } }
private void btnSwitch_Click(object sender, EventArgs e) { // chuyển đổi sang quét mã barcode if (panelChoose.Visible == true) { panelChoose.Visible = false; panelScan.Visible = true; picBarCode.Visible = true; btnSwitch.Text = "Chuyển đổi sang chọn thủ công"; filterInfoCollection = new FilterInfoCollection(FilterCategory.VideoInputDevice); foreach (FilterInfo device in filterInfoCollection) { if (device.Name != null) { nameDevice = device.Name; } } videoCaptureDevice = new VideoCaptureDevice(filterInfoCollection[0].MonikerString); videoCaptureDevice.NewFrame += VideoCaptureDevice_NewFrame; videoCaptureDevice.Start(); timer1.Start(); } else // chuyển đổi sang chọn thủ công { if (videoCaptureDevice != null) { if (videoCaptureDevice.IsRunning) { videoCaptureDevice.Stop(); } } panelChoose.Visible = true; panelScan.Visible = false; picBarCode.Visible = false; btnSwitch.Text = "Chuyển đổi sang quét mã BarCode"; } }
/// <summary> /// Пробуем инициализировать камеру с заданным моникером. Если не найдена такая камера - используется первая в системе. /// </summary> /// <param name="moniker"></param> /// <returns></returns> public bool TryInitCamera(string moniker) { var camMoniker = string.IsNullOrEmpty(moniker) ? string.Empty : moniker; IsCameraConfigured = false; try { // Пробуем найти такую камеру в устройствах var resultCam = _camList?.Find(x => x.MonikerString.Equals(camMoniker)); _monikerString = (resultCam == null) ? _camList?.FirstOrDefault()?.MonikerString : resultCam.MonikerString; if (string.IsNullOrEmpty(_monikerString)) { return(false); } CaptureDevice = new VideoCaptureDevice(_monikerString); // Подписываемся на получение нового фрейма if (CaptureDevice != null) { IsCameraConfigured = true; // CaptureDevice.NewFrame -= ImageRecievedUpdater; CaptureDevice.NewFrame += ImageRecievedUpdater; if (!CaptureDevice.IsRunning) { CaptureDevice.Start(); } } } catch (Exception e) { CaptureDevice.NewFrame -= ImageRecievedUpdater; MessageBox.Show(e.Message + @" line 236 " + typeof(AforgeWraper)); } return(true); }
// Collect supported video and snapshot sizes private void EnumeratedSupportedFrameSizes(VideoCaptureDevice videoDevice) { this.Cursor = Cursors.WaitCursor; videoResolutionsCombo.Items.Clear( ); snapshotResolutionsCombo.Items.Clear( ); try { videoCapabilities = videoDevice.VideoCapabilities; snapshotCapabilities = videoDevice.SnapshotCapabilities; foreach (VideoCapabilities capabilty in videoCapabilities) { videoResolutionsCombo.Items.Add(string.Format("{0} x {1}", capabilty.FrameSize.Width, capabilty.FrameSize.Height)); } foreach (VideoCapabilities capabilty in snapshotCapabilities) { snapshotResolutionsCombo.Items.Add(string.Format("{0} x {1}", capabilty.FrameSize.Width, capabilty.FrameSize.Height)); } if (videoCapabilities.Length == 0) { videoResolutionsCombo.Items.Add("Not supported"); } if (snapshotCapabilities.Length == 0) { snapshotResolutionsCombo.Items.Add("Not supported"); } videoResolutionsCombo.SelectedIndex = 0; snapshotResolutionsCombo.SelectedIndex = 0; } finally { this.Cursor = Cursors.Default; } }
/** * Iitialize the camera capturing class */ public CameraImaging() { // First obtain all the video captering devices VideoCapturingDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); // Go through and obtain all said devices Console.WriteLine("VIDEO CAPTURING DEVICES"); foreach (FilterInfo VideoCapturingDevice in VideoCapturingDevices) { //Print them out Console.WriteLine(VideoCapturingDevice.Name.ToString()); } Console.WriteLine(""); // Try to see if you can enable the first camera try { VideoCaptureDevice FileVideoSource = new VideoCaptureDevice(VideoCapturingDevices[0].MonikerString); } catch { // If not print NO WEBCAMS :0 Console.WriteLine("NO WEBCAMS :0"); return; } bitmap = null; // Set the first webcam to the main capturing device FileVideoSource = new VideoCaptureDevice(VideoCapturingDevices[0].MonikerString); //Start the webcam up FileVideoSource.Start(); //Obtain a Frame GOTO video_NewFrame() FUNCTION FileVideoSource.NewFrame += new NewFrameEventHandler(video_NewFrame); //Due to the fact that the camera has a start up time, we have to wait until //the frame has been captured then stop the camera. So first make sure the bitmap is null //Wait until the frame has been captured // THen stop the Camera }
//连接摄像头 private void OpenCam() { if (tscbxCameras == "未发现摄像头") { MessageBox.Show("未发现摄像头", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString); if (videoSource.VideoCapabilities.Count() == 0) { return; } int D = videoSource.VideoCapabilities.Length; Capabilities = videoSource.VideoCapabilities[D - 1].FrameSize.Height + "*" + videoSource.VideoCapabilities[D - 1].FrameSize.Width; videoSource.VideoResolution = videoSource.VideoCapabilities[D - 1]; videoSourcePlayer.VideoSource = videoSource; videoSourcePlayer.Start(); FSizeChanged(); track.Value = (int)(20 * 0.8); //初始化选框大小调整滑块 //根据pictureBox控件尺寸调整矩形选框尺寸,保证选框始终在pictureBox控件内部 int Width = (int)(videoSourcePlayer.Width * 0.8f); int Height = Width * 400 / 300; if (Height > videoSourcePlayer.Height) { Height = (int)(videoSourcePlayer.Height * 0.8f); Width = Height * 300 / 400; } int Top = (videoSourcePlayer.Width - Width) / 2; int Left = (videoSourcePlayer.Height - Height) / 2; m_Rect = new Rectangle(Top, Left, Width, Height); //初始化矩形裁剪选框 videoSourcePlayer.Invalidate(); //重绘pictureBox控件,触发paint事件 }
/// <summary> /// function to initiate inner cam feed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RecordInnerCamFeed_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(SerialNo.Text)) { MessageBox.Show("Enter serial number"); } else { try { if (recInnerVdo != null) { RecordInnerCamFeed.Content = "Record cam feed"; recInnerVdo?.StopRecording(); recInnerVdo = null; } else { if (CheckAlreadyExisting()) { outerVdoSource?.Stop(); outerVdoSource = null; } if (recInnerVdo == null || !recInnerVdo.RecordingStarted()) { recInnerVdo = new VideoRecorder(); recInnerVdo.SerialNumber = SerialNo.Text; } var videoDevicesList = new FilterInfoCollection(FilterCategory.VideoInputDevice); innerVdoSource = new VideoCaptureDevice(videoDevicesList[vdoInnerDeviceList.SelectedIndex].MonikerString); innerVdoSource.NewFrame += new NewFrameEventHandler(innervideo_NewFrame); innerVdoSource.Start(); RecordInnerCamFeed.Content = "Recording... (Click to stop)"; } } catch (Exception ex) { RecordInnerCamFeed.Content = "Record cam feed"; } } }
/// <summary> /// 摄像头初始化 /// </summary> public void InitCamera() { FRC.MainVM.CameraList.Clear(); FRC.MainVM.ResolutionList.Clear(); FilterInfoCollection = new FilterInfoCollection(FilterCategory.VideoInputDevice); //如果没有可用摄像头,“启用摄像头”按钮禁用,否则使可用 if (FilterInfoCollection.Count == 0) { return; } //添加相机 foreach (FilterInfo fi in FilterInfoCollection) { FRC.MainVM.CameraList.Add(fi.Name); } if (FRC.MainVM.SelectedCamera == null) { FRC.MainVM.SelectedCamera = FRC.MainVM.CameraList[0]; } int CameraIndex = FRC.MainVM.CameraList.IndexOf( FRC.MainVM.CameraList.SingleOrDefault(x => x == FRC.MainVM.SelectedCamera)); VideoCaptureDevice deviceVideo = new VideoCaptureDevice(FilterInfoCollection[CameraIndex].MonikerString); foreach (var resolution in deviceVideo.VideoCapabilities) { FRC.MainVM.ResolutionList.Add(resolution.FrameSize.Height + "*" + resolution.FrameSize.Width); } if (FRC.MainVM.SelectedResolution == null) { FRC.MainVM.SelectedResolution = FRC.MainVM.ResolutionList[0]; } FRC.MainVM.IsCameraEnable = FilterInfoCollection.Count > 0; FRC.MainVM.IsPGBtnEnable = false; //拍照录入 FRC.MainVM.IsSIBtnEnable = true; //选照录入 FRC.MainVM.IsPGIBtnEnable = false; //拍照识别 FRC.MainVM.IsSIIBtnEnable = true; //选照识别 }
private void cbxDispositivos_SelectionChangeCommitted(object sender, EventArgs e) { try { foto = 0; if (FuenteDeVideo.IsRunning) { TerminarFuenteDeVideo(); cbxDispositivos.Enabled = true; btnCamara.Enabled = false; btnGuardar.Enabled = false; pbxPerfil.Image = null; } if (ExisteDispositivo) { FuenteDeVideo = new VideoCaptureDevice(DispositivoDeVideo[cbxDispositivos.SelectedIndex].MonikerString); FuenteDeVideo.NewFrame += new NewFrameEventHandler(Video_NuevoFrame); FuenteDeVideo.Start(); //Estado.Text = "Ejecutando Dispositivo..." cbxDispositivos.Enabled = true; //groupBox1.Text = DispositivoDeVideo[cbxDispositivos.SelectedIndex].Name.ToString(); btnCamara.Enabled = true; btnGuardar.Enabled = false; } else { MessageBox.Show("¡No se encuentra el dispositivo!", "¡Problema!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { foto = 0; MessageBox.Show("Error: " + ex, "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void InitializeVideoRecorder() { if (_captureSource == null) { _captureSource = new CaptureSource(); _fileSink = new FileSink(); _videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); _captureSource.CaptureFailed += OnCaptureSourceOnCaptureFailed; _captureSource.CaptureImageCompleted += CaptureSourceOnCaptureImageCompleted; if (_videoCaptureDevice != null) { _videoBrush = new VideoBrush(); _videoBrush.SetSource(_captureSource); ViewFinderRectangle.Fill = _videoBrush; _captureSource.Start(); } } }
private void comboBoxcam_SelectedIndexChanged(object sender, EventArgs e) { //选择摄像头后 comboBoxreso.Items.Clear(); //先清理上次选择的摄像头支持的分辨率 //获取摄像头设备 FilterInfo filterInfo = CaptureDevices[comboBoxcam.SelectedIndex]; captureDevice = new VideoCaptureDevice(filterInfo.MonikerString); //获取所选择的摄像头分辨率列表并添加 videoCapabilities = captureDevice.VideoCapabilities; foreach (VideoCapabilities capabilitie in videoCapabilities) { comboBoxreso.Items.Add(capabilitie.FrameSize.Width.ToString() + "×" + capabilitie.FrameSize.Height.ToString()); } //选中默认分辨率 触发coBox_Resolution_SelectedIndexChanged() if (comboBoxreso.Items.Count > 0) { comboBoxreso.SelectedIndex = 0; } }
private void StartRecordDevice(string path) { this.streamDevice = new VideoCaptureDevice(videoDevices[sourceNumber].MonikerString); string fullName = string.Format(@"{0}\{1}_{2}.avi", path, Environment.UserName.ToUpper(), DateTime.Now.ToString("d_MMM_yyyy_HH_mm_ssff")); streamDevice.VideoResolution = streamDevice.VideoCapabilities[0]; writer.Open(fullName, streamDevice.VideoResolution.FrameSize.Width, streamDevice.VideoResolution.FrameSize.Height, (int)fps, (VideoCodec)videoCodec, (int)(BitRate)bitRate); this.streamDevice.NewFrame += new NewFrameEventHandler(this.NewFrame); isRecording = true; this.streamDevice.Start(); OnThreadLabelTimeEventStart(); }
public void StopRecording() { if (captureSource != null) { // Stop captureSource if it is running. if (captureSource.VideoCaptureDevice != null && captureSource.State == CaptureState.Started) { captureSource.Stop(); } // Remove the event handlers for capturesource and the shutter button. captureSource.CaptureFailed -= OnCaptureFailed; // Remove the video recording objects. captureSource = null; videoCaptureDevice = null; fileSink = null; videoRecorderBrush = null; } }
public CameraControl(VideoCaptureDevice vidDevice) { m_BaseFilter = vidDevice.BaseFilter; m_CameraControlInterface = (IAMCameraControl)m_BaseFilter; int valMin = 0; int valMax = 0; int valDefault = 0; int valStepping = 0; CameraControlFlags valFlags = CameraControlFlags.None; Controller.GetRange(CameraControlProperty.Pan, out valMin, out valMax, out valStepping, out valDefault, out valFlags); m_PanRange = new CamControlRange{Min = valMin, Max = valMax, Stepping = valStepping, Default = valDefault}; Controller.GetRange(CameraControlProperty.Tilt, out valMin, out valMax, out valStepping, out valDefault, out valFlags); m_TiltRange = new CamControlRange { Min = valMin, Max = valMax, Stepping = valStepping, Default = valDefault }; Controller.GetRange(CameraControlProperty.Roll, out valMin, out valMax, out valStepping, out valDefault, out valFlags); m_RollRange = new CamControlRange { Min = valMin, Max = valMax, Stepping = valStepping, Default = valDefault }; Controller.GetRange(CameraControlProperty.Zoom, out valMin, out valMax, out valStepping, out valDefault, out valFlags); m_ZoomRange = new CamControlRange { Min = valMin, Max = valMax, Stepping = valStepping, Default = valDefault }; }
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e) { capcam = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); capcam.DesiredFormat = capcam.SupportedFormats.First(f => f.PixelWidth == w); captureSource = new CaptureSource(); captureSource.VideoCaptureDevice = capcam; captureSource.Start(); sink = new FrameVideoSink(); sink.CaptureSource = captureSource; sink.OnFrameReady += sink_OnFrameReady; sink.Enabled = true; viewfinderBrush.SetSource(captureSource); viewfinderBrush.Stretch = Stretch.Fill; renderBmp = new WriteableBitmap(w, h); renderBrush.ImageSource = renderBmp; phocam = new PhotoCamera(); detector = new ColorDetector(w, h); }
public void InitializeVideoRecorder() { if (_captureSource == null) { // Create the VideoRecorder objects. _captureSource = new CaptureSource(); _fileSink = new FileSink(); _videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); // Add eventhandlers for captureSource. _captureSource.CaptureFailed += OnCaptureFailed; // Initialize the camera if it exists on the phone. if (_videoCaptureDevice != null) { // Create the VideoBrush for the viewfinder. _videoRecorderBrush = new VideoBrush(); _videoRecorderBrush.SetSource(_captureSource); // Display the viewfinder image on the rectangle. viewfinderRectangle.Fill = _videoRecorderBrush; // Start video capture and display it on the viewfinder. _captureSource.Start(); // Set the button state and the message. UpdateUI(ButtonState.Initialized, "Tap record to start recording..."); } else { // Disable buttons when the camera is not supported by the phone. UpdateUI(ButtonState.NoChange, "Camera Not Supported."); } } }
private void DisposeVideoRecorder() { try { if (captureSource != null) { if (captureSource.VideoCaptureDevice != null && captureSource.State == CaptureState.Started) { captureSource.Stop(); } captureSource.CaptureFailed -= OnCaptureFailed; captureSource = null; } videoCaptureDevice = null; fileSink = null; videoRecorderBrush = null; isoVideoFile = null; GC.Collect(); } catch (Exception ex) { var test = ex.Message; } }
/// <summary> /// Releases resources /// </summary> private void DisposeVideoRecorder() { if (captureSource != null) { if ((captureSource.VideoCaptureDevice != null) && (captureSource.State == CaptureState.Started)) { captureSource.Stop(); } captureSource = null; videoCaptureDevice = null; fileSink = null; videoRecorderBrush = null; } }
/// <summary> /// Initializes VideoRecorder /// </summary> public void InitializeVideoRecorder() { if (captureSource == null) { captureSource = new CaptureSource(); fileSink = new FileSink(); videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); if (videoCaptureDevice != null) { videoRecorderBrush = new VideoBrush(); videoRecorderBrush.SetSource(captureSource); viewfinderRectangle.Fill = videoRecorderBrush; captureSource.Start(); this.UpdateUI(VideoState.Initialized); } else { this.UpdateUI(VideoState.CameraNotSupported); } } }
/// <summary> /// 设置当前视频捕获设备 /// </summary> /// <param name="vcDevice"></param> public void SetVideoCaptureDevice(VideoCaptureDevice vcDevice) { _vcDevice = vcDevice; this._cSource.VideoCaptureDevice = _vcDevice; }
private void DisposeVideoRecorder() { if (_captureSource != null) { // Stop captureSource if it is running. if (_captureSource.VideoCaptureDevice != null && _captureSource.State == CaptureState.Started) { _captureSource.Stop(); } // Remove the event handler for captureSource. _captureSource.CaptureFailed -= OnCaptureFailed; // Remove the video recording objects. _captureSource = null; _videoCaptureDevice = null; _fileSink = null; _videoRecorderBrush = null; } }
public void InitializeVideoRecorder() { if (captureSource == null) { // Create the VideoRecorder objects. captureSource = new CaptureSource(); fileSink = new FileSink(); videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); // Add eventhandlers for captureSource. captureSource.CaptureFailed += new EventHandler<ExceptionRoutedEventArgs>(OnCaptureFailed); // Initialize the camera if it exists on the device. if (videoCaptureDevice != null) { // Create the VideoBrush for the viewfinder. videoRecorderBrush = new VideoBrush(); videoRecorderBrush.SetSource(captureSource); // Display the viewfinder image on the rectangle. viewfinderRectangle.Fill = videoRecorderBrush; // Start video capture and display it on the viewfinder. captureSource.Start(); // Set the button state and the message. UpdateUI(ButtonState.Initialized, "Tap record to start recording..."); } else { // Disable buttons when the camera is not supported by the device. UpdateUI(ButtonState.CameraNotSupported, "A camera is not supported on this device."); } } }
public void Inspect(string moniker) { _videoCaptureDevice = new VideoCaptureDevice(moniker); }
/// <summary> /// Create camera recorder and fill brush /// </summary> private void createCamera(string name = null) { source = new CaptureSource(); source.CaptureImageCompleted += triggerCaptureImage; camera = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); if (camera != null) { var supported = camera.SupportedFormats.Where(item => item.PixelFormat == PixelFormatType.Format32bppArgb).OrderBy(item => item.PixelWidth); source.VideoCaptureDevice.DesiredFormat = supported.ElementAt(0); if (videoSink != null) { videoSink.IsolatedStorageFileName = name != null ? name : null; videoSink.CaptureSource = name != null ? source : null; } VideoBrush = null; VideoBrush = new VideoBrush(); VideoBrush.SetSource(source); VideoBrush.Stretch = Stretch.UniformToFill; source.Start(); } OnPropertyChanged("IsSupported"); OnPropertyChanged("IsCameraEnabled"); OnPropertyChanged("IsShotEnabled"); }
public static VideoCaptureDevice CreateCaptureDeviceFromIndex(int index, int width, int height) { DsDevice[] devices; devices = DsDevice.GetDevicesOfCategory(FilterCategory.VideoInputDevice); VideoCaptureDevice newDevice = new VideoCaptureDevice(devices[index], width, height); return newDevice; }
private void button1_Click(object sender, EventArgs e) { FinalVideo = new VideoCaptureDevice(VideoCaptureDevices[comboBox1.SelectedIndex].MonikerString); FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame); FinalVideo.Start(); }
public void stop() { if (captureSource != null) { // Stop captureSource if it is running. if (captureSource.VideoCaptureDevice != null && captureSource.State == CaptureState.Started) { captureSource.Stop(); } // Remove the event handler for captureSource. captureSource.CaptureFailed -= OnCaptureFailed; // Remove the video recording objects. captureSource = null; videoCaptureDevice = null; fileSink = null; videoRecorderBrush = null; System.Diagnostics.Debug.WriteLine("Stopped"); _isRunning = false; } }
void loadCamera() { capcam = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice(); capcam.DesiredFormat = capcam.SupportedFormats.First(f => f.PixelWidth == w); captureSource = new CaptureSource(); captureSource.VideoCaptureDevice = capcam; if (captureSource.State != CaptureState.Started) captureSource.Start(); sink = new FrameVideoSink(); sink.CaptureSource = captureSource; sink.OnFrameReady += sink_OnFrameReady; sink.Enabled = true; viewfinderBrush.SetSource(captureSource); viewfinderBrush.Stretch = Stretch.Fill; phocam = new PhotoCamera(); }