Video source for local video capture device (for example USB webcam).

The video source captures video data from local video capture device. DirectShow is used for capturing.

Sample usage:

// enumerate video devices videoDevices = new FilterInfoCollection( FilterCategory.VideoInputDevice ); // create video source VideoCaptureDevice videoSource = new VideoCaptureDevice( videoDevices[0].MonikerString ); // set NewFrame event handler videoSource.NewFrame += new NewFrameEventHandler( video_NewFrame ); // start the video source videoSource.Start( ); // ... // signal to stop videoSource.SignalToStop( ); // ... private void video_NewFrame( object sender, NewFrameEventArgs eventArgs ) { // get new frame Bitmap bitmap = eventArgs.Frame; // process the frame }
Inheritance: IVideoSource
Example #1
3
        public bool Connect()
        {
            var videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

            if (videoDevices.Count == 0)
            {
                return false;
            }
            // create video source
            currentDevice = new VideoCaptureDevice(videoDevices[0].MonikerString);
            videoSourcePlayer1.VideoSource = currentDevice;
            var videoCapabilities = currentDevice.VideoCapabilities;
            //foreach (var video in videoCapabilities)
            //{
            //    LogHelper.Info("预览分辨率->" + video.FrameSize.Width + "*" + video.FrameSize.Height);
            //}
            if (videoCapabilities.Count() > 0)
                currentDevice.VideoResolution = currentDevice.VideoCapabilities.Last();

            var snapVabalities = currentDevice.SnapshotCapabilities;
            //foreach (var snap in snapVabalities)
            //{
            //    LogHelper.Info("抓拍分辨率->" + snap.FrameSize.Width + "*" + snap.FrameSize.Height);
            //}
            if (snapVabalities.Count() > 0)
                currentDevice.SnapshotResolution = currentDevice.SnapshotCapabilities.Last();

            currentDevice.Start();

            return true;
        }
Example #2
1
        private void button1_Click(object sender, EventArgs e)
        {
            cam = new VideoCaptureDevice(webcams[comboBox1.SelectedIndex].MonikerString);
            cam.NewFrame += new NewFrameEventHandler(cam_NewFrame);

            cam.Start();
        }
Example #3
1
        public minero_class(int puerto = 2134, GLOBAL_MODE modo = GLOBAL_MODE.MINI_MINERO)
        {
            _modoOperacion = modo;
            bmp1 = new Bitmap(640, 480, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            bw = new BackgroundWorker();
            _puerto = puerto;
            ipEnd = new IPEndPoint(IPAddress.Any, _puerto);
            bw.DoWork += new DoWorkEventHandler(bw_DoWork);

            if (_modoOperacion == GLOBAL_MODE.MINI_MINERO)
            {
                modeloRobot.setDeviceIndex(3);
            }
            else
            {
                modeloRobot.setDeviceIndex(4);
            }
            try
            {
                // enumerate video devices
                videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
                // create video source
                videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString);
                // set NewFrame event handler
                videoSource.NewFrame += videoSource_NewFrame;
            }
            catch (Exception ex)
            {

            }
            //jo¿ystick
            joy.JoystickEvent += joy_JoystickEvent;
        }
 private void button2_Click(object sender, EventArgs e)
 {
     FinalVideo2 = new VideoCaptureDevice(VideoCaptureDevices[comboBox1.SelectedIndex].MonikerString);
     FinalVideo2.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame2);
     FinalVideo2.Start();
     //   FinalVideo.Stop();
 }
Example #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            vkl             = true;
            button5.Enabled = false;
            button4.Enabled = true;
            var videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

            height        = Settings.height;
            width         = Settings.width;
            player        = new VideoSourcePlayer();
            player.Top    = 30;
            player.Left   = 30;
            player.Width  = width;
            player.Height = height;
            player.Show();
            Controls.Add(player);
            button1.Top  = height + 30;
            button1.Left = width + 50;
            button2.Top  = height + 60;
            button2.Left = width + 50;
            button3.Top  = height + 90;
            button3.Left = width + 50;
            button4.Top  = height + 120;
            button4.Left = width + 50;
            button5.Top  = height + 160;
            button5.Left = width + 50;
            cam          = new AForge.Video.DirectShow.VideoCaptureDevice(videoDevices[0].MonikerString);
            cam.Start();
            player.VideoSource = cam;
            player.Start();
        }
