Exemplo n.º 1
0
        public void InitializeCamera(string cameraName)
        {
            if (VideoDevices == null)
            {
                GetCameras();
            }

            var selected = VideoDevices.Where(x => x.Name == cameraName).FirstOrDefault().MonikerString;

            VideoSource = new VideoCaptureDevice(selected);

            // Then, we just have to define what we would like to do once the device send
            // us a new frame. This can be done using standard .NET events (the actual
            // contents of the video_NewFrame method is shown at the bottom of this page)
            videoSourcePlayer.VideoSource = VideoSource;
            videoSourcePlayer.Start();
        }
Exemplo n.º 2
0
        private void boxCaptureDevice_SelectedIndexChanged(object sender, EventArgs e)
        {
            // May need to tweak more
            if (boxCaptureDevice.SelectedItem.ToString() == VideoDevice)
            {
                return;
            }

            if (_Component.Scanner.IsVideoSourceRunning())
            {
                _Component.Scanner.Stop();
            }
retry:
            var videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            var matches = videoDevices.Where(v => v.ToString() == boxCaptureDevice.Text);

            if (matches.Count() > 0)
            {
                var match = matches.First();
                VideoDevice = match.ToString();
                _Component.Scanner.AsyncStart();
            }
            else
            {
                lblCaptureDevice.Text = "Capture Device";
                DialogResult dr = MessageBox.Show(
                    "Selected video capture device cannont be found. Has it been unplugged?",
                    "Error",
                    MessageBoxButtons.RetryCancel,
                    MessageBoxIcon.Error
                    );

                if (dr == DialogResult.Retry)
                {
                    goto retry;
                }
                else
                {
                    FillboxCaptureDevice();
                }
            }
        }
Exemplo n.º 3
0
        internal bool FillboxCaptureDevice()
        {
            var videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

            if (videoDevices.Count > 0)
            {
                boxCaptureDevice.Enabled = true;

                int selectedIndex = boxCaptureDevice.SelectedIndex;
                boxCaptureDevice.Items.Clear();

                if (!string.IsNullOrEmpty(VideoDevice))
                {
                    var savedDevices = videoDevices.Where(d => d.ToString() == VideoDevice);
                    if (savedDevices.Count() > 0)
                    {
                        var savedDevice = savedDevices.First();
                        selectedIndex = videoDevices.IndexOf(savedDevice);
                    }
                }

                for (var i = 0; i < videoDevices.Count; i++)
                {
                    boxCaptureDevice.Items.Add(videoDevices[i]);
                }

                boxCaptureDevice.SelectedIndex = selectedIndex;
                return(true);
            }
            else
            {
                boxCaptureDevice.Enabled = false;
                boxCaptureDevice.Items.Clear();
                return(false);
            }
        }
Exemplo n.º 4
0
        private void BoxCaptureDevice_SelectedIndexChanged(object sender, EventArgs e)
        {
            Scanner.Stop();
retry:
            var videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            var matches = videoDevices.Where(v => v.Name == BoxCaptureDevice.Text);

            if (matches.Count() > 0)
            {
                var match = matches.First();
                Scanner.SetVideoSource(match.MonikerString);
                lblCaptureDevice.Text = "Capture Device - " + Scanner.VideoGeometry.ToString();
                Properties.Settings.Default.VideoDevice = BoxCaptureDevice.Text;
                Properties.Settings.Default.Save();
            }
            else
            {
                lblCaptureDevice.Text = "Capture Device";
                DialogResult dr = MessageBox.Show(
                    "Selected video capture device cannont be found. Has it been unplugged?",
                    "Error",
                    MessageBoxButtons.RetryCancel,
                    MessageBoxIcon.Error
                    );

                if (dr == DialogResult.Retry)
                {
                    goto retry;
                }
                else
                {
                    FillBoxCaptureDevice();
                }
            }
            TryStart();
        }