Пример #1
0
        public Home()
        {
            BindingContext = new ComputerVisionViewModel();
            InitializeComponent();


            /*  Images = new List<MenuItem>();
             * //  var slide1 = new MenuItem() { Title = "HEllllllaaaaaa", ImageUrl= ""};
             * var slide1 = new MenuItem() { Title = "Explore New Books", ImageUrl = "https://c1.wallpaperflare.com/preview/589/21/277/book-education-pages-read.jpg" };
             * var slide2 = new MenuItem() { Title = "Make Your Personal Library", ImageUrl = "https://images.pexels.com/photos/1005324/literature-book-open-pages-1005324.jpeg" };
             * var slide3 = new MenuItem() { Title = "Find Your Favourite Books", ImageUrl = "https://images.pexels.com/photos/810050/pexels-photo-810050.jpeg" };
             * var slide4 = new MenuItem() { Title = "Find Your Favourite Authors", ImageUrl = "https://images.pexels.com/photos/415078/pexels-photo-415078.jpeg" };
             * Images.Add(slide1);
             * Images.Add(slide2);
             * Images.Add(slide3);
             * Images.Add(slide4);
             *
             *
             *
             * MainCarousalView.ItemsSource = Images;
             * Device.StartTimer(TimeSpan.FromSeconds(7), (Func<bool>)(() =>
             * {
             *     MainCarousalView.Position = (MainCarousalView.Position + 1) % Images.Count;
             *     return true;
             * }));*/

            //  BackgroundImage = "help.jpg"; Aspect = "AspectFit"; HeightRequest = 'V' ; Margin = "50 50 50 50";



            var images = new List <string>()
            {
                "https://www.creativindie.com/wp-content/uploads/2012/07/stock-image-site-pinterest-graphic.jpg",
                // "https://i.huffpost.com/gen/1039678/original.jpg",
                "https://i.pinimg.com/originals/b9/0d/56/b90d56623e94c6f8293ac7ae1f401b4d.png",
                "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ7eX9GxX1Nztj_qqLJ7UdE0GB-WtAwk9IWIv8Yq2va7qEcBnju&s",
                "https://i.pinimg.com/originals/f7/6a/61/f76a61440698a93d40f1947be5b8ab52.png",
                "https://nice-assets.s3-accelerate.amazonaws.com/smart_templates/e639b9513adc63d37ee4f577433b787b/assets/wn5u193mcjesm2ycxacaltq8jdu68kmu.jpg",
                "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTmOl1n5jeC001ysWli5G5M4PVl48VUZJsMY6bKAypZlh2RSr4v&s",
                "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQlyxax3oKQMOBTosXUA4s9yniAVkcQ4LPOMCe_GDODjFovoY5h&s",
                "https://nataliemerheb.com/wp-content/uploads/2019/02/Focal-Point-04-790x1024.jpg",
            };



            // MainCarousalView.ItemsSource = images;
            RecommendationCarousalView.ItemsSource = images;
            CarousalView.ItemsSource = images;
            //functions.ItemsSource = fun;
        }
        public async Task <ActionResult <ComputerVisionViewModel> > ComputerVision([FromForm] ComputerVisionAnalyzeRequest request)
        {
            var errorContent = "";

            if (string.IsNullOrWhiteSpace(request.ComputerVisionSubscriptionKey))
            {
                errorContent += $"Missing or invalid Computer Vision Subscription Key (see 'Azure Settings' tab){Environment.NewLine}";
            }

            if (string.IsNullOrWhiteSpace(request.ComputerVisionEndpoint))
            {
                errorContent += $"Missing or invalid Computer Vision Endpoint (see 'Azure Settings' tab){Environment.NewLine}";
            }

            if (string.IsNullOrWhiteSpace(request.ImageUrl) && (request.File == null || !_allowedFileContentType.Contains(request.File.ContentType)))
            {
                errorContent += $"Missing or invalid ImageUrl / no file provided";
            }

            if (!string.IsNullOrWhiteSpace(errorContent))
            {
                return(View(ComputerVisionViewModel.Analyzed(request,
                                                             new ComputerVisionAnalyzeResponse
                {
                    OtherErrorMessage = "Request not processed due to the following error(s):",
                    OtherErrorContent = errorContent
                })));
            }

            Track("Vision_ComputerVision");

            var imageAnalyzer = new ImageComputerVisionAnalyzer(request.ComputerVisionSubscriptionKey, request.ComputerVisionEndpoint, _httpClientFactory);
            var analyzeResult = await imageAnalyzer.AnalyzeAsync(request.ImageUrl, request.File, request.ImageAnalysisLanguage, request.ImageOcrLanguage, request.ImageReadLanguage);

            return(View(ComputerVisionViewModel.Analyzed(request, analyzeResult)));
        }