Example #6
0
        public void GetFrame()
        {
            // enumerate video devices
            var videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

            //foreach (FilterInfo item in videoDevices)
            //{

            //videoSource = new VideoCaptureDevice(item.MonikerString);
            videoSource = new VideoCaptureDevice(videoDevices[1].MonikerString);
            //videoSource.DesiredFrameSize = new Size(160, 120);

            // create video source
            //VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString);

            // set NewFrame event handler
            videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
            // start the video source
            videoSource.Start();
            // ...
            System.Threading.Thread.Sleep(500);
            Trace.WriteLine("FramesReceived: " + videoSource.FramesReceived);
            // signal to stop
            videoSource.SignalToStop();
            // ...
            //}
        }
        public void execute()
        {
            LocationSourceManager.Instance.Shutdown();
            this.videoPlayer.SignalToStop();
            this.videoPlayer.WaitForStop();

            FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[this.videoSourceCombo.SelectedIndex].MonikerString);

            int i = this.videoFormatCombo.SelectedIndex;
            videoSource.DesiredFrameSize = videoSource.VideoCapabilities[i].FrameSize;

            Size videoPlayerSize = videoSource.VideoCapabilities[i].FrameSize;
            videoPlayer.Size = videoPlayerSize;
            Size videoPlayerParentSize = videoPlayer.Parent.Size;
            videoPlayer.Location = new Point((videoPlayerParentSize.Width / 2) - (videoPlayerSize.Width / 2), (videoPlayerParentSize.Height / 2) - (videoPlayerSize.Height / 2));

            new UpdateMapSizeAndPosition(this.videoPlayer, MapOverlayForm.Instance).execute();

            Size mainFormMinSize = videoPlayerSize;
            mainFormMinSize.Width += 230;
            mainFormMinSize.Height += 50;
            if (mainFormMinSize.Height < 475)
                mainFormMinSize.Height = 475;
            this.mainForm.MinimumSize = mainFormMinSize;

            this.videoPlayer.VideoSource = videoSource;
            this.videoPlayer.Start();
        }
Example #8
0
        public void Start()
        {
            FilterInfoCollection videoDevices;
            string camDescr;
            try
            {
                videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
                if (videoDevices.Count == 0)
                {
                    throw new ApplicationException("no webcams");
                }
                else
                {
                    camName = videoDevices[Convert.ToInt32(devIndex)].MonikerString;
                    camDescr = videoDevices[Convert.ToInt32(devIndex)].Name;
                }
            }
            catch (ApplicationException)
            {
                throw new ApplicationException("failed web cams initialize");
            }

            videoSource = new VideoCaptureDevice(camName);
            videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
            videoSource.DesiredFrameSize = new Size(Convert.ToInt32(devWidth), Convert.ToInt32(devHeigth));//new Size(320, 240);//new Size(480, 360);//new Size(640, 480);//
            videoSource.DesiredFrameRate = 29;
            videoSource.Start();

            if (timerUploadImage == null)
            {
                timerUploadImage = new System.Timers.Timer(700);
                timerUploadImage.Elapsed += new ElapsedEventHandler(timerUploadImage_Tick);
                timerUploadImage.Start();
            }
        }
Example #9
0
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                ///---实例化对象  
                USE_Webcams = new FilterInfoCollection(FilterCategory.VideoInputDevice);
                ///---摄像头数量大于0  
                if (USE_Webcams.Count > 0)
                {
                    ///---禁用按钮  
                    btn_Start.Enabled = true;
                    ///---实例化对象  
                    cam = new VideoCaptureDevice(USE_Webcams[0].MonikerString);
                    ///---绑定事件  
                    cam.NewFrame += new NewFrameEventHandler(Cam_NewFrame);
                }
                else
                {
                    ///--没有摄像头  
                    btn_Start.Enabled = false;
                    ///---提示没有摄像头  
                    MessageBox.Show("没有摄像头外设");
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #10
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (button2.Text == "Tomar Foto")
     {
         AForge.Video.DirectShow.FilterInfoCollection videosources = new AForge.Video.DirectShow.FilterInfoCollection(AForge.Video.DirectShow.FilterCategory.VideoInputDevice);
         if (videosources != null)
         {
             videosource           = new AForge.Video.DirectShow.VideoCaptureDevice(videosources[0].MonikerString);
             videosource.NewFrame += (s, a) => pictureBox2.Image = (Bitmap)a.Frame.Clone();
             videosource.Start();
             button2.Text = "Capturar";
         }
     }
     else
     {
         pictureBox1.Image = pictureBox2.Image;
         if (videosource != null && videosource.IsRunning)
         {
             videosource.SignalToStop();
             videosource = null;
         }
         pictureBox2.Image = null;
         button2.Text      = "Tomar Foto";
     }
 }
        public Form1()
        {
            InitializeComponent();

            // show device list
            try
            {
                // enumerate video devices
                videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

                if (videoDevices.Count == 0)
                    throw new ApplicationException();

                // add all devices to combo
                foreach (FilterInfo device in videoDevices)
                {
                    devicesCombo.Items.Add(device.Name);
                }
            }
            catch (ApplicationException)
            {
                devicesCombo.Items.Add("No local capture devices");
                devicesCombo.Enabled = false;
                takePictureBtn.Enabled = false;
            }

            devicesCombo.SelectedIndex = 0;

            VideoCaptureDevice videoCaptureSource = new VideoCaptureDevice(videoDevices[devicesCombo.SelectedIndex].MonikerString);
            videoSourcePlayer.VideoSource = videoCaptureSource;
            videoSourcePlayer.Start();
        }
