private void cmdStartCapture_Click(object sender, RoutedEventArgs e)
        {
            if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess())
            {
                // Permission has been granted.

                // It's always safe to call this Stop(), even if no capture is running.
                // However, calling Start() while a capture is already running causes an error.
                capture.Stop();

                // Get the default webcam.
                capture.VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
                if (capture.VideoCaptureDevice == null)
                {
                    MessageBox.Show("Your computer does not have a video capture device.");
                }
                else
                {
                    // Start a new capture.
                    capture.Start();

                    // Map the live video to a VideoBrush.
                    VideoBrush videoBrush = new VideoBrush();
                    videoBrush.Stretch = Stretch.Uniform;
                    videoBrush.SetSource(capture);

                    // Use the VideoBrush to paint the fill of a Rectangle.
                    rectWebcamDisplay.Fill = videoBrush;
                }
            }
        }
Example #2
0
 void ToggleDevice(object sender, RoutedEventArgs e)
 {
     if (this.on)
     {
         this.videoSurface.Fill = new SolidColorBrush(Colors.White);
         this.source.Stop();
         this.toggleButton.Content        = "Turn On";
         this.takePictureButton.IsEnabled = false;
         this.on = false;
     }
     else
     {
         if (CaptureDeviceConfiguration.AllowedDeviceAccess ||
             CaptureDeviceConfiguration.RequestDeviceAccess())
         {
             this.source.Start();
             var vidBrush = new VideoBrush();
             vidBrush.SetSource(this.source);
             this.videoSurface.Fill           = vidBrush;
             this.toggleButton.Content        = "Turn Off";
             this.takePictureButton.IsEnabled = true;
             this.on = true;
         }
     }
 }
Example #3
0
        public void StartWebCam()
        {
            _captureSource = new CaptureSource();
            _captureSource.CaptureImageCompleted += new EventHandler <CaptureImageCompletedEventArgs>(_captureSource_CaptureImageCompleted);
            _captureSource.VideoCaptureDevice     = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();

            try
            {
                // Start capturing
                if (_captureSource.State != CaptureState.Started)
                {
                    // Create video brush and fill the WebcamVideo rectangle with it
                    var vidBrush = new VideoBrush();
                    vidBrush.Stretch = Stretch.Uniform;
                    vidBrush.SetSource(_captureSource);
                    WebcamVideo.Fill = vidBrush;

                    // Ask user for permission and start the capturing
                    if (CaptureDeviceConfiguration.RequestDeviceAccess())
                    {
                        _captureSource.Start();
                    }
                }
            }
            catch (InvalidOperationException)
            {
                InfoTextBox.Text = "Web Cam already started - if not, I can't find it...";
            }
            catch (Exception)
            {
                InfoTextBox.Text = "Could not start web cam, do you have one?";
            }
        }
Example #4
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            // Delayed due to Camera init bug in WP71 SDK Beta 2
            // See http://forums.create.msdn.com/forums/p/85830/516843.aspx
            Dispatcher.BeginInvoke(() =>
            {
                // Initialize the webcam
                photoCamera                          = new PhotoCamera();
                photoCamera.Initialized             += PhotoCameraInitialized;
                CameraButtons.ShutterKeyHalfPressed += PhotoCameraButtonHalfPress;
                isInitialized                        = false;
                isDetecting                          = false;

                // Fill the Viewport Rectangle with the VideoBrush
                var vidBrush = new VideoBrush();
                vidBrush.SetSource(photoCamera);
                Viewport.Fill = vidBrush;

                // Start timer
                dispatcherTimer = new DispatcherTimer {
                    Interval = TimeSpan.FromMilliseconds(50)
                };
                dispatcherTimer.Tick += (sender, e1) => Detect();
                dispatcherTimer.Start();
            });
        }
        private void btCapture_Click(object sender, RoutedEventArgs e)
        {
            if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess())
            {
                VideoCaptureDevice webcam = cboWebcams.SelectedItem as VideoCaptureDevice;

                if (webcam == null)
                {
                    CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
                }

                if (webcam != null)
                {
                    capture.Stop();
                    capture.VideoCaptureDevice = webcam;
                    capture.Start();


                    VideoBrush brush = new VideoBrush();
                    brush.SetSource(capture);
                    brush.Stretch    = Stretch.Uniform;
                    captureRect.Fill = brush;
                }
                else
                {
                    MessageBox.Show("Nessuna webcam disponibile");
                }
            }
        }