Пример #3
0
        public ComputerVisionPage()
        {
            Title = "Analyse";

            BindingContext = new ComputerVisionViewModel();

            var takePhotoButton = new Button
            {
                Text            = "Take Photo",
                TextColor       = Color.White,
                BackgroundColor = Color.Navy,
                FontSize        = 24
            };

            takePhotoButton.SetBinding(Button.CommandProperty, "TakePhotoCommand");

            var pickPhotoButton = new Button
            {
                Text            = "Pick Photo",
                TextColor       = Color.White,
                BackgroundColor = Color.Olive,
                FontSize        = 24
            };

            pickPhotoButton.SetBinding(Button.CommandProperty, "PickPhotoCommand");

            var imageUrlEntry = new Entry();

            imageUrlEntry.SetBinding(Entry.TextProperty, "ImageUrl");

            var image = new Image
            {
                HeightRequest = 200
            };
            //image.SetBinding(Image.SourceProperty, "ImageUrl");

            //var analyseImageUrlButton = new Button
            //{
            //    Text = "Analyse Image Url",
            //    TextColor = Color.White,
            //    BackgroundColor = Color.Purple,
            //    FontSize = 24
            //};
            // analyseImageUrlButton.SetBinding(Button.CommandProperty, "AnalyseImageUrlCommand");

            var analyseImageStreamButton = new Button
            {
                Text            = "Analyse Image Stream",
                TextColor       = Color.White,
                BackgroundColor = Color.Green,
                FontSize        = 24
            };

            analyseImageStreamButton.SetBinding(Button.CommandProperty, "AnalyseImageStreamCommand");

            var extractTextFromImageUrlButton = new Button
            {
                Text            = "Extract Text from Image Url",
                TextColor       = Color.White,
                BackgroundColor = Color.Silver,
                FontSize        = 24
            };

            extractTextFromImageUrlButton.SetBinding(Button.CommandProperty, "ExtractTextFromImageUrlCommand");


            var isBusyActivityIndicator = new ActivityIndicator();

            isBusyActivityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsBusy");
            isBusyActivityIndicator.SetBinding(ActivityIndicator.IsEnabledProperty, "IsBusy");
            isBusyActivityIndicator.SetBinding(ActivityIndicator.IsVisibleProperty, "IsBusy");

            var errorMessageLabel = new Label
            {
                TextColor = Color.Red,
                FontSize  = 20
            };

            errorMessageLabel.SetBinding(Label.TextProperty, "ErrorMessage");

            var captionsLabel = new Label
            {
                TextColor = Color.Maroon,
                FontSize  = 20
            };

            captionsLabel.SetBinding(Label.TextProperty, new Binding(
                                         "ImageResult.Description.Captions[0].Text",
                                         BindingMode.Default,
                                         null,
                                         null,
                                         "CAPTIONS: {0:F0}"));

            var isAdultContentLabel = new Label
            {
                TextColor = Color.Teal,
                FontSize  = 20
            };

            isAdultContentLabel.SetBinding(Label.TextProperty, new Binding(
                                               "ImageResult.Adult.IsAdultContent",
                                               BindingMode.Default,
                                               null,
                                               null,
                                               "IsAdultContent: {0:F0}"));

            var isRacyContentLabel = new Label
            {
                TextColor = Color.Teal,
                FontSize  = 20
            };

            isRacyContentLabel.SetBinding(Label.TextProperty, new Binding(
                                              "ImageResult.Adult.IsRacyContent",
                                              BindingMode.Default,
                                              null,
                                              null,
                                              "IsRacyContent: {0:F0}"));

            var tagsLabel = new Label
            {
                TextColor = Color.Green,
                FontSize  = 20
            };

            tagsLabel.SetBinding(Label.TextProperty, new Binding(
                                     "ImageResult.Description.Tags",
                                     BindingMode.Default,
                                     new ListOfStringToOneStringConverter(),
                                     null,
                                     "TAGS: {0:F0}"));

            var faceDataTemplate = new DataTemplate(() =>
            {
                var ageLabel = new Label
                {
                    TextColor = Color.Black,
                    FontSize  = 20
                };
                ageLabel.SetBinding(Label.TextProperty, new Binding(
                                        "Age",
                                        BindingMode.Default,
                                        null,
                                        null,
                                        "Age: {0:F0}"));

                var genderLabel = new Label
                {
                    TextColor = Color.Gray,
                    FontSize  = 20
                };
                genderLabel.SetBinding(Label.TextProperty, new Binding(
                                           "Gender",
                                           BindingMode.Default,
                                           null,
                                           null,
                                           "Gender: {0:F0}"));

                var faceStackLayout = new StackLayout
                {
                    Padding  = 5,
                    Children =
                    {
                        ageLabel,
                        genderLabel
                    }
                };

                return(new ViewCell
                {
                    View = faceStackLayout
                });
            });

            var facesListView = new ListView()
            {
                HasUnevenRows = true,
                ItemTemplate  = faceDataTemplate
            };

            facesListView.SetBinding(ListView.ItemsSourceProperty, "ImageResult.Faces");

            var stackLayout = new StackLayout
            {
                Padding  = new Thickness(10, 0),
                Children =
                {
                    new StackLayout
                    {
                        Orientation = StackOrientation.Horizontal,
                        Children    =
                        {
                            takePhotoButton,
                            pickPhotoButton
                        }
                    },
                    imageUrlEntry,
                    image,
                    //analyseImageUrlButton,
                    analyseImageStreamButton,
                    isBusyActivityIndicator,
                    errorMessageLabel,
                    captionsLabel,
                    isAdultContentLabel,
                    isRacyContentLabel,
                    tagsLabel,
                    facesListView
                }
            };

            Content = new ScrollView
            {
                Content = stackLayout
            };
        }
