Exemplo n.º 1
0
        /// <summary>
        /// Initialize webcam, set source for StreamElement and start process of face detection
        /// </summary>
        /// <returns></returns>
        private async Task InitializeVideoAsync()
        {
            StatusTextBlock.Text = "Opening video stream...";
            try
            {
                // we only need video from our webcam
                var settings = new MediaCaptureInitializationSettings {
                    StreamingCaptureMode = StreamingCaptureMode.Video
                };
                var mediaCapture = new MediaCapture();
                await mediaCapture.InitializeAsync(settings);

                // set source to see ourselves on the screen
                StreamingElement.Source = mediaCapture;
                await mediaCapture.StartPreviewAsync();

                // start face detection for the first time
                _faceMatrix = await FaceMatrix.CreateAsync(mediaCapture, CellsRowsCount, CellsColumnsCount);

                StatusTextBlock.Text = "Live video";
            }
            catch (UnauthorizedAccessException)
            {
                //We'll get this if the webcam is disabled, or inaccessible.
                StatusTextBlock.Text = "Unable to access the webcam. Ensure that it is connected, and that the app has permission to access it. In addition, ensure that \"Webcam\" is declared in the AppManifest's Capabilities.";
            }
            catch (Exception ex)
            {
                StatusTextBlock.Text = $"Start webcam error: {ex}";
            }
        }
Exemplo n.º 2
0
        public static async Task<FaceMatrix> CreateAsync(MediaCapture mediaCapture, int rowsCount, int columnsCount)
        {
            var faceTracker = await FaceTracker.CreateAsync();
            var faceMatrix = new FaceMatrix(faceTracker, mediaCapture, rowsCount, columnsCount);
            faceMatrix.StartRecognitionLoop();

            return faceMatrix;
        }
Exemplo n.º 3
0
        public static async Task <FaceMatrix> CreateAsync(MediaCapture mediaCapture, int rowsCount, int columnsCount)
        {
            var faceTracker = await FaceTracker.CreateAsync();

            var faceMatrix = new FaceMatrix(faceTracker, mediaCapture, rowsCount, columnsCount);

            faceMatrix.StartRecognitionLoop();

            return(faceMatrix);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initialize webcam, set source for StreamElement and start process of face detection
        /// </summary>
        /// <returns></returns>
        private async Task InitializeVideoAsync()
        {
            StatusTextBlock.Text = "Opening video stream...";
            try
            {
                // we only need video from our webcam
                var settings = new MediaCaptureInitializationSettings {StreamingCaptureMode = StreamingCaptureMode.Video};
                var mediaCapture = new MediaCapture();
                await mediaCapture.InitializeAsync(settings);

                // set source to see ourselves on the screen
                StreamingElement.Source = mediaCapture;
                await mediaCapture.StartPreviewAsync();

                // start face detection for the first time
                _faceMatrix = await FaceMatrix.CreateAsync(mediaCapture, CellsRowsCount, CellsColumnsCount);
                StatusTextBlock.Text = "Live video";
            }
            catch (UnauthorizedAccessException)
            {
                //We'll get this if the webcam is disabled, or inaccessible.
                StatusTextBlock.Text = "Unable to access the webcam. Ensure that it is connected, and that the app has permission to access it. In addition, ensure that \"Webcam\" is declared in the AppManifest's Capabilities.";
            }
            catch (Exception ex)
            {
                StatusTextBlock.Text = $"Start webcam error: {ex}";
            }
        }