Example #6
0
        private async Task InitCamera()
        {
            if (!PhotoCaptureDevice.AvailableSensorLocations.Contains(CameraSensorLocation.Back))
            {
                MessageBox.Show("No primary camera found. Unable to capture photos.", "Error", MessageBoxButton.OK);
                cameraButton.IsEnabled = false;
                return;
            }

            System.Collections.Generic.IReadOnlyList <Windows.Foundation.Size> supportedResolutions = PhotoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back);

            Windows.Foundation.Size res = GetResolution(supportedResolutions);
            Camera = await PhotoCaptureDevice.OpenAsync(CameraSensorLocation.Back, res);

            Camera.SetProperty(KnownCameraPhotoProperties.FlashMode, FlashState.Off);
            Camera.SetProperty(KnownCameraGeneralProperties.PlayShutterSoundOnCapture, App.ShutterSoundEnabled);
            Camera.SetProperty(KnownCameraGeneralProperties.AutoFocusRange, AutoFocusRange.Normal);
            CameraButtons.ShutterKeyHalfPressed += OnCameraButtonHalfPress;
            CameraButtons.ShutterKeyPressed     += OnCameraButtonFullPress;

            var viewFinderTransform = new CompositeTransform();

            viewFinderTransform.CenterX       = 0.5;
            viewFinderTransform.CenterY       = 0.5;
            viewfinderBrush                   = new VideoBrush();
            viewfinderBrush.RelativeTransform = viewFinderTransform;
            viewfinderBrush.Stretch           = Stretch.UniformToFill;
            camCanvas.Background              = viewfinderBrush;
            viewfinderBrush.SetSource(Camera);
            m_canTakePicture = true;
        }
Example #7
0
        void Load()
        {
            if (CaptureDeviceConfiguration.AllowedDeviceAccess ||
                CaptureDeviceConfiguration.RequestDeviceAccess())
            {
                var devices = CaptureDeviceConfiguration.GetAvailableVideoCaptureDevices();

                foreach (var device in devices)
                {
                    var videoItem = new VideoItem();
                    videoItem.Name = device.FriendlyName;

                    var source = new CaptureSource();
                    source.VideoCaptureDevice = device;
                    var videoBrush = new VideoBrush();
                    videoBrush.SetSource(source);
                    videoItem.Brush = videoBrush;
                    this.sources.Add(source);
                    this.sourceItems.Add(videoItem);
                }

                this.videoItems.ItemsSource = this.sourceItems;
                this.StartAll();
            }
        }
        private void UserControlLoaded(object sender, RoutedEventArgs e)
        {
            // Initialize the webcam
            captureSource = new CaptureSource();
            captureSource.VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();

            // Desired format is 640 x 480 (good tracking results and performance)
            captureSource.VideoCaptureDevice.DesiredFormat = new VideoFormat(PixelFormatType.Unknown, 640, 480, 60);
            captureSource.CaptureImageCompleted           += CaptureSourceCaptureImageCompleted;

            // Fill the Viewport Rectangle with the VideoBrush
            var vidBrush = new VideoBrush();

            vidBrush.SetSource(captureSource);
            Viewport.Fill = vidBrush;

            //  Conctruct the Detector
            arDetector = new BitmapMarkerDetector {
                Threshold = 200, JitteringThreshold = 1
            };

            // Load the marker patterns. It has 16x16 segments and a width of 80 millimeters
            slarMarker = Marker.LoadFromResource("data/Marker_SLAR_16x16segments_80width.pat", 16, 16, 80);
            lMarker    = Marker.LoadFromResource("data/Marker_L_16x16segments_80width.pat", 16, 16, 80);
        }