Пример #4
0
        public OcrPage()
        {
            BindingContext = new ComputerVisionViewModel();

            var takePhotoButton = new Button
            {
                TextColor   = Color.FromHex("#990033"),
                ImageSource = "camera.png",
                Text        = "  Capture",
                Margin      = 9,

                CornerRadius    = 5,
                BackgroundColor = Color.FromHex("#f2f2f2"),
            };

            takePhotoButton.SetBinding(Button.CommandProperty, "TakePhotoCommand");

            var pickPhotoButton = new Button
            {
                TextColor       = Color.FromHex("#990033"),
                ImageSource     = "img.png",
                Text            = "  Upload",
                Margin          = 9,
                CornerRadius    = 5,
                BackgroundColor = Color.FromHex("#f2f2f2"),
            };

            pickPhotoButton.SetBinding(Button.CommandProperty, "PickPhotoCommand");

            var imageUrlEntry = new Entry
            {
                FontSize  = 17,
                TextColor = Color.Blue,
            };

            imageUrlEntry.SetBinding(Entry.TextProperty, "ImageUrl");

            var image = new Image
            {
                HeightRequest = 301
            };

            image.SetBinding(Image.SourceProperty, "ImageUrl");



            var extractTextFromImageStreamButton = new Button
            {
                TextColor   = Color.FromHex("#990033"),
                ImageSource = "ic_action_search.png",
                Text        = "  Search",
                // WidthRequest = 150,
                //HeightRequest = 70,
                CornerRadius    = 5,
                Margin          = 20,
                BackgroundColor = Color.FromHex("#f2f2f2"),
            };

            extractTextFromImageStreamButton.SetBinding(Button.CommandProperty, "ExtractTextFromImageStreamCommand");

            var isBusyActivityIndicator = new ActivityIndicator();

            isBusyActivityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsBusy");
            isBusyActivityIndicator.SetBinding(ActivityIndicator.IsEnabledProperty, "IsBusy");
            isBusyActivityIndicator.SetBinding(ActivityIndicator.IsVisibleProperty, "IsBusy");

            var errorMessageLabel = new Label
            {
                TextColor = Color.Red,
                FontSize  = 15
            };

            errorMessageLabel.SetBinding(Label.TextProperty, "ErrorMessage");

            var languageLabel = new Label
            {
                TextColor = Color.Maroon,
                FontSize  = 17
            };

            languageLabel.SetBinding(Label.TextProperty, new Binding(
                                         "OcrResult.Language",
                                         BindingMode.Default,
                                         null,
                                         null,
                                         "Language: {0:F0}"));

            /* var textAngleLabel = new Label
             * {
             *   TextColor = Color.Teal,
             *   FontSize = 20
             * };
             * textAngleLabel.SetBinding(Label.TextProperty, new Binding(
             *   "OcrResult.TextAngle",
             *   BindingMode.Default,
             *   null,
             *   null,
             *   "TextAngle: {0:F0}"));
             *
             * var orientationLabel = new Label
             * {
             *   TextColor = Color.Teal,
             *   FontSize = 20
             * };
             * orientationLabel.SetBinding(Label.TextProperty, new Binding(
             *   "OcrResult.Orientation",
             *   BindingMode.Default,
             *   null,
             *   null,
             *   "Orientation: {0:F0}"));
             *
             * //var tagsLabel = new Label
             * //{
             * //    TextColor = Color.Green,
             * //    FontSize = 20
             * //};
             * //tagsLabel.SetBinding(Label.TextProperty, new Binding(
             * //    "ImageResult.Description.Tags",
             * //    BindingMode.Default,
             * //    new ListOfStringToOneStringConverter(),
             * //    null,
             * //    "TAGS: {0:F0}"));*/

            var regionDataTemplate = new DataTemplate(() =>
            {
                /* var boundingBoxLabel = new Label
                 * {
                 *   TextColor = Color.Black,
                 *   FontSize = 20
                 * };
                 * boundingBoxLabel.SetBinding(Label.TextProperty, new Binding(
                 *   "BoundingBox",
                 *   BindingMode.Default,
                 *   null,
                 *   null,
                 *   "BoundingBox: {0:F0}"));*/

                var linesLabel = new Label
                {
                    TextColor = Color.Maroon,
                    FontSize  = 17
                };
                linesLabel.SetBinding(Label.TextProperty, new Binding(
                                          "Lines",
                                          BindingMode.Default,
                                          new ListOfLinesToOneStringConverter(),
                                          null,
                                          "Extracted Text: {0:F0}"));

                var faceStackLayout = new StackLayout
                {
                    Padding  = 5,
                    Children =
                    {
                        //boundingBoxLabel,
                        linesLabel
                    }
                };

                return(new ViewCell
                {
                    View = faceStackLayout
                });
            });

            var regionsListView = new ListView
            {
                HasUnevenRows = true,
                ItemTemplate  = regionDataTemplate
            };

            regionsListView.SetBinding(ListView.ItemsSourceProperty, "OcrResult.Regions");

            var stackLayout = new StackLayout
            {
                Padding  = new Thickness(10, 0),
                Children =
                {
                    new StackLayout
                    {
                        Orientation = StackOrientation.Horizontal,
                        Margin      = 21,
                        Children    =
                        {
                            takePhotoButton,
                            pickPhotoButton
                        }
                    },

                    image,
                    imageUrlEntry,
                    extractTextFromImageStreamButton,
                    isBusyActivityIndicator,
                    errorMessageLabel,
                    languageLabel,
                    // textAngleLabel,
                    //orientationLabel,
                    regionsListView
                }
            };

            Content = new ScrollView
            {
                Content = stackLayout
            };
        }
 public IActionResult ComputerVision()
 {
     return(View(ComputerVisionViewModel.NotAnalyzed()));
 }
