private void Initialize()
        {
            if (_videoSource == null)
            {
                // create video source
                _videoSource = _applicationConfiguration.SelectedVideoCaptureDevice == null
                    ? new VideoCaptureDevice(_videoDevices.GetDefaultDeviceName())
                    : new VideoCaptureDevice(_applicationConfiguration.SelectedVideoCaptureDevice.MonikerString);
            }

            if (_videoCapturePipeline == null)
            {
                _videoCapturePipeline = Observable.FromEvent <NewFrameEventHandler, NewFrameEventArgs>(
                    d =>
                {
                    NewFrameEventHandler nfeHandler = (sender, e) => d(e);
                    return(nfeHandler);
                }, h => _videoSource.NewFrame += h, h => _videoSource.NewFrame -= h)
                                        .Select(e => e.Frame)
                                        .Subscribe(frame =>
                {
                    if (DateTime.Now - _lastCaptureTime <
                        TimeSpan.FromSeconds(_applicationConfiguration.FrameCaptureInterval))
                    {
                        return;
                    }

                    _mediator.SendMessageAsync(this,
                                               frame.Clone(new Rectangle(0, 0, frame.Width, frame.Height), frame.PixelFormat));

                    _lastCaptureTime = DateTime.Now;
                }, exception => Debug.Write(exception));
            }
        }
 public void Start()
 {
     // create video source
     _videoSource = _applicationConfiguration.SelectedVideoCaptureDevice == null
         ? new VideoCaptureDevice(_videoDevices.GetDefaultDeviceName())
         : new VideoCaptureDevice(_applicationConfiguration.SelectedVideoCaptureDevice.MonikerString);
     // set NewFrame event handler
     _videoSource.NewFrame += video_NewFrame;
     // start the video source
     _videoSource.Start();
 }