Example #9
0
        public void start()
        {
            if (captureSource == null)
            {
                // Create the VideoRecorder objects.
                captureSource = new CaptureSource();
                fileSink      = new FileSink();

                videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();

                // Add eventhandlers for captureSource.
                captureSource.CaptureFailed += new EventHandler <ExceptionRoutedEventArgs>(OnCaptureFailed);

                // Initialize the camera if it exists on the device.
                if (videoCaptureDevice != null)
                {
                    // Create the VideoBrush for the viewfinder.
                    videoRecorderBrush = new VideoBrush();
                    videoRecorderBrush.SetSource(captureSource);
                    videoRecorderBrush.RelativeTransform = new CompositeTransform()
                    {
                        CenterX = 0.5, CenterY = 0.5, Rotation = 90
                    };
                    viewfinderRectangle.Fill = videoRecorderBrush;

                    // Start video capture and display it on the viewfinder.
                    captureSource.Start();
                    System.Diagnostics.Debug.WriteLine("Started");
                    _isRunning = true;
                }
            }
        }
Example #10
0
        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            btnSaveRaw.IsEnabled = false;
            btnPlayRaw.IsEnabled = false;

            videoCapture.Height           = VideoConstants.Height;
            videoCapture.Width            = VideoConstants.Width;
            mRawMediaElement.Height       = VideoConstants.Height;
            mRawMediaElement.Width        = VideoConstants.Width;
            mProcessedMediaElement.Height = VideoConstants.Height;
            mProcessedMediaElement.Width  = VideoConstants.Width;

            // Initialize and capture the webcam.
            InitializeCaptureSource();
            CaptureSelectedInputDevices();
            var videoBrush = new VideoBrush();

            videoBrush.SetSource(mCaptureSource);
            videoCapture.Fill = videoBrush;

            // Setup the recorder
            mVideoQualityController = new TestVideoQualityController();
            mRecorder  = new Recorder();
            mVideoSink = new VideoSinkAdapter(mCaptureSource, mRecorder, mVideoQualityController);
            lblFramesRecorded.DataContext = mRecorder;
        }
Example #11
0
        void InitializeVideoRecorder(Rectangle viewfinderRectangle)
        {
            if (captureSource == null)
            {
                // Create the VideoRecorder objects.
                captureSource = new CaptureSource();
                fileSink      = new FileSink();

                videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();

                // Add eventhandlers for captureSource.
                captureSource.CaptureFailed += new EventHandler <ExceptionRoutedEventArgs>(OnCaptureFailed);

                // Initialize the camera if it exists on the device.
                if (videoCaptureDevice != null)
                {
                    // Create the VideoBrush for the viewfinder.
                    videoRecorderBrush = new VideoBrush();
                    videoRecorderBrush.SetSource(captureSource);

                    // Display the viewfinder image on the rectangle.
                    viewfinderRectangle.Fill = videoRecorderBrush;

                    // Start video capture and display it on the viewfinder.
                    captureSource.Start();
                }
                else
                {
                    // A camera is not supported on this device
                }
            }
        }
Example #12
0
        private static void VideoSouceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CaptureSource video = (CaptureSource)e.NewValue;
            VideoBrush    vb    = (VideoBrush)d;

            vb.SetSource(video);
        }
Example #13
0
        private void ButtonStart_Click(object sender, RoutedEventArgs eargs)
        {
            try
            {
                // Start capturing
                if (_captureSource.State != CaptureState.Started)
                {
                    // Create video brush and fill the WebcamVideo rectangle with it
                    var vidBrush = new VideoBrush();
                    vidBrush.Stretch = Stretch.Uniform;
                    vidBrush.SetSource(_captureSource);
                    WebcamVideo.Fill = vidBrush;

                    // Ask user for permission and start the capturing
                    if (CaptureDeviceConfiguration.RequestDeviceAccess())
                    {
                        _captureSource.Start();
                    }
                }
            }
            catch (InvalidOperationException ex)
            {
                TextBoxInfo.Text = "Web Cam already started - if not, I can't find it...";
            }
            catch (Exception)
            {
                TextBoxInfo.Text = "Could not start web cam, do you have one?";
            }
        }
