Exemple #1
0
        /// <summary>
        /// Triggered when UIButtonSwitchOutput is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UIButtonSwitchOutput_Click(object sender, RoutedEventArgs e)
        {
            // Swap upscaled output
            switch (m_currentOutputType)
            {
            case ScaledOutputType.SuperResolution:
                Canvas.SetZIndex(UIOutputViewer, -99);
                Canvas.SetZIndex(UICameraPreview, 0);
                m_currentOutputType          = ScaledOutputType.LinearUpsample;
                UIButtonSwitchOutput.Content = "Switch to Super Resolution";
                break;

            case ScaledOutputType.LinearUpsample:
                Canvas.SetZIndex(UIOutputViewer, 0);
                Canvas.SetZIndex(UICameraPreview, -99);
                m_currentOutputType          = ScaledOutputType.SuperResolution;
                UIButtonSwitchOutput.Content = "Switch to Linear Scaling";
                break;

            default:
                break;
            }
        }
Exemple #2
0
        /// <summary>
        /// Triggered when UICameraToggle is clicked, initializes frame grabbing from the camera stream
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void UICameraToggle_Click(object sender, RoutedEventArgs e)
        {
            UICameraToggle.IsEnabled = false;

            await m_lock.WaitAsync();

            try
            {
                UICameraPreview.Stop();
                if (UICameraPreview.CameraHelper != null)
                {
                    await UICameraPreview.CameraHelper.CleanUpAsync();
                }
                m_isCameraFrameDimensionInitialized = false;

                // Instantiate skill only if object is null or selected execution device has changed
                if ((m_paramsSkillObj.m_selectedDeviceId != UISkillExecutionDevices.SelectedIndex) || (m_paramsSkillObj.m_skill == null))
                {
                    if (m_paramsSkillObj.m_skill != null)
                    {
                        // Release previous instance
                        m_paramsSkillObj.m_skill = null;
                    }

                    // Update selected device
                    m_paramsSkillObj.m_selectedDeviceId = UISkillExecutionDevices.SelectedIndex;

                    // Initialize skill with the selected supported device
                    m_paramsSkillObj.m_skill = await m_paramsSkillObj.m_skillDescriptor.CreateSkillAsync(m_paramsSkillObj.m_availableExecutionDevices[UISkillExecutionDevices.SelectedIndex]) as SuperResolutionWinMLSkill;

                    // Instantiate a binding object that will hold the skill's input and output resource
                    m_paramsSkillObj.m_binding = await m_paramsSkillObj.m_skill.CreateSkillBindingAsync() as SuperResolutionWinMLBinding;
                }

                // Initialize the CameraPreview control, register frame arrived event callback
                UICameraPreview.Visibility = Visibility.Visible;
                await UICameraPreview.StartAsync();

                UICameraPreview.CameraHelper.FrameArrived += CameraHelper_FrameArrived;

                // Set a specific resolution if available. This version of super resolution skill works best on 640x360 input.
                var lrFrameFormat = UICameraPreview.CameraHelper.FrameFormatsAvailable.Find((format) => ((format.VideoFormat.Width == 640) && (format.VideoFormat.Height == 360)));
                if (lrFrameFormat != null)
                {
                    await UICameraPreview.CameraHelper.PreviewFrameSource.SetFormatAsync(lrFrameFormat);
                }

                // Set super resolution output on top as default
                m_currentFrameSourceToggled = FrameSourceToggledType.Camera;
                m_currentOutputType         = ScaledOutputType.SuperResolution;
                Canvas.SetZIndex(UIOutputViewer, 0);
                Canvas.SetZIndex(UICameraPreview, -99);
                UIButtonSwitchOutput.Content   = "Switch to Linear Scaling";
                UIButtonSwitchOutput.IsEnabled = true;
            }
            catch (Exception ex)
            {
                await(new MessageDialog(ex.Message)).ShowAsync();
                m_currentFrameSourceToggled = FrameSourceToggledType.None;
            }
            finally
            {
                m_lock.Release();
            }
        }