Example #12
0
        public Webcam(string ocu_ipAddress, CameraConfiguration config)
        {
            this.config = config;
            FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            if (videoDevices.Count < 1)
                throw new Exception("No video input devices available");
            if (!string.IsNullOrEmpty(config.DeviceName))
                videoSource = new VideoCaptureDevice(config.DeviceName);
                //videoSource = new VideoCaptureDevice(videoDevices[1].MonikerString);
            else
            {
                videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString);
            }

            updateWorker = new Timer();
            updateWorker.Elapsed += new ElapsedEventHandler(updateWorker_Elapsed);
            FrameRate = config.RCU_To_OCU_Framerate;
            JPEGQuality = config.JPEGQuality;
            isActive = false;
            jpegCodec = GetEncoderInfo("image/jpeg");
            videoSource.DesiredFrameSize = new Size(320, 240);
            videoSource.NewFrame += new NewFrameEventHandler(videoSource_NewFrame);
            udp_sender = new Comms.UDP_Sender(ocu_ipAddress, config.SendPort);
            raw_frame_queue = new Utility.UpdateQueue<byte[]>(-1);
        }
Example #13
0
 private void btnComeçar_Click(object sender, RoutedEventArgs e)
 {
     //Iniciar a camera e mostrar no picture Box[form control] por meio do evento
     cam = new VideoCaptureDevice(webcam[cmbDevices.SelectedIndex].MonikerString);
     cam.NewFrame += new NewFrameEventHandler(cam_NewFrame);
     cam.Start();
 }
Example #14
0
 public MainWindow()
 {
     InitializeComponent();
     videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
     VCD = new VideoCaptureDevice(videoDevices[0].MonikerString);
     SSSender = new snapShotSender(VCD);
 }