Example #14
0
        public void EnsureNotFrozen()
        {
            VideoBrush vb = new VideoBrush();

            Assert.IsTrue(MatrixTransformTest.CheckFreezer(vb.RelativeTransform as MatrixTransform), "RelativeTransform");
            Assert.IsTrue(MatrixTransformTest.CheckFreezer(vb.Transform as MatrixTransform), "Transform");
        }
Example #15
0
        public void Init()
        {
            // Initialize the webcams
            ReadOnlyCollection <VideoCaptureDevice> videoCams = CaptureDeviceConfiguration.GetAvailableVideoCaptureDevices();

            try
            {
                foreach (VideoCaptureDevice videoCam in videoCams)
                {
                    captureSources.Add(new CaptureSource()
                    {
                        VideoCaptureDevice = videoCam
                    });
                }

                captureSourceLeftIndex   = 0 % captureSources.Count;
                captureSourceCenterIndex = 1 % captureSources.Count;
                captureSourceRightIndex  = 2 % captureSources.Count;
            }
            catch {
                Stop();
                return;
            }

            videoBrushLeft   = new VideoBrush();
            videoBrushCenter = new VideoBrush();
            videoBrushRight  = new VideoBrush();

            if (!initialized)
            {
                Start();
                initialized = true;
            }
        }
Example #16
0
        private void SetupMarkerTracking(VideoBrush videoBrush)
        {
            IVideoCapture captureDevice = null;

            captureDevice = new PhoneCameraCapture(videoBrush);
            captureDevice.InitVideoCapture(0, FrameRate._30Hz, Resolution._640x480, ImageFormat.B8G8R8A8_32, false);
            ((PhoneCameraCapture)captureDevice).UseLuminance = true;

            if (betterFPS)
            {
                captureDevice.MarkerTrackingImageResizer = new HalfResizer();
            }

            // Add this video capture device to the scene so that it can be used for the marker tracker
            scene.AddVideoCaptureDevice(captureDevice);

            NyARToolkitIdTracker tracker = new NyARToolkitIdTracker();

            if (captureDevice.MarkerTrackingImageResizer != null)
            {
                tracker.InitTracker((int)(captureDevice.Width * captureDevice.MarkerTrackingImageResizer.ScalingFactor),
                                    (int)(captureDevice.Height * captureDevice.MarkerTrackingImageResizer.ScalingFactor),
                                    "camera_para.dat");
            }
            else
            {
                tracker.InitTracker(captureDevice.Width, captureDevice.Height, "camera_para.dat");
            }

            // Set the marker tracker to use for our scene
            scene.MarkerTracker = tracker;
        }
Example #17
0
        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            captureSource = new CaptureSource
            {
                VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice()
            };

            var videoBrush = new VideoBrush();

            videoBrush.SetSource(captureSource);
            Viewport.Fill = videoBrush;

            markerDetector = new CaptureSourceMarkerDetector();
            var marker = Marker.LoadFromResource("Bola.pat", 64, 64, 80);

            markerDetector.Initialize(captureSource, 1d, 4000d, marker);

            markerDetector.MarkersDetected += (obj, args) =>
            {
                Dispatcher.BeginInvoke(() =>
                {
                    var results = args.DetectionResults;
                    if (results.HasResults)
                    {
                        var centerAtOrigin =
                            Matrix3DFactory.
                            CreateTranslation(
                                -Imagem.ActualWidth *
                                0.5,
                                -Imagem.
                                ActualHeight *
                                0.5, 0);
                        var scale =
                            Matrix3DFactory.CreateScale
                                (0.5, -0.5, 0.5);
                        var world = centerAtOrigin *
                                    scale *
                                    results[0].
                                    Transformation;
                        var vp =
                            Matrix3DFactory.
                            CreateViewportTransformation
                                (Viewport.ActualWidth,
                                Viewport.ActualHeight);
                        var m =
                            Matrix3DFactory.
                            CreateViewportProjection
                                (world,
                                Matrix3D.Identity,
                                markerDetector.
                                Projection, vp);
                        Imagem.Projection =
                            new Matrix3DProjection
                        {
                            ProjectionMatrix = m
                        };
                    }
                });
            };
        }