Пример #6
0
        public EmotionPage()
        {
            Title = "Emotion";

            BindingContext = new ComputerVisionViewModel
            {
                ImageUrl = ""
                           //"https://pbs.twimg.com/media/CnVGRLqWAAAnf1q.jpg:large"
                           //"https://pbs.twimg.com/media/CnQSbt0XgAAjREq.jpg"
                           //"https://scontent-lhr3-1.xx.fbcdn.net/t31.0-8/13416828_1110682725621456_2065685633287031902_o.jpg"
                           //"https://pbs.twimg.com/media/CmzB22aXgAAySZ7.jpg"
            };

            var takePhotoButton = new Button
            {
                Text            = "Take Photo",
                TextColor       = Color.White,
                BackgroundColor = Color.Navy,
                FontSize        = 24
            };

            takePhotoButton.SetBinding(Button.CommandProperty, "TakePhotoCommand");

            var pickPhotoButton = new Button
            {
                Text            = "Pick Photo",
                TextColor       = Color.White,
                BackgroundColor = Color.Olive,
                FontSize        = 24
            };

            pickPhotoButton.SetBinding(Button.CommandProperty, "PickPhotoCommand");

            var imageUrlEntry = new Entry();

            imageUrlEntry.SetBinding(Entry.TextProperty, "ImageUrl");

            var image = new Image
            {
                HeightRequest = 200
            };

            image.SetBinding(Image.SourceProperty, "ImageUrl");

            //var extractTextFromImageUrlButton = new Button
            //{
            //    Text = "Recognize Emotion (Url)",
            //    TextColor = Color.White,
            //    BackgroundColor = Color.FromHex("#03A9F4"),
            //    FontSize = 22
            //};
            //extractTextFromImageUrlButton.SetBinding(Button.CommandProperty, "RecognizeEmotionFromImageUrlCommand");

            var extractTextFromImageStreamButton = new Button
            {
                Text            = "Recognize Emotion (Stream)",
                TextColor       = Color.White,
                BackgroundColor = Color.Fuchsia,
                FontSize        = 21
            };

            extractTextFromImageStreamButton.SetBinding(Button.CommandProperty, "RecognizeEmotionFromImageStreamCommand");

            var isBusyActivityIndicator = new ActivityIndicator();

            isBusyActivityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsBusy");
            isBusyActivityIndicator.SetBinding(ActivityIndicator.IsEnabledProperty, "IsBusy");
            isBusyActivityIndicator.SetBinding(ActivityIndicator.IsVisibleProperty, "IsBusy");

            var errorMessageLabel = new Label
            {
                TextColor = Color.Red,
                FontSize  = 20
            };

            errorMessageLabel.SetBinding(Label.TextProperty, "ErrorMessage");

            var emotionsDataTemplate = new DataTemplate(() =>
            {
                var angerLabel = new Label
                {
                    TextColor = Color.Black,
                    FontSize  = 20
                };
                angerLabel.SetBinding(Label.TextProperty, new Binding(
                                          "Scores.Anger",
                                          BindingMode.Default,
                                          null,
                                          null,
                                          "Anger: {0:F0}"));

                var contemptLabel = new Label
                {
                    TextColor = Color.Black,
                    FontSize  = 20
                };
                contemptLabel.SetBinding(Label.TextProperty, new Binding(
                                             "Scores.Contempt",
                                             BindingMode.Default,
                                             null,
                                             null,
                                             "Contempt: {0:F0}"));

                var disgustLabel = new Label
                {
                    TextColor = Color.Black,
                    FontSize  = 20
                };
                disgustLabel.SetBinding(Label.TextProperty, new Binding(
                                            "Scores.Disgust",
                                            BindingMode.Default,
                                            null,
                                            null,
                                            "Disgust: {0:F0}"));

                var fearLabel = new Label
                {
                    TextColor = Color.Black,
                    FontSize  = 20
                };
                fearLabel.SetBinding(Label.TextProperty, new Binding(
                                         "Scores.Fear",
                                         BindingMode.Default,
                                         null,
                                         null,
                                         "Fear: {0:F0}"));

                var happinessLabel = new Label
                {
                    TextColor = Color.Black,
                    FontSize  = 20
                };
                happinessLabel.SetBinding(Label.TextProperty, new Binding(
                                              "Scores.Happiness",
                                              BindingMode.Default,
                                              null,
                                              null,
                                              "Happiness: {0:F0}"));

                var neutralLabel = new Label
                {
                    TextColor = Color.Black,
                    FontSize  = 20
                };
                neutralLabel.SetBinding(Label.TextProperty, new Binding(
                                            "Scores.Neutral",
                                            BindingMode.Default,
                                            null,
                                            null,
                                            "Neutral: {0:F0}"));

                var sadnessLabel = new Label
                {
                    TextColor = Color.Black,
                    FontSize  = 20
                };
                sadnessLabel.SetBinding(Label.TextProperty, new Binding(
                                            "Scores.Sadness",
                                            BindingMode.Default,
                                            null,
                                            null,
                                            "Sadness: {0:F0}"));

                var surpriseLabel = new Label
                {
                    TextColor = Color.Black,
                    FontSize  = 20
                };
                surpriseLabel.SetBinding(Label.TextProperty, new Binding(
                                             "Scores.Surprise",
                                             BindingMode.Default,
                                             null,
                                             null,
                                             "Surprise: {0:F0}"));

                var faceStackLayout = new StackLayout
                {
                    Padding  = 5,
                    Children =
                    {
                        angerLabel,
                        contemptLabel,
                        disgustLabel,
                        fearLabel,
                        happinessLabel,
                        neutralLabel,
                        sadnessLabel,
                        surpriseLabel
                    }
                };

                return(new ViewCell
                {
                    View = faceStackLayout
                });
            });

            var regionsListView = new ListView
            {
                HasUnevenRows = true,
                ItemTemplate  = emotionsDataTemplate
            };

            regionsListView.SetBinding(ListView.ItemsSourceProperty, "ImageResultEmotions");

            var stackLayout = new StackLayout
            {
                Padding  = new Thickness(10, 0),
                Children =
                {
                    new StackLayout
                    {
                        Orientation = StackOrientation.Horizontal,
                        Children    =
                        {
                            takePhotoButton,
                            pickPhotoButton
                        }
                    },
                    imageUrlEntry,
                    image,
                    //extractTextFromImageUrlButton,
                    extractTextFromImageStreamButton,
                    isBusyActivityIndicator,
                    errorMessageLabel,
                    regionsListView
                }
            };

            Content = new ScrollView
            {
                Content = stackLayout
            };
        }