Example #15
0
        // Collect supported video and snapshot sizes
        private void EnumeratedSupportedFrameSizes(VideoCaptureDevice videoDevice)
        {
            this.Cursor = Cursors.WaitCursor;

            videoResolutionsCombo.Items.Clear();
            try
            {
                videoCapabilities = videoDevice.VideoCapabilities;
                foreach (VideoCapabilities capabilty in videoCapabilities)
                {
                    videoResolutionsCombo.Items.Add(string.Format("{0} x {1}",
                        capabilty.FrameSize.Width, capabilty.FrameSize.Height));
                }

                if (videoCapabilities.Length == 0)
                {
                    videoResolutionsCombo.Items.Add("Not supported");
                }

                videoResolutionsCombo.SelectedIndex = 0;
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
        private void button_iniciar_Click(object sender, EventArgs e)
        {
            if (button_iniciar.Text.Equals("Iniciar"))
            {
                if (existem_dispositivos)
                {
                    fonte_video = new VideoCaptureDevice(dispositivos_video[comboBox_dispositivo.SelectedIndex].MonikerString);
                    fonte_video.NewFrame += new NewFrameEventHandler(VideoNovoFrame);
                    fonte_video.Start();
                    //statusStrip_barra.Text = "Executando dispositivo";
                    button_iniciar.Text = "Parar";
                    comboBox_dispositivo.Enabled = false;
                    //label_nome.Text = dispositivos_video[comboBox_camera.SelectedIndex].ToString();

                }
                else
                {
                    //statusStrip_barra.Text = "Error: Não encontrado dispositivo";
                }

            }
            else
            {
                if (fonte_video != null)// || fonte_video.IsRunning)
                {
                    TerminarFonteVideo();
                    //statusStrip_barra.Text = "Dispositivo Terminado";
                    //button_iniciar.Text = "Iniciar";
                    comboBox_dispositivo.Enabled = true;
                }
            }
        }
Example #17
0
 private void button1_Click(object sender, EventArgs e)
 {
     timer1.Enabled = true;
     Video = new VideoCaptureDevice(Dispositivos[comboBox1.SelectedIndex].MonikerString);
     videoSourcePlayer1.VideoSource = Video;
     videoSourcePlayer1.Start();
 }
        public CameraDevice GetFirstCameraDevice()
        {
            CameraDevice cameraDevice = null;
            // enumerate video devices
            FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            if ((videoDevices != null) && (videoDevices.Count > 0))
            {
                // create video source
                VideoCaptureDevice videoDevice = new VideoCaptureDevice(videoDevices[0].MonikerString);
                List<CameraDevice> devicesData = _config.GetConfiguredCameraDevicesData().Where(a => a.ID == videoDevice.Source).ToList();
                if ((devicesData != null) && (devicesData.Count > 0))
                {
                    cameraDevice = devicesData[0];
                }
                else
                {
                    cameraDevice = new LocalCameraDevice();
                    cameraDevice.ID = videoDevice.Source;
                    cameraDevice.Name = "Camera";
                    _config.AddCameraDevice(cameraDevice);
                    _config.Save();
                }
                (cameraDevice as LocalCameraDevice).Init(videoDevice);

            }

            return cameraDevice;
        }
Example #19
0
        private void btn_afficher_flux_cam_Click(object sender, EventArgs e)
        {
            if (DeviceExist && videoSource == null)
            {
                videoSource = new VideoCaptureDevice(videoDevices[selecteur_camera.SelectedIndex].MonikerString);
                videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
                //CloseVideoSource();
                //videoSource.DesiredFrameRate = 10;
                videoSource.DesiredFrameRate = videoSource.VideoCapabilities[selecteur_resolution.SelectedIndex].FrameRate;
                videoSource.DesiredFrameSize = videoSource.VideoCapabilities[selecteur_resolution.SelectedIndex].FrameSize;
                videoSource.Start();

            }
            else if (videoSource != null)
            {
                label_etat_programe.Text = "Erreur flux déjà en route !";
            }
            else
            {
                label_etat_programe.Text = "Erreur, aucune caméra sélectionnée !";
            }

            btn_afficher_flux_cam.Enabled = false;
            btn_stopper_flux_video.Enabled = true;
        }
Example #20
0
        public Form1()
        {
            InitializeComponent();

            dm.setDeviceIndex(3);
            comboBox2.DataSource = Enum.GetValues(typeof(MODELO_TYPE));

            // enumerate video devices
            videoDevices = new FilterInfoCollection(
                     FilterCategory.VideoInputDevice);
            // create video source
            videoSource = new VideoCaptureDevice(
                    videoDevices[0].MonikerString);
            // set NewFrame event handler
            videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);

            /*ax12_Rot = new AX_12_Motor();
            ax12_Dir = new AX_12_Motor();

            ax12_Dir.setDeviceID(3);
            ax12_Rot.setDeviceID(3);
            ax12_Dir.setBaudSpeed(BAUD_RATE.BAUD_1Mbps);
            ax12_Rot.setBaudSpeed(BAUD_RATE.BAUD_1Mbps);*/
            //button3_Click(null, null);
        }
Example #21
0
        public MainWindow()
        {
            InitializeComponent();

            ////////////////////Video Config - Start//////////////////////
            FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            string toPrint = "";
            foreach (FilterInfo vidDevice in videoDevices)
            {
                toPrint += vidDevice.MonikerString + "  \n  ";
            }
            MessageBox.Show("Found:\n\n" + toPrint);
            if (videoDevices.Count < 2)
            {
                MessageBox.Show("Not enough webcams detected, closing");
                Environment.Exit(0);
            }
            VideoCaptureDevice leftSource = new VideoCaptureDevice(videoDevices[0].MonikerString);
            VideoCaptureDevice rightSource = new VideoCaptureDevice(videoDevices[1].MonikerString);

            leftSource.Start();
            rightSource.Start();

            leftPlayer.VideoSource = leftSource;
            rightPlayer.VideoSource = rightSource;

            leftHost.Child = leftPlayer;
            rightHost.Child = rightPlayer;

            leftPlayer.Start();
            rightPlayer.Start();
        }
        public IList<CameraDevice> GetAvailableDevices()
        {
            List<CameraDevice> cameraDevices = new List<CameraDevice>();
            try
            {
                FilterInfoCollection filterInfoCollection = new FilterInfoCollection(FilterCategory.VideoInputDevice);

                if (filterInfoCollection.Count == 0)
                    return cameraDevices;

                foreach (FilterInfo device in filterInfoCollection)
                {
                    VideoCaptureDevice videoCaptureDevice = new VideoCaptureDevice(device.MonikerString);

                    // only add device if it has video capabilities
                    if (videoCaptureDevice.VideoCapabilities.Length > 0)
                    {
                        cameraDevices.Add(
                            new CameraDevice
                            {
                                Name = device.Name,
                                MonikerString = device.MonikerString
                            });
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);

                return cameraDevices;
            }

            return cameraDevices;
        }
Example #23
0
        public bool Init()
        {
            _WebcamDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            int num = 0;
            foreach (FilterInfo info in _WebcamDevices)
            {
                SWebcamDevice device = new SWebcamDevice {
                    ID = num,
                    Name = info.Name,
                    MonikerString = info.MonikerString,
                    Capabilities = new List<SCapabilities>()
                };
                num++;
                VideoCaptureDevice tmpdev = new VideoCaptureDevice(info.MonikerString);

                for (int i = 0; i < tmpdev.VideoCapabilities.Length; i++ )
                {
                    SCapabilities item = new SCapabilities
                    {
                        Framerate = tmpdev.VideoCapabilities[i].FrameRate,
                        Height = tmpdev.VideoCapabilities[i].FrameSize.Height,
                        Width = tmpdev.VideoCapabilities[i].FrameSize.Width
                    };
                    device.Capabilities.Add(item);
                }
                _Devices.Add(device);
            }
            return true;
        }
Example #24
0
        private void Apagar()
        {
            try
            {
                btnSalvarFoto.Enabled = true;
                btnCapturar.Enabled   = false;

                AForge.Video.DirectShow.FilterInfoCollection videosources = new AForge.Video.DirectShow.FilterInfoCollection(AForge.Video.DirectShow.FilterCategory.VideoInputDevice);

                if (videosources != null)
                {
                    videoSource           = new AForge.Video.DirectShow.VideoCaptureDevice(videosources[0].MonikerString);
                    videoSource.NewFrame += (s, e) => picWebCam.Image = (Bitmap)e.Frame.Clone();

                    videoSource.SetCameraProperty(
                        CameraControlProperty.Focus,
                        500,
                        CameraControlFlags.Manual);
                    videoSource.Start();
                }
            }
            catch (Exception ex)
            {
            }
        }
        public void StartVideo()
        {
            if (filterInfoCollection != null)
            {
                videoCaptureDevice = new VideoCaptureDevice(filterInfoCollection[1].MonikerString);
                try
                {
                    if (videoCaptureDevice.VideoCapabilities.Length > 0)
                    {
                        string highestSolution = "0;0";

                        for (int i = 0; i < videoCaptureDevice.VideoCapabilities.Length; i++)
                        {
                            highestSolution = videoCaptureDevice.VideoCapabilities[i].FrameSize.Width.ToString() +';'
                            +i.ToString();
                        }

                        videoCaptureDevice.VideoResolution =
                            videoCaptureDevice.VideoCapabilities[Convert.ToInt32(highestSolution.Split(';')[1])];

                    }

                }
                catch (Exception e)
                {

                }

                videoCaptureDevice.NewFrame += newFrameEventHandler;

                videoCaptureDevice.Start();
            }
        }
Example #26
0
 public static void Cameraint(int i)
 {
     videoSource = new VideoCaptureDevice(videoDevices[i].MonikerString);
      videoSource.DesiredFrameSize = new Size(2048, 1536);
      videoSource.DesiredFrameRate = 1;
      videoSource.Start();
 }
Example #27
0
        private void button2_Click(object sender, EventArgs e)
        {
            mpeg = new MJPEGStream();
            AForge.Video.DirectShow.VideoCaptureDevice fcg = new AForge.Video.DirectShow.VideoCaptureDevice();
            mpeg.Login    = "******";
            mpeg.Password = "******";
            mpeg.Source   = "http://192.168.1.111/GetData.cgi";
            AsyncVideoSource asyncSource = new AsyncVideoSource(mpeg);

            mpeg.NewFrame += new NewFrameEventHandler(cam_NewFrame);
            mpeg.Start();

            Timer ti = new Timer();

            /* sec = 0;
             *
             * frame_count = 0;
             * //usbCam = new FilterInfoCollection(FilterCategory.VideoInputDevice);
             * //cam = new VideoCaptureDevice(usbCam[0].MonikerString);
             * VideoCaptureDeviceForm Video_Input = new VideoCaptureDeviceForm();
             * Video_Input.ShowDialog();
             * cam =new VideoCaptureDevice(Video_Input.VideoDeviceMoniker);
             * cam.NewFrame +=new  NewFrameEventHandler(cam_NewFrame);
             * cam.Start();*/


            ti.Interval = 1000;
            ti.Tick    += new EventHandler(time);
            ti.Start();
        }
Example #28
0
        public FPSAim(String vcd)
        {
            InitializeComponent();

              VideoCaptureDevice videoSource = new VideoCaptureDevice(vcd, new Size(320, 240), false);
              OpenVideoSource(videoSource);

              redDot.Location = new Point(gridBox.Width / 2 + gridBox.Left, gridBox.Height / 2 + gridBox.Top);
              servos = new Servos();
              redDot.Location = servos.GetPorportionalMathPosition(gridBox.Bounds);
              redDot.Location = new Point(redDot.Location.X - REDDOT_OFFSET_X, redDot.Location.Y - REDDOT_OFFSET_Y);
              label1.Text = "(-" + servos.CenterServosPosition.X + "," + servos.CenterServosPosition.Y + ")";
              textBoxXServo.Text = servos.ShootingRange.Width.ToString();
              textBoxYServo.Text = servos.ShootingRange.Height.ToString();
              textBoxXCoord.Text = servos.ServosPosition.X.ToString();
              textBoxYCoord.Text = servos.ServosPosition.Y.ToString();

              Packet packet = new Packet(servos.CenterServosPosition);
              packet.setFireOff();
              this.sendData(packet);
              Cursor.Hide();
              cursorhidden = true;
              CoordinateTimer.Start();

              //Point camwindowcenter = new Point(gridBox.PointToScreen(new Point(0, 0)).X , gridBox.PointToScreen(new Point(0, 0)).Y );
              //Cursor.Position = camwindowcenter;
              currentX = Cursor.Position.X;
              currentY = Cursor.Position.Y;
              lastX = 0;
              lastY = 0;
        }
Example #29
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == -1)
            {
                MessageBox.Show("请选择设备录像!");
                return;
            }

            this.Size = new Size(659, 415);
            foreach (FilterInfo i in devices)
            {
                if (i.Name == this.comboBox1.SelectedItem.ToString())
                {
                    currentDevice = i;
                }
            }
            currentVideoSource = Camera.connectDevice(currentDevice);
            if (this.comboBox2.SelectedIndex == -1)
            {
                currentVideoSource.DesiredFrameRate = 1;
            }
            else
            {
                currentVideoSource.DesiredFrameRate = int.Parse(this.comboBox2.SelectedItem.ToString());
            }
            currentVideoSource.DesiredFrameSize = new System.Drawing.Size(this.pixtureBox.Width, this.pixtureBox.Height);
            currentVideoSource.NewFrame        += videosource_NewFrame;
            Camera.openDevice(currentVideoSource);

            button1.Enabled = false;
            button2.Enabled = true;
            button3.Enabled = true;
            button4.Enabled = true;
        }
