Example #1
0
        public CameraFigure(AForge.Video.DirectShow.VideoCaptureDevice videoSource, string formText)
        {
            /// Set current Process Affinity: (I want this process work only of the first 1 available processors)
            ///
            /// Bitmask                  Binary value               Eligible processors
            /// 0x0001                   00000000 00000001          1
            /// 0x0003                   00000000 00000011          1 and 2
            /// 0x0007                   00000000 00000111          1, 2 and 3
            /// 0x0009                   00000000 00001001          1 and 4
            /// 0x007F                   00000000 01111111          1, 2, 3, 4, 5, 6 and 7
            ///
            Process Proc         = Process.GetCurrentProcess();
            long    AffinityMask = (long)Proc.ProcessorAffinity;

            AffinityMask          &= 0x0001; // use only any of the first 1 available processors
            Proc.ProcessorAffinity = (IntPtr)AffinityMask;
            //
            InitializeComponent();
            InitializeVideoSourcePlayer(videoSource);
            //
            this.Text         = formText;
            this.SizeChanged += CameraFigure_SizeChanged;
            this.FormClosing += CameraFigure_FormClosing;

            this.videoSourcePlayer.SignalToStop();
            this.videoSourcePlayer.WaitForStop();
            this.videoSourcePlayer.Start();
            this.isRunning = true;



            this.videoSourcePlayer.MouseClick += videoSourcePlayer_MouseClick;
        }
Example #2
0
 private void Voltar(object sender, EventArgs e)
 {
     if (videoSource != null && videoSource.IsRunning)
     {
         videoSource.SignalToStop();
         videoSource = null;
     }
     this.Close();
 }
Example #3
0
 protected override void OnClosed(EventArgs e)
 {
     if (videoSource != null && videoSource.IsRunning)
     {
         videoSource.SignalToStop();
         videoSource = null;
     }
     base.OnClosed(e);
 }
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            base.OnClosed(e);

            if (videoSource != null && videoSource.IsRunning)
            {
                videoSource.SignalToStop();
                videoSource = null;
            }
        }
Example #5
0
 private void Ini_tirar_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, f) => perfilPB.Image = (Bitmap)f.Frame.Clone();
         videoSource.Start();
     }
 }
Example #6
0
 public TFCapturaVideo()
 {
     InitializeComponent();
     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) => pbImagem.Image = (Bitmap)e.Frame.Clone();
         videoSource.Start();
     }
 }
Example #7
0
        private void TakePicture_FormClosed(object sender, FormClosedEventArgs e)
        {
            base.OnClosed(e);

            if (videoSource != null && videoSource.IsRunning)
            {
                this.takenPicture.Dispose();
                this.pictureBox1.Image.Dispose();
                videoSource.SignalToStop();
                videoSource = null;
            }
        }
Example #8
0
 public void tirar_foto(object sender, EventArgs e)
 {
     if (take.Text == "Save")
     {
         perfilPB.Image.Save("snapshot.png", System.Drawing.Imaging.ImageFormat.Png);
         videoSource.SignalToStop();
         videoSource            = null;
         perfilPB.ImageLocation = @".\snapshot.png";
         perfilPB.SizeMode      = PictureBoxSizeMode.Zoom;
         take.Text = "Tirar";
     }
     else
     {
         take.Text = "Save";
         Ini_tirar_foto();
     }
 }
 public void Read(XmlElement element)
 {
     try
     {
         Name    = element.GetAttribute("name");
         Moniker = element.GetElementsByTagName("moniker")[0].InnerText;;
         device_ = new AForge.Video.DirectShow.VideoCaptureDevice(Moniker);
         XmlNodeList calib = element.GetElementsByTagName("CameraCalibrationData");
         if (calib.Count > 0)
         {
             Calibration = new Calibration.CameraCalibrationData();
             Calibration.Read(calib[0] as XmlElement);
         }
     }
     catch (Exception ex)
     {
         ErrorHandler.GetInst().PushError(ex);
     }
 }