Example #18
0
        void ToggleDevice(object sender, RoutedEventArgs e)
        {
            if (on)
            {
                this.videoSurface.Fill = new SolidColorBrush(Colors.White);
                this.source.Stop();
                this.toggleButton.Content = "Record";
                this.playButton.IsEnabled = true;
                on = false;
            }
            else
            {
                if (CaptureDeviceConfiguration.AllowedDeviceAccess ||
                    CaptureDeviceConfiguration.RequestDeviceAccess())
                {
                    this.encoder = new VideoEncoder();
                    //C:\hods\Presentations\OfflineWebCam\VideoCapture.Web\VideoCapture.Silverlight\VideoDecoder.cs
                    this.encoder.CaptureSource = this.source;

                    this.source.Start();

                    VideoBrush vidBrush = new VideoBrush();
                    vidBrush.SetSource(this.source);
                    this.videoSurface.Fill    = vidBrush;
                    this.toggleButton.Content = "Stop";
                    this.playButton.IsEnabled = false;
                    on = true;
                }
            }
        }
Example #19
0
        public void InitializeVideoRecorder()
        {
            if (captureSource == null)
            {
                // Create the VideoRecorder objects.
                captureSource      = new CaptureSource();
                fileSink           = new FileSink();
                videoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();

                captureSource.CaptureImageCompleted += captureSource_CaptureImageCompleted;
                // Add eventhandlers for captureSource.
                captureSource.CaptureFailed += new EventHandler <ExceptionRoutedEventArgs>(OnCaptureFailed);
                // Initialize the camera if it exists on the device.
                if (videoCaptureDevice != null)
                {
                    // Create the VideoBrush for the viewfinder.
                    videoRecorderBrush = new VideoBrush();
                    videoRecorderBrush.SetSource(captureSource);

                    // Display the viewfinder image on the rectangle.
                    viewfinderRectangle.Fill = videoRecorderBrush;

                    // Start video capture and display it on the viewfinder.
                    captureSource.Start();

                    // Set the button state and the message.
                    UpdateUI(ButtonState.Initialized, "Tap record to start recording...");
                }
                else
                {
                    // Disable buttons when the camera is not supported by the device.
                    UpdateUI(ButtonState.CameraNotSupported, "A camera is not supported on this device.");
                }
            }
        }
Example #20
0
 public QRModel(VideoBrush video)
 {
     reader = new PhoneBarcodeReader();
     reader.CodeAvailable += async code => {
         await PhoneUtil.OnUiThread(() => Code = code);
     };
     this.video = video;
 }
Example #21
0
        /// <summary>
        /// Creates a <see cref="VideoBrush" /> containing the current image.
        /// </summary>
        /// <returns>A <see cref="VideoBrush" /> containing the current image.</returns>
        public VideoBrush CreateVideoBrush()
        {
            var videoBrush = new VideoBrush();

            videoBrush.SetSource(_photoCamera);

            return(videoBrush);
        }
Example #22
0
        public void Destructive()
        {
            VideoBrush vb = new VideoBrush();

            // from this instance we can change all default values
            BrushTest.DestructiveRelativeTransform(vb);
            BrushTest.DestructiveTransform(vb);
            // but it's safe to execute since we revert the changes
        }
Example #23
0
        public void BindVideoBrush(VideoBrush brush)
        {
            if (_device == null)
            {
                throw new InvalidOperationException("device is null");
            }

            brush.SetSource(_device);
        }