Example #30
0
 private void btnIniciar_Click(object sender, EventArgs e)
 {
     if (btnIniciar.Text == "Start")
     {
         if (ExistenDispositive)
         {
             FuenteVideo = new VideoCaptureDevice(DispositiveVideo[cboDispositive.SelectedIndex].MonikerString);
             FuenteVideo.NewFrame += new NewFrameEventHandler(video_NuevoFrame);
             FuenteVideo.Start();
             Estado.Text = "Connection Complete";
             btnIniciar.Text = "Stop";
             cboDispositive.Enabled = false;
             groupBox1.Text = DispositiveVideo[cboDispositive.SelectedIndex].Name.ToString();
         }
         else
             Estado.Text = "Error: No matching device.";
     }
     else {
         if (FuenteVideo.IsRunning) {
             btnIniciar.Text = "Start";
             TerminarFuenteDeVideo();
             Estado.Text = "Dispositiveo detenio";
             cboDispositive.Enabled = true;
         }
     }
 }
Example #31
0
        //GetCamSettings
        public static void GetCamSettingsCombobox(ComboBox c)
        {
            WebCamSettings = c;

            try
            {
                videoSource = new VideoCaptureDevice(VideoDevices[WebCamList.SelectedIndex].MonikerString);
                WebCamSettings.Items.Clear();
                //DeviceExist = true;
                foreach (var capability in videoSource.VideoCapabilities)
                {
                    WebCamSettings.Items.Add(capability.FrameSize.Width.ToString() + " x " + capability.FrameSize.Height.ToString() + "  " + capability.AverageFrameRate.ToString() + " fps");
                }

                if (Properties.Settings.Default.WebCamResolution == null || Properties.Settings.Default.WebCamDevice != Convert.ToString(WebCamList.SelectedItem))
                {
                    WebCamSettings.SelectedIndex = 0;
                }
                else
                {
                    WebCamSettings.SelectedIndex = WebCamSettings.FindString(Properties.Settings.Default.WebCamResolution);
                }
            }
            catch (ArgumentOutOfRangeException)
            {
                //DeviceExist = false;
                WebCamSettings.Items.Add("No capture device on your system");
            }
        }