Example #10
0
 void InitializeVideoSourcePlayer(AForge.Video.DirectShow.VideoCaptureDevice videoSource)
 {
     this.videoSourcePlayer = new AForge.Controls.VideoSourcePlayer();
     //
     // videoSourcePlayer
     //
     this.videoSourcePlayer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                                                                            | System.Windows.Forms.AnchorStyles.Left)
                                                                           | System.Windows.Forms.AnchorStyles.Right)));
     this.videoSourcePlayer.Location    = new System.Drawing.Point(0, 0);
     this.videoSourcePlayer.Name        = "videoSourcePlayer";
     this.videoSourcePlayer.Size        = new System.Drawing.Size(400, 400);
     this.videoSourcePlayer.TabIndex    = 0;
     this.videoSourcePlayer.Text        = "videoSourcePlayer";
     this.videoSourcePlayer.VideoSource = videoSource;
     this.videoSourcePlayer.NewFrame   += videoSourcePlayer_NewFrame;
     //
     // Add to client form
     //
     this.Controls.Add(this.videoSourcePlayer);
 }
Example #11
0
        public static bool CheckSupportSize(int cameraId, int width, int height)
        {
            var videoDevices = new AForge.Video.DirectShow.FilterInfoCollection(FilterCategory.VideoInputDevice);
            var videoDevice  = new AForge.Video.DirectShow.VideoCaptureDevice(videoDevices[cameraId].MonikerString);

            foreach (var item in videoDevice.VideoCapabilities)
            {
                if (item.FrameSize.Width == width && item.FrameSize.Height == height)
                {
                    videoDevice.VideoResolution = item;
                }
            }
            if (videoDevice.VideoResolution == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Example #12
0
        public CameraAForge(int camera, int width, int height, Action <byte[]> callBack)
        {
            _callBack    = callBack;
            _ffscale     = new FFScale(width, height, 3, 24, width, height, 0, 12);
            videoDevices = new AForge.Video.DirectShow.FilterInfoCollection(FilterCategory.VideoInputDevice);
            videoDevice  = new AForge.Video.DirectShow.VideoCaptureDevice(videoDevices[camera].MonikerString);
            foreach (var item in videoDevice.VideoCapabilities)
            {
                if (item.FrameSize.Width == width && item.FrameSize.Height == height)
                {
                    videoDevice.VideoResolution = item;
                }
            }
            if (videoDevice.VideoResolution == null)
            {
                throw new Exception(string.Format("摄像头不支持{0}*{1}分辨率", width, height));
            }

            videoDevice.NewFrame    += NewFrame;
            videoDevice.RGBRawFrame += YUVFrame;
        }
Example #13
0
        public void FindFace(PictureBox pb)
        {
            AForge.Video.DirectShow.VideoCaptureDevice   FinalVideoSource;
            AForge.Video.DirectShow.FilterInfoCollection VideoCaptuerDevices;
            VideoCaptuerDevices = new AForge.Video.DirectShow.FilterInfoCollection(AForge.Video.DirectShow.FilterCategory.VideoInputDevice);
            FinalVideoSource    = new AForge.Video.DirectShow.VideoCaptureDevice(VideoCaptuerDevices[0].MonikerString);

            FinalVideoSource.NewFrame += new AForge.Video.NewFrameEventHandler((sender, eventArgs) =>
            {
                Bitmap image = (Bitmap)eventArgs.Frame.Clone();
                pb.Image     = image;
            });

            FinalVideoSource.Start();
            FinalVideoSource.NewFrame += new AForge.Video.NewFrameEventHandler((sender, eventArgs) =>
            {
                Bitmap image = (Bitmap)eventArgs.Frame.Clone();
                //görüntüde yüz aranacağı belirtilir.
                Accord.Vision.Detection.Cascades.FaceHaarCascade cascade = new Accord.Vision.Detection.Cascades.FaceHaarCascade();
                //görüntü üzerinde arama yapar. İkinci parametresi minimum arama alanıdır.
                Accord.Vision.Detection.HaarObjectDetector detector = new Accord.Vision.Detection.HaarObjectDetector(cascade, 1);

                detector.SearchMode            = Accord.Vision.Detection.ObjectDetectorSearchMode.Single;
                detector.ScalingFactor         = 1.5f;
                detector.ScalingMode           = Accord.Vision.Detection.ObjectDetectorScalingMode.GreaterToSmaller;
                detector.UseParallelProcessing = true;
                detector.Suppression           = 3;
                Rectangle[] faces = detector.ProcessFrame(image);
                Graphics g        = Graphics.FromImage(image);
                foreach (var face in faces)
                {
                    Pen p = new Pen(Color.Red, 10f);
                    g.DrawRectangle(p, face);
                }
                g.Dispose();

                pb.Image = image;
            });
        }
Example #14
0
        public TakePicture(MainForm mainForm)
        {
            InitializeComponent();

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

            if (videosources != null)
            {
                //videoSource.GetCameraProperty(AForge.Video.DirectShow.CameraControlProperty.)
                videoSource           = new AForge.Video.DirectShow.VideoCaptureDevice(videosources[0].MonikerString);
                videoSource.NewFrame += (s, e) => {
                    if (pictureBox1.Image != null)
                    {
                        pictureBox1.Image.Dispose();
                        takenPicture.Dispose();
                    }

                    pictureBox1.Image = (Bitmap)e.Frame.Clone();
                    takenPicture      = (Bitmap)e.Frame.Clone();
                };
                videoSource.Start();
            }
        }
Example #15
0
        private void cmbDispositivos_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                //Se o index for maior do que 1, ou seja, se estiver algum item selecionado
                if (cmbDispositivos.SelectedIndex > -1)
                {
                    //será instanciado o videoSource de novo, com o valor selecionado do comboBox como parãmetro
                    _VideoSource = new AForge.Video.DirectShow.VideoCaptureDevice(_VideoSources[cmbDispositivos.SelectedIndex].MonikerString);

                    //o atributo NewFrame será igual a soma dele mesmo com o resultado do método VideoSourceNewFrame
                    _VideoSource.NewFrame += VideoSourceNewFrame;

                    //Será iniciado um novo frame
                    _VideoSource.Start();

                    this.Text = "Dispositivo : " + cmbDispositivos.SelectedItem.ToString();
                }
            }
            catch (Exception ex)
            {
                MetroMessageBox.Show(this, ex.Message, "Ocorreu um erro", MessageBoxButtons.OK, MessageBoxIcon.Error, 150);
            }
        }
        public Form1(int tempo, int qtd, string path, string nome)
        {
            InitializeComponent();
            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) =>
                {
                    if (pictureBox1.Image != null)
                    {
                        pictureBox1.Image.Dispose();
                    }

                    pictureBox1.Image = (Bitmap)e.Frame.Clone();
                };
                videoSource.Start();
            }
            timer1.Interval = tempo;
            _qtd            = qtd;
            _path           = path;
            _nomeOriginal   = nome;
        }
 public USBMocapRecorder(AForge.Video.DirectShow.VideoCaptureDevice device, string name, string moniker)
 {
     device_ = device;
     Name = name;
     Moniker = moniker;
 }
 public void Read(XmlElement element)
 {
     try
     {
         Name = element.GetAttribute("name");
         Moniker = element.GetElementsByTagName("moniker")[0].InnerText; ;
         device_ = new AForge.Video.DirectShow.VideoCaptureDevice(Moniker);
         XmlNodeList calib = element.GetElementsByTagName("CameraCalibrationData");
         if (calib.Count > 0)
         {
             Calibration = new Calibration.CameraCalibrationData();
             Calibration.Read(calib[0] as XmlElement);
         }
     }
     catch (Exception ex)
     {
         ErrorHandler.GetInst().PushError(ex);
     }
 }
        bool TrySetupDeviceOnce()
        {
            try
            {
                DisposeAForgeVideoCaptureInstance();

                AForgeVideoCaptureInstance = new AForge.Video.DirectShow.VideoCaptureDevice(VideoCaptureDeviceDevicePath);
                if (AForgeVideoCaptureInstance == null)
                {
                    if (ApplicationCommonSettings.IsDebugging)
                    {
                        Debugger.Break();
                    }
                    throw new EgsDeviceOperationException("AForgeVideoCaptureInstance == null.");
                }
                AForgeVideoCaptureInstance.NewFrame += AForgeVideoCaptureInstance_NewFrame;
                StartUvcIsWorkingMonitorTimer();
                UvcIsWorkingMonitorTimer.Tick += UvcIsWorkingMonitorTimer_Tick;

                // TODO: MUSTDO: AForgeVideoCaptureInstance.VideoResolution = AForgeVideoCaptureInstance.VideoCapabilities[someIndex]; で解像度が変わるが、
                // AForgeVideoCaptureInstance.IsRunning == true のままでは変更できない。
                // そしてSignalToStop()からのWaitForStop()メソッドの実行が完了しないことがある。
                // デバイスがKS版ではなく、後のネゴシエーションの更新版以降では問題ないのか?

                if (AForgeVideoCaptureInstance.VideoCapabilities == null)
                {
                    if (ApplicationCommonSettings.IsDebugging)
                    {
                        Debugger.Break();
                    }
                    throw new EgsDeviceOperationException("AForgeVideoCaptureInstance.VideoCapabilities == null");
                }
                if (VideoCaptureDeviceIndex < 0)
                {
                    if (ApplicationCommonSettings.IsDebugging)
                    {
                        Debugger.Break();
                    }
                    throw new EgsDeviceOperationException("VideoCaptureDeviceIndex < 0");
                }
                var videoCapabilityIndex = Device.Settings.CameraViewImageSourceBitmapSize.OptionalValue.SelectedIndex;
                if (videoCapabilityIndex < 0)
                {
                    if (ApplicationCommonSettings.IsDebugging)
                    {
                        Debugger.Break();
                    }
                    throw new EgsDeviceOperationException("videoCapabilityIndex < 0");
                }
                if (videoCapabilityIndex >= AForgeVideoCaptureInstance.VideoCapabilities.Length)
                {
                    if (ApplicationCommonSettings.IsDebugging)
                    {
                        Debugger.Break();
                    }
                    throw new EgsDeviceOperationException("videoCapabilityIndex >= AForgeVideoCaptureInstance.VideoCapabilities.Length");
                }

                var capability = AForgeVideoCaptureInstance.VideoCapabilities[videoCapabilityIndex];
                if (capability == null)
                {
                    if (ApplicationCommonSettings.IsDebugging)
                    {
                        Debugger.Break();
                    }
                    throw new EgsDeviceOperationException("capability == null");
                }
                int width = capability.FrameSize.Width;
                if (width == 0)
                {
                    if (ApplicationCommonSettings.IsDebugging)
                    {
                        Debugger.Break();
                    }
                    throw new EgsDeviceOperationException("width == 0");
                }
                int height = capability.FrameSize.Height;
                if (height == 0)
                {
                    if (ApplicationCommonSettings.IsDebugging)
                    {
                        Debugger.Break();
                    }
                    throw new EgsDeviceOperationException("height == 0");
                }

                AForgeVideoCaptureInstance.VideoResolution = capability;
                AForgeVideoCaptureInstance.Start();
                IsCameraDeviceConnected = true;

                return(true);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                if (ApplicationCommonSettings.IsDebugging)
                {
                    Debugger.Break();
                }
                return(false);
            }
        }
 public USBMocapRecorder(AForge.Video.DirectShow.VideoCaptureDevice device, string name, string moniker)
 {
     device_ = device;
     Name    = name;
     Moniker = moniker;
 }