Пример #7
0
        public OcrPage()
        {
            Title = "OCR";

            BindingContext = new ComputerVisionViewModel
            {
                ImageUrl = "https://pbs.twimg.com/media/CnQSbt0XgAAjREq.jpg"
                           //"https://scontent-lhr3-1.xx.fbcdn.net/t31.0-8/13416828_1110682725621456_2065685633287031902_o.jpg"
                           //"https://pbs.twimg.com/media/CmzB22aXgAAySZ7.jpg"
            };

            var takePhotoButton = new Button
            {
                Text            = "Take Photo",
                TextColor       = Color.White,
                BackgroundColor = Color.Navy,
                FontSize        = 24
            };

            takePhotoButton.SetBinding(Button.CommandProperty, "TakePhotoCommand");

            var pickPhotoButton = new Button
            {
                Text            = "Pick Photo",
                TextColor       = Color.White,
                BackgroundColor = Color.Olive,
                FontSize        = 24
            };

            pickPhotoButton.SetBinding(Button.CommandProperty, "PickPhotoCommand");

            var imageUrlEntry = new Entry();

            imageUrlEntry.SetBinding(Entry.TextProperty, "ImageUrl");

            var image = new Image
            {
                HeightRequest = 200
            };

            image.SetBinding(Image.SourceProperty, "ImageUrl");

            //var extractTextFromImageUrlButton = new Button
            //{
            //    Text = "Extract Text (Url)",
            //    TextColor = Color.White,
            //    BackgroundColor = Color.FromHex("#03A9F4"),
            //    FontSize = 22
            //};
            //extractTextFromImageUrlButton.SetBinding(Button.CommandProperty, "ExtractTextFromImageUrlCommand");

            var extractTextFromImageStreamButton = new Button
            {
                Text            = "Extract Text (Stream)",
                TextColor       = Color.White,
                BackgroundColor = Color.Teal,
                FontSize        = 22
            };

            extractTextFromImageStreamButton.SetBinding(Button.CommandProperty, "ExtractTextFromImageStreamCommand");

            var isBusyActivityIndicator = new ActivityIndicator();

            isBusyActivityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsBusy");
            isBusyActivityIndicator.SetBinding(ActivityIndicator.IsEnabledProperty, "IsBusy");
            isBusyActivityIndicator.SetBinding(ActivityIndicator.IsVisibleProperty, "IsBusy");

            var errorMessageLabel = new Label
            {
                TextColor = Color.Red,
                FontSize  = 20
            };

            errorMessageLabel.SetBinding(Label.TextProperty, "ErrorMessage");

            var languageLabel = new Label
            {
                TextColor = Color.Maroon,
                FontSize  = 20
            };

            languageLabel.SetBinding(Label.TextProperty, new Binding(
                                         "OcrResult.Language",
                                         BindingMode.Default,
                                         null,
                                         null,
                                         "Language: {0:F0}"));

            var textAngleLabel = new Label
            {
                TextColor = Color.Teal,
                FontSize  = 20
            };

            textAngleLabel.SetBinding(Label.TextProperty, new Binding(
                                          "OcrResult.TextAngle",
                                          BindingMode.Default,
                                          null,
                                          null,
                                          "TextAngle: {0:F0}"));

            var orientationLabel = new Label
            {
                TextColor = Color.Teal,
                FontSize  = 20
            };

            orientationLabel.SetBinding(Label.TextProperty, new Binding(
                                            "OcrResult.Orientation",
                                            BindingMode.Default,
                                            null,
                                            null,
                                            "Orientation: {0:F0}"));

            //var tagsLabel = new Label
            //{
            //    TextColor = Color.Green,
            //    FontSize = 20
            //};
            //tagsLabel.SetBinding(Label.TextProperty, new Binding(
            //    "ImageResult.Description.Tags",
            //    BindingMode.Default,
            //    new ListOfStringToOneStringConverter(),
            //    null,
            //    "TAGS: {0:F0}"));

            var regionDataTemplate = new DataTemplate(() =>
            {
                var boundingBoxLabel = new Label
                {
                    TextColor = Color.Black,
                    FontSize  = 20
                };
                boundingBoxLabel.SetBinding(Label.TextProperty, new Binding(
                                                "BoundingBox",
                                                BindingMode.Default,
                                                null,
                                                null,
                                                "BoundingBox: {0:F0}"));

                var linesLabel = new Label
                {
                    TextColor = Color.Gray,
                    FontSize  = 20
                };
                linesLabel.SetBinding(Label.TextProperty, new Binding(
                                          "Lines",
                                          BindingMode.Default,
                                          new ListOfLinesToOneStringConverter(),
                                          null,
                                          "Lines: {0:F0}"));

                var faceStackLayout = new StackLayout
                {
                    Padding  = 5,
                    Children =
                    {
                        boundingBoxLabel,
                        linesLabel
                    }
                };

                return(new ViewCell
                {
                    View = faceStackLayout
                });
            });

            var regionsListView = new ListView
            {
                HasUnevenRows = true,
                ItemTemplate  = regionDataTemplate
            };

            regionsListView.SetBinding(ListView.ItemsSourceProperty, "OcrResult.Regions");

            var stackLayout = new StackLayout
            {
                Padding  = new Thickness(10, 0),
                Children =
                {
                    new StackLayout
                    {
                        Orientation = StackOrientation.Horizontal,
                        Children    =
                        {
                            takePhotoButton,
                            pickPhotoButton
                        }
                    },
                    imageUrlEntry,
                    image,
                    //extractTextFromImageUrlButton,
                    extractTextFromImageStreamButton,
                    isBusyActivityIndicator,
                    errorMessageLabel,
                    languageLabel,
                    textAngleLabel,
                    orientationLabel,
                    regionsListView
                }
            };

            Content = new ScrollView
            {
                Content = stackLayout
            };
        }