Example #32
0
        private void videoSourcePlayer_Click(object sender, EventArgs e)
        {
            if (videoSourcePlayer.IsRunning)
            {
                videoSourcePlayer.SignalToStop();
                viewModel.IsWebcamEnabled = false;
                return;
            }

            using (CaptureDeviceDialog form = new CaptureDeviceDialog())
            {
                if (form.ShowDialog(this) == DialogResult.OK)
                {
                    // create video source
                    VideoCaptureDevice videoSource = new VideoCaptureDevice(form.VideoDevice);

                    // set busy cursor
                    this.Cursor = Cursors.WaitCursor;

                    stop();

                    // start new video source
                    videoSourcePlayer.VideoSource = new AsyncVideoSource(videoSource);
                    videoSourcePlayer.Start();

                    Cursor = Cursors.Default;
                    label1.Visible = false;
                    viewModel.IsWebcamEnabled = true;
                }
            }
        }
Example #33
0
 public VideoCaptureDevice(VideoCaptureDeviceInfo deviceInfo)
 {
     videoSource           = new AForge.Video.DirectShow.VideoCaptureDevice(deviceInfo.MonikerString);
     videoSource.NewFrame += videoSource_NewFrame;
     videoSource.Start();
     isStarted = true;
 }
Example #34
0
        public Logic()
        {
            videodevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            videoSource = new VideoCaptureDevice(videodevices[0].MonikerString);

            videoSource.NewFrame += videoSource_NewFrame;
            videoSource.Start();
        }
Example #35
0
 // New video device is selected
 private void devicesCombo_SelectedIndexChanged( object sender, EventArgs e )
 {
     if ( videoDevices.Count != 0 )
     {
         videoDevice = new VideoCaptureDevice( videoDevices[devicesCombo.SelectedIndex].MonikerString );
         EnumeratedSupportedFrameSizes( videoDevice );
     }
 }
Example #36
0
        public MainForm()
        {
            InitializeComponent();
            timerLapso.Stop();
            timerCaptura.Stop();
            buttonEmpezar.Focus();

            //TestSet testSet = TestSetDao.GetTestSet(defaultTestSet);

            VideoSources = new AForge.Video.DirectShow.FilterInfoCollection(AForge.Video.DirectShow.FilterCategory.VideoInputDevice);
            if (VideoSources != null)
            {
                foreach (Screen screens1 in Screen.AllScreens)
                {
                    comboBoxPantallas.Items.Add(screens1.DeviceName);
                }

                screens2 = Screen.AllScreens;

                comboBoxPantallas.SelectedIndex = 0;

                foreach (FilterInfo VideoSource in VideoSources)
                {
                    comboBoxWebCam.Items.Add(VideoSource.Name);
                }

                VideoSource           = new AForge.Video.DirectShow.VideoCaptureDevice(VideoSources[0].MonikerString);
                VideoSource.NewFrame += new NewFrameEventHandler(FinalFrame_NewFrame);
                VideoSource.Start();

                if (comboBoxWebCam.Items.Count > 0)
                {
                    comboBoxWebCam.SelectedIndex = 0;
                }
            }

            buttonTerminar.Enabled = false;

            try {
                Conexion.Open();

                SqlCommand    cmd = new SqlCommand("select max(SECCION) AS SECCION from [NEUROSKY_IMAGENES]", Conexion);
                SqlDataReader dr  = cmd.ExecuteReader();

                if (dr.Read())
                {
                    int.TryParse(Convert.ToString(dr["SECCION"]), out this.Seccion);
                    Seccion++;
                }
                Conexion.Close();
            } catch (Exception e) {
                Console.WriteLine("Fallo la conexion a la base");
                Console.WriteLine(e.Message);
            }
        }
