Example #1
0
        private async void InitMediaCapture()
        {
            mediaCapture = null;
            mediaCapture = new Windows.Media.Capture.MediaCapture();

            // for dispose purpose
            (App.Current as App).MediaCapture   = mediaCapture;
            (App.Current as App).PreviewElement = capturePreview;

            await mediaCapture.InitializeAsync(captureInitSettings);

            // Add video stabilization effect during Live Capture
            //await _mediaCapture.AddEffectAsync(MediaStreamType.VideoRecord, Windows.Media.VideoEffects.VideoStabilization, null); //this will be deprecated soon
            Windows.Media.Effects.VideoEffectDefinition def = new Windows.Media.Effects.VideoEffectDefinition(Windows.Media.VideoEffects.VideoStabilization);
            await mediaCapture.AddVideoEffectAsync(def, MediaStreamType.VideoRecord);

            CreateProfile();

            // start preview

            capturePreview.Source = mediaCapture;

            DisplayInformation.AutoRotationPreferences = DisplayOrientations.None;

            //// set the video Rotation
            //    _mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
            //    _mediaCapture.SetRecordRotation(VideoRotation.Clockwise90Degrees);
        }
Example #2
0
		protected override async void Start()
		{
			ResourceCache.AutoReloadResources = true;
			base.Start();

			EnableGestureTapped = true;

			busyIndicatorNode = Scene.CreateChild();
			busyIndicatorNode.SetScale(0.06f);
			busyIndicatorNode.CreateComponent<BusyIndicator>();

			mediaCapture = new MediaCapture();
			await mediaCapture.InitializeAsync();
			await mediaCapture.AddVideoEffectAsync(new MrcVideoEffectDefinition(), MediaStreamType.Photo);
			await RegisterCortanaCommands(new Dictionary<string, Action> {
					{"Describe", () => CaptureAndShowResult(false)},
					{"Read this text", () => CaptureAndShowResult(true)}, 
					{"Enable preview", () => EnablePreview(true) },
					{"Disable preview", () => EnablePreview(false) },
					{"Help", Help }
				});
			
			ShowBusyIndicator(true);
			await TextToSpeech("Welcome to the Microsoft Cognitive Services sample for HoloLens and UrhoSharp.");
			ShowBusyIndicator(false);

			inited = true;
		}
