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");
            }
        }
예제 #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();
            }
        }
 private void ReleaseModel()
 {
     aiClient?.Dispose();
     aiClient = null;
     System.Diagnostics.Debug.WriteLine("AI Client Released");
 }
 private void LoadModel()
 {
     aiClient = iOSChestXRayAIClient.NewInstance();
     System.Diagnostics.Debug.WriteLine("AI Client Loaded");
 }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            AnalyticsService.TrackEvent(AnalyticsService.Event.ResultsPageViewed);

            // Load XML layout
            SetContentView(Resource.Layout.activity_results);

            // Setup toolbar
            SupportWidget.Toolbar toolbar = FindViewById <SupportWidget.Toolbar>(Resource.Id.toolbar);
            toolbar.Title = ""; // We don't want to show the title in the toolbar, but we need it as the Activity label for accessibility
            SetSupportActionBar(toolbar);
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            SupportActionBar.SetHomeButtonEnabled(true);

            // Load strings and colors
            conditionNames   = Resources.GetStringArray(Resource.Array.ai_chest_conditions);
            likelihoodLabels = Resources.GetStringArray(Resource.Array.ai_likelihood_labels);
            conditionColors  = new SKColor[]
            {
                LoadColor(Resource.Color.purple),
                LoadColor(Resource.Color.pink),
                LoadColor(Resource.Color.blue),
                LoadColor(Resource.Color.turquoise)
            };

            // Obtain UI references
            xRayDisplayView         = FindViewById <XRayDisplayView>(Resource.Id.img_xray);
            xRayDisplayViewOriginal = FindViewById <XRayDisplayView>(Resource.Id.img_xray_original);
            conditionListPrimary    = FindViewById <RecyclerView>(Resource.Id.condition_list_primary);
            conditionListSecondary  = FindViewById <RecyclerView>(Resource.Id.condition_list_secondary);
            seeMoreHideButton       = FindViewById <Button>(Resource.Id.button_see_more_hide);

            // Set up for constraint transitions to/from see more
            seeMoreModeEnabled = false;
            root = FindViewById <ConstraintLayout>(Resource.Id.root);
            resultsConstraints = new ConstraintSet();
            resultsConstraints.Clone(this, Resource.Layout.activity_results);
            seeMoreConstraints = new ConstraintSet();
            seeMoreConstraints.Clone(this, Resource.Layout.activity_see_more);

            // See more and hide click listener
            seeMoreHideButton.Click += delegate
            {
                PageTransition();
            };

            // Load analysis results
            ExtractResultsFromIntent();

            // Load and display the original X-Ray
            croppedImageUri  = (AndroidUri)this.Intent.GetParcelableExtra(ExtraCroppedImageUri);
            originalImageUri = (AndroidUri)this.Intent.GetParcelableExtra(ExtraOriginalImageUri);

            originalXRay = ImageHelper.GetBitmapFromUri(
                this.ContentResolver,
                croppedImageUri,
                LoadImageWidth,
                LoadImageHeight
                );
            xRayDisplayView.SetXRayImageResetZoom(originalXRay);
            xRayDisplayViewOriginal.SetXRayImageResetZoom(originalXRay);

            // Load and display filename
            string filename = ImageHelper.ExtractFilename(originalImageUri, this.ContentResolver);

            xRayDisplayView.Filename         = filename;
            xRayDisplayViewOriginal.Filename = filename;

            // Load and display the image date
            string date = ImageHelper.ExtractDate(originalImageUri, this.ContentResolver, this);

            xRayDisplayView.Date         = date;
            xRayDisplayViewOriginal.Date = date;

            // Retrieve the shared AI Client that was loaded by the MainApplication class
            aiClient = ((MainApplication)this.Application).AIClient;

            // Fill in data and attach listeners
            SetupConditionResultViews();
        }