Example #37
0
            public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
            {
                var deviceInfo         = new FilterInfoCollection(FilterCategory.VideoInputDevice);
                var videoCaptureDevice = (VideoCaptureDevice)context.Instance;
                var index = videoCaptureDevice.Index;

                var videoSource = new AForge.Video.DirectShow.VideoCaptureDevice(deviceInfo[index].MonikerString);
                var frameSizes  = Array.ConvertAll(videoSource.VideoCapabilities, capabilities => new VideoFormat(capabilities));

                return(new StandardValuesCollection(frameSizes));
            }
        private void button5_Click(object sender, EventArgs e)
        {
            mpeg = new MJPEGStream();
            AForge.Video.DirectShow.VideoCaptureDevice fcg = new AForge.Video.DirectShow.VideoCaptureDevice();
            mpeg.Login    = "******";
            mpeg.Password = "******";
            mpeg.Source   = "http://192.168.1.8/GetData.cgi";
            AsyncVideoSource asyncSource = new AsyncVideoSource(mpeg);

            mpeg.NewFrame += new NewFrameEventHandler(cam_NewFrame);
            mpeg.Start();
        }
Example #39
0
 public void Stop()
 {
     if (isStarted)
     {
         if (videoSource.IsRunning)
         {
             videoSource.Stop();
         }
         videoSource = null;
         isStarted   = false;
     }
 }
Example #40
0
 private void comboBoxWebCam_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (VideoSources != null)
     {
         if (VideoSource.IsRunning)
         {
             VideoSource.Stop();
         }
         VideoSource           = new AForge.Video.DirectShow.VideoCaptureDevice(VideoSources[comboBoxWebCam.SelectedIndex].MonikerString);
         VideoSource.NewFrame += new NewFrameEventHandler(FinalFrame_NewFrame);
         VideoSource.Start();
     }
 }
Example #41
0
        private void button3_Click(object sender, EventArgs e)
        {
            IsRunning = false;
            //有问题,需要改进。
            if (currentDevice != null)
            {
                currentVideoSource.NewFrame -= videosource_NewFrame;
                currentVideoSource.Stop();
                currentVideoSource = null;
                bmp = null;
            }
            this.Size = new Size(261, 415);

            button2.Enabled = false;
            button4.Enabled = false;
            button1.Enabled = true;
        }
Example #42
0
        protected override IVideoSource CreateVideoSource()
        {
            var index         = Index;
            var deviceFilters = new FilterInfoCollection(FilterCategory.VideoInputDevice);

            if (index >= deviceFilters.Count)
            {
                throw new InvalidOperationException("The specified video input device is not available.");
            }

            var format      = Format;
            var videoSource = new AForge.Video.DirectShow.VideoCaptureDevice(deviceFilters[index].MonikerString);

            if (format != null)
            {
                var videoResolution = Array.Find(videoSource.VideoCapabilities, capabilities => format.Equals(capabilities));
                videoSource.VideoResolution = videoResolution;
            }
            return(videoSource);
        }
Example #43
0
        public void StartCapturing(object logic)
        {
            _logic = (Logic)logic;
            int fps = 25;

            writerThread      = new Thread(ImageWriter);
            writerThread.Name = "writerThread";
            writerThread.Start();

            var videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

            _captureDevice = new VideoCaptureDevice(videoDevices[0].MonikerString);
            _captureDevice.DesiredFrameSize = new Size(704, 576);
            _captureDevice.DesiredFrameRate = fps;
            _captureDevice.NewFrame        += new AForge.Video.NewFrameEventHandler(camera_NewFrame);
            _captureDevice.Start();
            globFrameCount   = 0;
            globCaptureStart = DateTime.Now;
            //now capturing
        }
Example #44
0
 private void AtivarFoto_CheckedChanged(object sender, EventArgs e)
 {
     if (AtivarFoto.Checked)
     {
         FilterInfoCollection videosource = new FilterInfoCollection(FilterCategory.VideoInputDevice);
         if (videosource != null)
         {
             videoSource = new AForge.Video.DirectShow.VideoCaptureDevice(videosource[0].MonikerString);;
             videoSource.VideoResolution = videoSource.VideoCapabilities[1];
             videoSource.NewFrame       += (s, a) => Foto.Image = (Bitmap)a.Frame.Clone();
             videoSource.Start();
         }
     }
     else
     {
         if (videoSource.IsRunning)
         {
             videoSource.Stop();
         }
     }
 }
Example #45
0
        private void CreateVideoFigure(AForge.Video.DirectShow.VideoCaptureDevice videoSource)
        {
            try
            {
                ViewOriginalVideo(videoSource);
                ViewAppliedFilterVideo(videoSource);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.Source);
            }
            #region AggregateException catch for .NET 4 or higher

            /*
             * catch (AggregateException ex)
             * {
             *  foreach (var v in ex.InnerExceptions)
             *      MessageBox.Show(ex.Message + " " + v.Message);
             * }
             */
            #endregion
        }