Example #3
0
		/// <summary>
		/// Continuously look for a QR code
		/// NOTE: this method won't work if recording is enabled ('hey Cortana, start recording' thing).
		/// </summary>
		public static async Task<string> ReadAsync(CancellationToken token = default(CancellationToken))
		{
			var mediaCapture = new MediaCapture();
			await mediaCapture.InitializeAsync();
			await mediaCapture.AddVideoEffectAsync(new MrcVideoEffectDefinition(), MediaStreamType.Photo);

			var reader = new BarcodeReader();
			reader.Options.TryHarder = false;

			while (!token.IsCancellationRequested)
			{
				var imgFormat = ImageEncodingProperties.CreateJpeg();
				using (var ras = new InMemoryRandomAccessStream())
				{
					await mediaCapture.CapturePhotoToStreamAsync(imgFormat, ras);
					var decoder = await BitmapDecoder.CreateAsync(ras);
					using (var bmp = await decoder.GetSoftwareBitmapAsync())
					{
						Result result = await Task.Run(() =>
							{
								var source = new SoftwareBitmapLuminanceSource(bmp);
								return reader.Decode(source);
							});
						if (!string.IsNullOrEmpty(result?.Text))
							return result.Text;
					}
				}
				await Task.Delay(DelayBetweenScans);
			}
			return null;
		}
        // Enables the grayscale effect.
        private async void AddRemoveEffect_Checked(object sender, RoutedEventArgs e)
        {
            try
            {
                AddRemoveEffect.IsEnabled = false;
                VideoEffectDefinition def = new VideoEffectDefinition("GrayscaleTransform.GrayscaleEffect");
                await mediaCapture.AddVideoEffectAsync(def, MediaStreamType.Photo);

                ShowStatusMessage("Add effect to video preview successful");
                AddRemoveEffect.IsEnabled = true;
            }
            catch (Exception ex)
            {
                ShowExceptionMessage(ex);
            }
        }
        private async Task CreateMediaCapture()
        {
            mediaCapture = new MediaCapture();
            mediaCapture.Failed += mediaCapture_Failed;

            var settings = new MediaCaptureInitializationSettings()
            {
                StreamingCaptureMode = StreamingCaptureMode.Video
            };

            // Pick the back camera if one exists
            DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
            foreach (var device in devices)
            {
                // Check if the device on the requested panel supports Video Profile
                if (device.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back)
                {
                    settings.VideoDeviceId = device.Id;
                    break;
                }
            }

            try
            {
                await mediaCapture.InitializeAsync(settings);
            }
            catch (Exception)
            {
                this.progressText.Text = "No camera is available.";
                return;
            }

            captureElement.Source = mediaCapture;
            await mediaCapture.StartPreviewAsync();

            // Limit the photo capture to be a reasonable size
            var photoStreamProperties = mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo);
            IMediaEncodingProperties mediaEncodingProperties = null;
            foreach (var photoStreamProperty in photoStreamProperties)
            {
                var videoEncodingProperties = (photoStreamProperty as VideoEncodingProperties);
                if (videoEncodingProperties != null)
                {
                    if (videoEncodingProperties.Width * videoEncodingProperties.Height <= 2048 * 1024)
                    {
                        mediaEncodingProperties = photoStreamProperty;
                    }
                }
            }

            await mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, mediaEncodingProperties);

            if (settings.VideoDeviceId == "")
            {
                // If we didn't find a back camera, and the camera we defaulted to is a front camera, then mirror the content
                DeviceInformation info = devices[0];
                if (info.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front)
                {
                    await mediaCapture.AddVideoEffectAsync(new VideoEffectDefinition(typeof(MirrorEffect).FullName, new PropertySet()), MediaStreamType.VideoPreview);
                    await mediaCapture.AddVideoEffectAsync(new VideoEffectDefinition(typeof(MirrorEffect).FullName, new PropertySet()), MediaStreamType.Photo);
                }
            }
        }
        private async void OnLoaded(object sender, RoutedEventArgs e)
        {
            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
            m_mediaCapture = new MediaCapture();
            m_mediaCapture.Failed += mediaCapture_Failed;

            var settings = new MediaCaptureInitializationSettings()
            {
                StreamingCaptureMode = StreamingCaptureMode.Video
            };

            try
            {
                await m_mediaCapture.InitializeAsync(settings);
                
                await m_mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, GetHighestResolution());
            }
            catch (Exception)
            {               
                return;
            }

            await m_mediaCapture.AddVideoEffectAsync( new VideoEffectDefinition(typeof(ExampleVideoEffect).FullName, new PropertySet()), MediaStreamType.VideoPreview);

            m_previewVideoElement.Source = m_mediaCapture;
            await m_mediaCapture.StartPreviewAsync();
        }
Example #7
0
        private async void InitMediaCapture()
        {
            mediaCapture = null;
            mediaCapture = new Windows.Media.Capture.MediaCapture();

            // for dispose purpose
            (App.Current as App).MediaCapture = mediaCapture;
            (App.Current as App).PreviewElement = capturePreview;

            await mediaCapture.InitializeAsync(captureInitSettings);

            // Add video stabilization effect during Live Capture
            //await _mediaCapture.AddEffectAsync(MediaStreamType.VideoRecord, Windows.Media.VideoEffects.VideoStabilization, null); //this will be deprecated soon
            Windows.Media.Effects.VideoEffectDefinition def = new Windows.Media.Effects.VideoEffectDefinition(Windows.Media.VideoEffects.VideoStabilization);
            await mediaCapture.AddVideoEffectAsync(def, MediaStreamType.VideoRecord);

           CreateProfile();

            // start preview

            capturePreview.Source = mediaCapture;
            
            DisplayInformation.AutoRotationPreferences = DisplayOrientations.None;

        //// set the video Rotation
        //    _mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
        //    _mediaCapture.SetRecordRotation(VideoRotation.Clockwise90Degrees);
        }