public override async void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            this.NavigationController.NavigationBar.AccessibilityLabel = Constants.NavigationBarAccessibilityLabel_AnalysisPage;

            // TODO Notify the user that there was an error
            // If images are null return back to Image Input
            if (this.InputImage == null || this.InputImageBitmap == null)
            {
                this.NavigationController.PopViewController(true);
                return;
            }

            cancellationTokenSource = new CancellationTokenSource();

            // Retrieve the shared AI Client that was loaded by the AppDelegate
            ChestXRayAIClient aiClient = ((AppDelegate)UIApplication.SharedApplication.Delegate).AIClient;

            System.Diagnostics.Debug.WriteLine("AI Client retrieved from AppDelegate");

            try
            {
                (ScoreOutput[] scores, CAM[] cams) = await ChestXRayAIRunner.Analyze(aiClient, InputImageBitmap, cancellationTokenSource.Token);

                System.Diagnostics.Debug.WriteLine("Analysis completed");

                LaunchResults(scores, cams);
            }
            catch (OperationCanceledException)
            {
                System.Diagnostics.Debug.WriteLine("Analysis cancelled");
            }
        }
Beispiel #2
0
        protected override async void OnResume()
        {
            base.OnResume();

            // Set a flag so we know the activity is in the foreground
            activityResumed = true;

            // Makes sure that this only runs the first time OnResume is called
            if (cancellationTokenSource == null)
            {
                cancellationTokenSource = new CancellationTokenSource();

                // Retrieve the shared AI Client that was loaded by the MainApplication class
                ChestXRayAIClient aiClient = ((MainApplication)this.Application).AIClient;
                System.Diagnostics.Debug.WriteLine("AI Client retrieved from MainApplication class");

                try
                {
                    // Load image
                    SKBitmap image = await LoadImage(cancellationTokenSource.Token);

                    System.Diagnostics.Debug.WriteLine("Image loaded");

                    // Run analysis and save results
                    (scores, cams) = await ChestXRayAIRunner.Analyze(aiClient, image, cancellationTokenSource.Token);

                    System.Diagnostics.Debug.WriteLine("Analysis completed");

                    // Release the SKBitmap
                    image.Dispose();

                    // If the activity is currently in the foreground immediately finish the analysis
                    if (activityResumed)
                    {
                        FinishAnalysis();
                    }
                    else
                    {
                        // Otherwise set a flag to finish the analysis when the activity does become the foreground activity
                        finishAnalysisOnResume = true;
                    }
                }
                catch (System.OperationCanceledException) // NOT Android.OS.OperationCanceledException
                {
                    System.Diagnostics.Debug.WriteLine("Analysis cancelled");
                }
            }
            else if (finishAnalysisOnResume)
            {
                // Analysis completed while we were in the background, so finish the analysis now that we're in the foreground
                FinishAnalysis();
            }
        }