Example #46
0
        private void TakePhoto()
        {
            try
            {
                //webCamPictureBox.Image.Save("snapshot.png", System.Drawing.Imaging.ImageFormat.Png);
                btnSalvarFoto.Enabled = false;
                btnCapturar.Enabled   = true;

                //webCamPictureBox.ImageLocation = "snapshot.png";

                if (videoSource != null && videoSource.IsRunning)
                {
                    videoSource.SignalToStop();
                    videoSource = null;
                }


                picWebCam.Image.Save(diretorioImagem + txtNomeAluno.Text + ".jpg", System.Drawing.Imaging.ImageFormat.Png);
            }
            catch (Exception ex)
            {
            }
        }
Example #47
0
 // Constructor
 public Grabber(VideoCaptureDevice parent)
 {
     this.parent = parent;
 }
Example #48
0
        // Collect supported video and snapshot sizes
        private void EnumeratedSupportedFrameSizes(VideoCaptureDevice videoDevice)
        {
            this.Cursor = Cursors.WaitCursor;

            videoResolutionsCombo.Items.Clear( );
            snapshotResolutionsCombo.Items.Clear( );
            videoInputsCombo.Items.Clear( );

            videoCapabilitiesDictionary.Clear( );
            snapshotCapabilitiesDictionary.Clear( );

            try
            {
                // collect video capabilities
                VideoCapabilities[] videoCapabilities = videoDevice.VideoCapabilities;
                int videoResolutionIndex = 0;

                foreach (VideoCapabilities capabilty in videoCapabilities)
                {
                    string item = string.Format(
                        "{0} x {1}", capabilty.FrameSize.Width, capabilty.FrameSize.Height);

                    if (!videoResolutionsCombo.Items.Contains(item))
                    {
                        if (captureSize == capabilty.FrameSize)
                        {
                            videoResolutionIndex = videoResolutionsCombo.Items.Count;
                        }

                        videoResolutionsCombo.Items.Add(item);
                    }

                    if (!videoCapabilitiesDictionary.ContainsKey(item))
                    {
                        videoCapabilitiesDictionary.Add(item, capabilty);
                    }
                    else
                    {
                        if (capabilty.FrameRate > videoCapabilitiesDictionary[item].FrameRate)
                        {
                            videoCapabilitiesDictionary[item] = capabilty;
                        }
                    }
                }

                if (videoCapabilities.Length == 0)
                {
                    videoResolutionsCombo.Items.Add("Not supported");
                }

                videoResolutionsCombo.SelectedIndex = videoResolutionIndex;


                if (configureSnapshots)
                {
                    // collect snapshot capabilities
                    VideoCapabilities[] snapshotCapabilities = videoDevice.SnapshotCapabilities;
                    int snapshotResolutionIndex = 0;

                    foreach (VideoCapabilities capabilty in snapshotCapabilities)
                    {
                        string item = string.Format(
                            "{0} x {1}", capabilty.FrameSize.Width, capabilty.FrameSize.Height);

                        if (!snapshotResolutionsCombo.Items.Contains(item))
                        {
                            if (snapshotSize == capabilty.FrameSize)
                            {
                                snapshotResolutionIndex = snapshotResolutionsCombo.Items.Count;
                            }

                            snapshotResolutionsCombo.Items.Add(item);
                            snapshotCapabilitiesDictionary.Add(item, capabilty);
                        }
                    }

                    if (snapshotCapabilities.Length == 0)
                    {
                        snapshotResolutionsCombo.Items.Add("Not supported");
                    }

                    snapshotResolutionsCombo.SelectedIndex = snapshotResolutionIndex;
                }

                // get video inputs
                availableVideoInputs = videoDevice.AvailableCrossbarVideoInputs;
                int videoInputIndex = 0;

                foreach (VideoInput input in availableVideoInputs)
                {
                    string item = string.Format("{0}: {1}", input.Index, input.Type);

                    if ((input.Index == videoInput.Index) && (input.Type == videoInput.Type))
                    {
                        videoInputIndex = videoInputsCombo.Items.Count;
                    }

                    videoInputsCombo.Items.Add(item);
                }

                if (availableVideoInputs.Length == 0)
                {
                    videoInputsCombo.Items.Add("Not supported");
                }

                videoInputsCombo.SelectedIndex = videoInputIndex;
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
Example #49
0
 // Constructor
 public Grabber(VideoCaptureDevice parent)
 {
     this.parent = parent;
     YUYV        = parent.getYUYV();
     erode       = parent.getErosion();
 }
Example #50
0
 public Grabber(VideoCaptureDevice parent, bool snapshotMode)
 {
     this.parent       = parent;
     this.snapshotMode = snapshotMode;
 }
Example #51
-1
        static void Main()
        {
            _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)
            {
                _path += "motions";

                if (!Directory.Exists(_path))
                {
                    Directory.CreateDirectory(_path);
                }
                else
                {
                    var dir = new DirectoryInfo(_path);
                    foreach (var fi in dir.GetFiles())
                    {
                        fi.Delete();
                    }
                }

                var videoDevice = new FilterInfoCollection(FilterCategory.VideoInputDevice)[0];
                var videoCaptureDevice = new VideoCaptureDevice(videoDevice.MonikerString);
                var videoSourcePlayer = new AForge.Controls.VideoSourcePlayer();
                videoSourcePlayer.NewFrame += VideoSourcePlayer_NewFrame;
                videoSourcePlayer.VideoSource = new AsyncVideoSource(videoCaptureDevice);
                videoSourcePlayer.Start();
            }
        }