コード例 #1
0
ファイル: WebCamViewModel.cs プロジェクト: armujahid/Captura
        public void Dispose()
        {
            _selectedCamera = null;

            if (_camControl.IsCapturing)
            {
                _camControl.StopCapture();
            }
        }
コード例 #2
0
        /// <summary>
        /// Get available capture devices
        /// </summary>
        public void CheckCaptureDevices()
        {
            var captureDevices = webCameraControl.GetVideoCaptureDevices();

            if (captureDevices != null && captureDevices.Count() > 0)
            {
                _captureDevice = captureDevices.First();
            }
        }
コード例 #3
0
        /// <summary>
        /// Starts a capture.
        /// </summary>
        /// <param name="camera">The camera to capture from.</param>
        /// <exception cref="ArgumentNullException">A null reference is passed as an argument.</exception>
        /// <exception cref="Win32Exception">Failed to load the DirectShow utilities dll.</exception>
        /// <exception cref="DirectShowException">Failed to run a video capture graph.</exception>
        public void StartCapture(WebCameraId camera)
        {
            if (camera == null)
            {
                throw new ArgumentNullException();
            }

            if (!_captureGraphInitialized)
            {
                InitializeCaptureGraph();

                _captureGraphInitialized = true;
            }

            if (IsCapturing)
            {
                if (_currentCamera == camera)
                {
                    return;
                }

                StopCapture();
            }

            if (_currentCamera != null)
            {
                Proxy.ResetCaptureGraph();
                _currentCamera = null;
            }

            Proxy.AddCaptureFilter(camera.DevicePath);
            _currentCamera = camera;

            try
            {
                Proxy.Start();
                IsCapturing = true;
            }
            catch (DirectShowException)
            {
                Proxy.ResetCaptureGraph();
                _currentCamera = null;
                throw;
            }
        }
コード例 #4
0
        private Bitmap GetWebCamImage()
        {
            Bitmap      image            = null;
            var         webCameraControl = new WebCameraControl();
            WebCameraId camera           = null;

            foreach (WebCameraId c in webCameraControl.GetVideoCaptureDevices())
            {
                if (c != null)
                {
                    camera = c;
                    break;
                }
            }
            if (camera != null)
            {
                webCameraControl.StartCapture(camera);
                System.Threading.Thread.Sleep(2000);
                image = webCameraControl.GetCurrentImage();
                System.Threading.Thread.Sleep(250);
                webCameraControl.StopCapture();
            }
            return(image);
        }
コード例 #5
0
 public ComboBoxItem(WebCameraId id)
 {
     _id = id;
 }
コード例 #6
0
ファイル: Form1.cs プロジェクト: ziVaza/cyber_project
 public ComboBoxItem(WebCameraId id)
 {
     _id = id;
 }
コード例 #7
0
        // Method to perform all the steps to take a picture.
        public void takePicture()
        {
            WebCameraControl control = new WebCameraControl();

            WebCameraId camera = null;

            if (control.GetVideoCaptureDevices().Count() > 0)
            {
                //Select the first camera we find. This can be more sophisticated.
                camera = (WebCameraId)control.GetVideoCaptureDevices().First();

                control.RenderSize = new System.Windows.Size(1920, 1080);

                control.StartCapture(camera);

                // This seems risky.
                // TODO change this to a more secure method of waiting.
                while (control.GetCurrentImage() == null)
                {
                }

                // Take 50 images (about 2 seconds.) The camera should have focussed and exposed correctly in that time.
                Image[]     img   = new Image[50];
                BitmapImage image = new BitmapImage();
                for (int i = 0; i < img.Length; i++)
                {
                    img[i] = control.GetCurrentImage();

                    MemoryStream ms = new MemoryStream();
                    img[i].Save(ms, ImageFormat.Bmp);
                    ms.Position = 0;
                    image       = new BitmapImage();
                    image.BeginInit();
                    ms.Seek(0, SeekOrigin.Begin);
                    image.StreamSource = ms;
                    image.EndInit();
                }
                // Store the image in DataDelegate.
                DataDelegate.customerImage = image;
                // Record the time taken.
                DataDelegate.timeCustomerImageTaken = DateTime.Now;
                control.StopCapture();

                // TODO Fix the code below to allow saving of the file to disk and/or to database.



                /*
                 * String path = System.IO.Path.Combine(Environment.CurrentDirectory, @"..\..\Assets\audio\PhotographComplete.wav");
                 * Audio.play(path);
                 *
                 * string filename = @"/GLASS/CustomerPhoto";
                 * string ext = @".png";
                 * var filePath = @Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), filename + ext);
                 *
                 * SaveFileDialog saveFile = new SaveFileDialog();
                 * saveFile.Filter = "PNG file |*.png";
                 * saveFile.FileName = filename + DateTime.Now.Date.Year + "-" + DateTime.Now.Date.Month + "-" + DateTime.Now.Date.Day + "-" + ext;
                 * saveFile.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                 *
                 * if (saveFile.ShowDialog() == DialogResult.OK)
                 * {
                 *  img.Last().Save(filePath);
                 * }
                 */
            }
        }
コード例 #8
0
        /// <summary>
        /// Stops a capture.
        /// </summary>
        /// <exception cref="InvalidOperationException">The control is not capturing a video stream.</exception>
        /// <exception cref="DirectShowException">Failed to stop a video capture graph.</exception>
        public void StopCapture()
        {
            if (!IsCapturing)
            {
                throw new InvalidOperationException();
            }

            Proxy.Stop();
            IsCapturing = false;

            Proxy.ResetCaptureGraph();
            _currentCamera = null;
        }
コード例 #9
0
ファイル: WebCamProvider.cs プロジェクト: stantoxt/Captura
            public WebCamModel(WebCameraId Cam, string Name)
            {
                this.Cam = Cam;

                _name = Name;
            }
コード例 #10
0
ファイル: WebCameraControl.cs プロジェクト: ThomasHana/WebEye
        /// <summary>
        /// Stops a capture.
        /// </summary>
        /// <exception cref="InvalidOperationException">The control is not capturing a video stream.</exception>
        /// <exception cref="DirectShowException">Failed to stop a video capture graph.</exception>
        public void StopCapture()
        {
            if (!_isCapturing)
            {
                throw new InvalidOperationException();
            }

            Utilities.Stop();
            _isCapturing = false;

            Utilities.ResetCaptureGraph();
            _currentCamera = null;
        }
コード例 #11
0
 public WebcamItem(WebCameraId Cam)
 {
     this.Cam = Cam ?? throw new ArgumentNullException(nameof(Cam));
     Name     = Cam.Name;
 }
コード例 #12
0
 private void OnStartButtonClick(object sender, RoutedEventArgs e)
 {
     _webcam = (WebCameraId)ComboBox.SelectedItem;
     Preview.StartCapture(_webcam);
 }