Пример #8
0
        public ComputerVisionPage()
        {
            BindingContext = new ComputerVisionViewModel();

            var image = new Image
            {
                HeightRequest = 400,
                WidthRequest  = 320,
            };

            image.SetBinding(Image.SourceProperty, "ImageUrl");

            var takePhotoButton = new Button
            {
                Text            = "Take Photo",
                TextColor       = Color.White,
                BackgroundColor = Color.Green,
                FontSize        = 24,
            };

            takePhotoButton.SetBinding(Button.CommandProperty, "TakePhotoCommand");

            //var pickPhotoButton = new Button
            //{
            //    Text = "Pick Photo",
            //    TextColor = Color.White,
            //    BackgroundColor = Color.Olive,
            //    FontSize = 24
            //};
            //pickPhotoButton.SetBinding(Button.CommandProperty, "PickPhotoCommand");


            //var imageUrlEntry = new Entry();
            //imageUrlEntry.SetBinding(Entry.TextProperty, "ImageUrl");



            //var analyseImageUrlButton = new Button
            //{
            //    Text = "Analyse Image Url",
            //    TextColor = Color.White,
            //    BackgroundColor = Color.Purple,
            //    FontSize = 24
            //};
            //analyseImageUrlButton.SetBinding(Button.CommandProperty, "AnalyseImageUrlCommand");

            //var analyseImageStreamButton = new Button
            //{
            //    Text = "Analyse Image Stream",
            //    TextColor = Color.White,
            //    BackgroundColor = Color.Green,
            //    FontSize = 24
            //};
            //analyseImageStreamButton.SetBinding(Button.CommandProperty, "AnalyseImageStreamCommand");

            //var extractTextFromImageUrlButton = new Button
            //{
            //    Text = "Extract Text from Image Url",
            //    TextColor = Color.White,
            //    BackgroundColor = Color.Silver,
            //    FontSize = 24
            //};
            //extractTextFromImageUrlButton.SetBinding(Button.CommandProperty, "ExtractTextFromImageUrlCommand");


            var isBusyActivityIndicator = new ActivityIndicator();

            isBusyActivityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsBusy");
            isBusyActivityIndicator.SetBinding(ActivityIndicator.IsEnabledProperty, "IsBusy");
            isBusyActivityIndicator.SetBinding(ActivityIndicator.IsVisibleProperty, "IsBusy");

            var errorMessageLabel = new Label
            {
                TextColor = Color.Red,
                FontSize  = 20,
            };

            errorMessageLabel.SetBinding(Label.TextProperty, "ErrorMessage");

            captionsLabel = new Label
            {
                TextColor = Color.Black,
                FontSize  = 20,
                Margin    = 20
            };

            captionsLabel.SetBinding(Label.TextProperty, new Binding(
                                         "ImageResult.Description.Captions[0].Text",
                                         BindingMode.Default,
                                         null,
                                         null
                                         ));



            var SpeakButton = new Button
            {
                Text            = "Listen",
                TextColor       = Color.White,
                BackgroundColor = Color.Green,
                FontSize        = 24,
            };

            SpeakButton.Clicked += SpeakButton_Clicked;



            //var isAdultContentLabel = new Label
            //{
            //    TextColor = Color.Teal,
            //    FontSize = 20
            //};
            //isAdultContentLabel.SetBinding(Label.TextProperty, new Binding(
            //    "ImageResult.Adult.IsAdultContent",
            //    BindingMode.Default,
            //    null,
            //    null,
            //    "IsAdultContent: {0:F0}"));

            //var isRacyContentLabel = new Label
            //{
            //    TextColor = Color.Teal,
            //    FontSize = 20
            //};
            //isRacyContentLabel.SetBinding(Label.TextProperty, new Binding(
            //    "ImageResult.Adult.IsRacyContent",
            //    BindingMode.Default,
            //    null,
            //    null,
            //    "IsRacyContent: {0:F0}"));

            //var tagsLabel = new Label
            //{
            //    TextColor = Color.Green,
            //    FontSize = 20
            //};
            //tagsLabel.SetBinding(Label.TextProperty, new Binding(
            //    "ImageResult.Description.Tags",
            //    BindingMode.Default,
            //    new ListOfStringToOneStringConverter(),
            //    null,
            //    "TAGS: {0:F0}"));

            //var faceDataTemplate = new DataTemplate(() =>
            //{
            //    var ageLabel = new Label
            //    {
            //        TextColor = Color.Black,
            //        FontSize = 20
            //    };
            //    ageLabel.SetBinding(Label.TextProperty, new Binding(
            //        "Age",
            //        BindingMode.Default,
            //        null,
            //        null,
            //        "Age: {0:F0}"));

            //    var genderLabel = new Label
            //    {
            //        TextColor = Color.Gray,
            //        FontSize = 20
            //    };
            //genderLabel.SetBinding(Label.TextProperty, new Binding(
            //    "Gender",
            //    BindingMode.Default,
            //    null,
            //    null,
            //    "Gender: {0:F0}"));

            //var faceStackLayout = new StackLayout
            //{
            //    Padding = 5,
            //    Children =
            //    {
            //        ageLabel,
            //        genderLabel
            //    }
            //};

            //    return new ViewCell
            //    {
            //        View = faceStackLayout
            //    };
            //});

            //var facesListView = new ListView()
            //{
            //    HasUnevenRows = true,
            //    ItemTemplate = faceDataTemplate
            //};
            //facesListView.SetBinding(ListView.ItemsSourceProperty, "ImageResult.Faces");

            var stackLayout = new StackLayout
            {
                Children =
                {
                    new StackLayout
                    {
                        Orientation = StackOrientation.Horizontal,

                        Children =
                        {
                            image,



                            //pickPhotoButton
                        }
                    },

                    new StackLayout
                    {
                        Orientation = StackOrientation.Horizontal,

                        Children =
                        {
                            takePhotoButton,
                            SpeakButton,
                        }
                    },



                    //imageUrlEntry,
                    //analyseImageUrlButton,
                    //analyseImageStreamButton,
                    isBusyActivityIndicator,
                    errorMessageLabel,
                    captionsLabel,


                    //isAdultContentLabel,
                    //isRacyContentLabel,
                    //tagsLabel,
                    //facesListView
                }
            };

            Content = new ScrollView
            {
                Content = stackLayout
            };
        }