コード例 #1
0
ファイル: MainPage.xaml.cs プロジェクト: cjsatuforc/Pilot37
        private async Task InitializeCameraAsync()
        {
            if (_mediaCapture == null)
            {
                DeviceInformationCollection cameraDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

                _fpvDevice1 = cameraDevices.Last();
                // TODO: Grab 2 camera devices for the RC Car, and only 1 for the Drone
                foreach (DeviceInformation device in cameraDevices)
                {
                    if (device.Name.Contains("USB2.0 PC CAMERA"))
                    {
                        _fpvDevice1 = device;
                    }
                    else
                    {
                        Debug.WriteLine("Error: No external video stream detected!");
                    }
                }

                _mediaCapture = new MediaCapture();
                await _mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings { VideoDeviceId = _fpvDevice1.Id });

                // Set the preview source for the CaptureElement. PreviewControl is defined in the xaml file
                PreviewControl.Source = _mediaCapture;
                await _mediaCapture.StartPreviewAsync();

                //await _mediaCapture.StopPreviewAsync();
            }
        }
コード例 #2
0
        public async Task InitializeAsync()
        {
            Message = "Initializing";

            devInfoCollection = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            // Setup SignalR client and subscribe events.
            hubConnection = new HubConnection(Settings.HubUrl);
            hubProxy      = hubConnection.CreateHubProxy(Settings.HubName);
            hubProxy.On("BroadcastStartQuestion", async() =>
            {
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                    CoreDispatcherPriority.Normal, async() => { await StartQuestionAsync(); });
            });
            hubProxy.On("BroadcastStopQuestion", async() =>
            {
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                    CoreDispatcherPriority.Normal, async() => { await StopQuestionAsync(); });
            });
            hubProxy.On("BroadcastClear", async() =>
            {
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                    CoreDispatcherPriority.Normal, async() => { await ClearInputAsync(); });
            });
            await hubConnection.Start();

            // Initialize Speech recognizer and subscribe event.
            speechRecognizer = new SpeechRecognizer(new Windows.Globalization.Language(Settings.SpeechLanguage));
            speechRecognizer.Timeouts.BabbleTimeout         = TimeSpan.FromSeconds(25);
            speechRecognizer.Timeouts.InitialSilenceTimeout = TimeSpan.FromSeconds(50);
            speechRecognizer.Timeouts.EndSilenceTimeout     = TimeSpan.FromMilliseconds(50);

            speechRecognizer.ContinuousRecognitionSession.ResultGenerated += ContinuousRecognitionSession_ResultGenerated;
            speechRecognizer.HypothesisGenerated += SpeechRecognizer_HypothesisGenerated;
            speechRecognizer.ContinuousRecognitionSession.Completed += ContinuousRecognitionSession_Completed;
            await speechRecognizer.CompileConstraintsAsync();

            // Initialize video and start preview.
            await mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings()
            {
                VideoDeviceId = devInfoCollection.Last().Id
            });

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

            faceDetector = await FaceDetector.CreateAsync();

            Identify();
            GetEmotion();
        }
コード例 #3
0
        private async Task <DeviceInformation> ChooseCameraDevice()
        {
            switchIcon.Visibility = Visibility.Visible;
            cameraIcon.Visibility = Visibility.Visible;
            StartIcon.Visibility  = Visibility.Collapsed;
            Debug.WriteLine("Choose a Camera Device");
            //Get all Devices
            _CameraDeviceGroup = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            for (int i = 0; i < _CameraDeviceGroup.Count; i++)
            {
                Debug.WriteLine(_CameraDeviceGroup[i].Name.ToString());
            }
            // try to get the back facing device for a phone
            var backFacingDevice = _CameraDeviceGroup
                                   .First(c => c.EnclosureLocation?.Panel == Windows.Devices.Enumeration.Panel.Front);

            // but if that doesn't exist, take the first camera device available
            var preferredDevice = backFacingDevice ?? _CameraDeviceGroup.Last();

            _CurrentCamera = preferredDevice;

            return(_CurrentCamera);
        }