예제 #6
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            AnalyticsService.TrackEvent(AnalyticsService.Event.ResultsPageViewed);

            //Programmatically add a back button and an arrow
            UIImage  backArrowImage = UIImage.FromBundle("back-arrow");
            UIButton backButton     = new UIButton(UIButtonType.Custom);

            backButton.SetImage(backArrowImage, UIControlState.Normal);
            backButton.SetTitle("Back", UIControlState.Normal);
            backButton.ImageEdgeInsets = new UIEdgeInsets(0.0f, -12.5f, 0.0f, 0.0f);
            backButton.AddTarget((sender, e) =>
            {
                AnalyticsService.TrackEvent(AnalyticsService.Event.ReturnBackToCroppingPage);
                this.NavigationController?.PopViewController(true);
            }, UIControlEvent.TouchUpInside);

            this.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(backButton);

            UIButton newSession = new UIButton(UIButtonType.Custom);

            newSession.SetTitle("New Session", UIControlState.Normal);
            newSession.AddTarget((sender, e) =>
            {
                AnalyticsService.TrackEvent(AnalyticsService.Event.ReturnBackToImageInputPage);
                this.NavigationController?.PopToRootViewController(true);
            }, UIControlEvent.TouchUpInside);

            this.NavigationItem.RightBarButtonItem = new UIBarButtonItem(newSession);

            // Set nav bar attributes
            NavigationControllerUtil.SetNavigationBarAttributes(this.NavigationController.NavigationBar);
            NavigationControllerUtil.SetNavigationTitle(this.NavigationItem, NavBarTitle);

            InputImage = InputImage.Scale(new CoreGraphics.CGSize(LoadImageWidth, LoadImageHeight));

            // Initialize UIImageView
            imageView       = new UIImageView();
            imageView.Frame = new CGRect(0, 0, InputImage.Size.Width, InputImage.Size.Height);
            imageView.Image = InputImage;
            imageView.UserInteractionEnabled = true;

            // Initialize original imageview
            originalImageView       = new UIImageView();
            originalImageView.Frame = new CGRect(0, 0, InputImage.Size.Width, InputImage.Size.Height);
            originalImageView.Image = InputImage;
            originalImageView.UserInteractionEnabled = true;

            // Initialize meta-data display
            string   filename;
            DateTime?time;

            try
            {
                filename = GetFileString(ImageUrl, DefaultFileStringForCamera);
                time     = GetDate(ImageUrl);
            }
            catch (NullReferenceException ex)
            {
                filename = DefaultFileStringForCamera;
                time     = DateTime.Now;
            }

            AnalyzedImageFileNameLabel.Text = filename;
            AnalyzedImageDateLabel.Text     = time.HasValue ? time.Value.ToShortDateString() : DefaultNoDateDisplay;

            OriginalImageFileNameLabel.Text = filename;
            OriginalImageDateLabel.Text     = time.HasValue ? time.Value.ToShortDateString() : DefaultNoDateDisplay;

            // Add all original labels to List<UILabel>
            originalLabels = new List <UILabel>();
            originalLabels.Add(OriginalImageDateLabel);
            originalLabels.Add(OriginalImageDateHeaderLabel);
            originalLabels.Add(OriginalImageFileNameLabel);
            originalLabels.Add(OriginalImageFileNameHeaderLabel);

            // Toggle accessibilty off for all original labels (they are initially hidden)
            EnableVoiceOverForViews(originalLabels.ToArray(), false);

            SetDisplayBorders();

            // Retrieve the shared AI Client that was loaded by the AppDelegate
            aiClient = ((AppDelegate)UIApplication.SharedApplication.Delegate).AIClient;
            System.Diagnostics.Debug.WriteLine("AI Client retrieved from AppDelegate");
        }
 private void LoadModel()
 {
     aiClient = AndroidChestXRayAIClient.NewInstance(this.Assets);
     System.Diagnostics.Debug.WriteLine("AI Client Loaded");
 }