Example #24
0
        private void SetupMarkerTracking(VideoBrush videoBrush)
        {
            IVideoCapture captureDevice = null;

            if (useStaticImage)
            {
                captureDevice = new NullCapture();
                captureDevice.InitVideoCapture(0, FrameRate._30Hz, Resolution._320x240,
                                               ImageFormat.B8G8R8A8_32, false);
                if (useSingleMarker)
                {
                    ((NullCapture)captureDevice).StaticImageFile = "MarkerImageHiro.jpg";
                }
                else
                {
                    ((NullCapture)captureDevice).StaticImageFile = "MarkerImage_320x240";
                }

                scene.ShowCameraImage = true;
            }
            else
            {
                captureDevice = new PhoneCameraCapture(videoBrush);
                captureDevice.InitVideoCapture(0, FrameRate._30Hz, Resolution._640x480,
                                               ImageFormat.B8G8R8A8_32, false);
                ((PhoneCameraCapture)captureDevice).UseLuminance = true;

                if (betterFPS)
                {
                    captureDevice.MarkerTrackingImageResizer = new HalfResizer();
                }
            }

            // Add this video capture device to the scene so that it can be used for
            // the marker tracker
            scene.AddVideoCaptureDevice(captureDevice);

#if USE_PATTERN_MARKER
            NyARToolkitTracker tracker = new NyARToolkitTracker();
#else
            NyARToolkitIdTracker tracker = new NyARToolkitIdTracker();
#endif

            if (captureDevice.MarkerTrackingImageResizer != null)
            {
                tracker.InitTracker((int)(captureDevice.Width * captureDevice.MarkerTrackingImageResizer.ScalingFactor),
                                    (int)(captureDevice.Height * captureDevice.MarkerTrackingImageResizer.ScalingFactor),
                                    "camera_para.dat");
            }
            else
            {
                tracker.InitTracker(captureDevice.Width, captureDevice.Height, "camera_para.dat");
            }

            // Set the marker tracker to use for our scene
            scene.MarkerTracker = tracker;
        }
Example #25
0
        public void InitCamera(VideoBrush CurrentVideoBrush)
        {
            this.Camera = new PhotoCamera(CameraType.Primary);

            this.Camera.Initialized           += Camera_Initialized;
            this.Camera.CaptureCompleted      += Camera_CaptureCompleted;
            this.Camera.CaptureImageAvailable += Camera_CaptureImageAvailable;
            //Set the VideoBrush source to the camera.
            CurrentVideoBrush.SetSource(Camera);
        }
Example #26
0
        public void NullSource()
        {
            VideoBrush vb = new VideoBrush();

            Assert.Throws <NullReferenceException> (delegate {
                vb.SetSource((MediaElement)null);
            }, "MediaElement");
            Assert.Throws <NullReferenceException> (delegate {
                vb.SetSource((CaptureSource)null);
            }, "CaptureSource");
        }
Example #27
0
 // Constructor
 public MainPage()
 {
     InitializeComponent();
     rotation        = new RotateTransform();
     cameraViewBrush = new VideoBrush();
     purchaser       = new PurchaseInterface();
     camHeight       = 0;
     run             = 0;
     pitch           = 0;
     adFailed        = false;
 }
Example #28
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _videoBrush = GetTemplateChild(VideoBrushName) as VideoBrush;

            if (_photoCamera == null && _videoBrush != null)
            {
                InitializePhotoCamera();
            }
        }
Example #29
0
        public Camera(VideoBrush video, int photocount)
        {
            if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary) == true)
            {
                // There is a camera. Which I already know. But useful if I decide to use this in any other apps.

                cam        = new Microsoft.Devices.PhotoCamera(CameraType.Primary);
                photoname  = photocount;
                videobrush = video;
            }
        }
Example #30
0
        public override void OnApplyTemplate()
        {
            _videoPreviewBrush = this.GetTemplateChild(_videoPreviewBrushName) as VideoBrush;

            //do not perfom heavy initialization in design mode
            if (!DesignerProperties.IsInDesignTool)
            {
                LoadCameraBrush();
            }
            base.OnApplyTemplate();
        }