Esempio n. 1
0
        // -- Event handlers -- //
        #region EventHandlers

        /// <summary>
        /// Triggered when the file picker button is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void UIButtonFilePick_Click(object sender, RoutedEventArgs e)
        {
            // Pick image file
            var imageFile = await GetFilePickedAsync();

            if (imageFile == null)
            {
                return;
            }

            UIResultPanel.Items.Clear();

            // Disable UI
            UISkillTabs.IsEnabled = false;
            NotifyUser("", NotifyType.ClearMessage);

            // Start our stopwatch to measure the time it takes to process all of this
            m_perfWatch.Restart();

            // Take a lock for using the binding
            await m_bindingLock.WaitAsync();

            // Display a staging content in our UI
            m_currentSkillControl = SkillControl.CreateControl(m_currentSkillWrapper.Binding);
            UIResultPanel.Items.Add(m_currentSkillControl);
            m_currentSkillControl.RunButtonClicked += SkillControl_RunButtonClicked;

            // Start a task that will Load the frame, display it in the UI, bind it and schedule
            // execution of the skill against that binding
            // (fire and forget)
            var bindingTask = Task.Run(async() =>
            {
                // Execute concept tag skill
                try
                {
                    // Load the VideoFrame from the image file
                    var frame = await LoadVideoFrameFromFileAsync(imageFile);
                    if (frame == null)
                    {
                        throw new Exception($"Error reading image file: {imageFile.Path}");
                    }

                    var baseTime = (float)m_perfWatch.ElapsedTicks / Stopwatch.Frequency * 1000f;

                    // Bind input image
                    await m_currentSkillWrapper.Binding["InputImage"].SetFeatureValueAsync(frame);

                    // Display image
                    await UIResultPanel.Dispatcher.RunAsync(
                        CoreDispatcherPriority.Normal,
                        async() =>
                    {
                        await m_currentSkillControl.UpdateSkillControlInputImageAsync(frame.SoftwareBitmap);
                    });

                    // Record bind time for display
                    m_currentSkillControl.BindTime = (float)m_perfWatch.ElapsedTicks / Stopwatch.Frequency * 1000f - baseTime;
                }
                catch (Exception ex)
                {
                    NotifyUser(ex.Message, NotifyType.ErrorMessage);
                }
                m_bindingLock.Release();

                // Enable UI
                await Dispatcher.RunAsync(
                    CoreDispatcherPriority.Normal,
                    () =>
                {
                    UISkillTabs.IsEnabled      = true;
                    UIButtonFilePick.IsEnabled = true;
                });
            });
        }