예제 #1
0
        /// <summary>
        /// Inserts new image
        /// </summary>
        /// <param name="user"></param>
        /// <returns>boolean</returns>
        public async Task <bool> InsertPersonInToGroup(UserModel user)
        {
            CreatePersonResult result = await _faceServiceClient.CreatePersonAsync(_groupId, user.Id.ToString());

            //Mock error heandling
            if (result == null)
            {
                return(false);
            }

            RecognitionUtils recUtils = new RecognitionUtils();

            await _faceServiceClient.AddPersonFaceAsync(_groupId, result.PersonId, recUtils.GetStream(user.ImageUri));

            await _faceServiceClient.TrainPersonGroupAsync(_groupId);

            return(true);
        }
예제 #2
0
        /// <summary>
        /// Identifies person from an image taken in the app
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public async Task <string> Identify(UserModel user)
        {
            string imageUri = user.ImageUri;

            //Mock error heandling
            if (imageUri == null)
            {
                return(null);
            }

            RecognitionUtils recUtils = new RecognitionUtils();

            var memoryStream = new MemoryStream();

            memoryStream = recUtils.GetStream(imageUri);

            var faces = await _faceServiceClient.DetectAsync(memoryStream);

            //Mock error heandling
            if (faces.Length == 0 || faces == null)
            {
                return(null);
            }

            var faceIds = faces.Select(face => face.FaceId).ToArray();

            var results = await _faceServiceClient.IdentifyAsync(_groupId, faceIds);

            //Mock error heandling
            if (results.Length == 0 || results == null || results[0].Candidates.Length == 0 || results[0].Candidates[0] == null)
            {
                return(null);
            }

            var candidateId = results[0].Candidates[0].PersonId;
            var person      = await _faceServiceClient.GetPersonAsync(_groupId, candidateId);

            return(person.Name);
        }
예제 #3
0
        public void GetStream_ShouldReturnExpected()
        {
            //Arrange
            byte[] fakeBytes             = new byte[1000];
            var    fakeWebClientFacttory = A.Fake <ICustomWebClientFactory>();
            var    fakeWebClient         = fakeWebClientFacttory.Create();

            A.CallTo(() => fakeWebClient.DownloadData("https://static.tvtropes.org/pmwiki/pub/images/young_joseph_joestar_anime.png")).Returns(fakeBytes);

            //Act
            var recognitionUtils = new RecognitionUtils()
            {
                CustomWebClient = fakeWebClient
            };
            var result = recognitionUtils.GetStream("https://static.tvtropes.org/pmwiki/pub/images/young_joseph_joestar_anime.png");

            //Assert
            var resultBytes = result.ToArray();

            resultBytes.ShouldBe(fakeBytes);

            A.CallTo(() => fakeWebClient.DownloadData("https://static.tvtropes.org/pmwiki/pub/images/young_joseph_joestar_anime.png")).MustHaveHappenedOnceExactly();
        }
예제 #4
0
        private void SearchCardByName(string searchedCardName, bool showBestCard)
        {
            if (string.IsNullOrEmpty(searchedCardName))
            {
                SearchResults.Children.RemoveRange(0, SearchResults.Children.Count);
                return;
            }

            var bestMatches = RecognitionUtils.FindBestCardReviewMatches(searchedCardName);

            if (bestMatches.Count > 1 || !showBestCard)
            {
                SearchResults.Children.RemoveRange(0, SearchResults.Children.Count);
                foreach (var match in bestMatches)
                {
                    TextBlock searchResult = new TextBlock
                    {
                        Text       = match.ReviewByTeam[Team.TDC].Name,
                        Foreground = Brushes.White,
                    };
                    searchResult.PreviewMouseDown += (e, args) =>
                    {
                        SearchCardByName(searchResult.Text, true);
                    };
                    SearchResults.Children.Add(searchResult);
                }
                return;
            }

            var newGuess = bestMatches.Last();

            StackPanel searchedCommentsPanel = FindName("ManualSearchControl") as StackPanel;

            if (searchedCommentsPanel == null)
            {
                searchedCommentsPanel = new StackPanel
                {
                    Name        = "ManualSearchControl",
                    Orientation = Orientation.Vertical,
                    Background  = backgroundBrush,
                    Width       = 210,
                };

                Canvas.SetLeft(searchedCommentsPanel, 1275);
                Canvas.SetTop(searchedCommentsPanel, 420);
                MainCanvas.Children.Add(searchedCommentsPanel);
                MainCanvas.RegisterName(searchedCommentsPanel.Name, searchedCommentsPanel);

                ScrollViewer scrollViewerComments = new ScrollViewer
                {
                    Width  = 210,
                    Height = 300,
                    VerticalScrollBarVisibility = ScrollBarVisibility.Hidden,
                    BorderThickness             = new Thickness(0)
                };

                StackPanel titleCommentsPanel = new StackPanel
                {
                    Background  = Brushes.DarkCyan,
                    Orientation = Orientation.Horizontal,
                    Height      = 30,
                };
                searchedCommentsPanel.Children.Add(titleCommentsPanel);

                TextBox cardTitle = new TextBox
                {
                    VerticalAlignment = VerticalAlignment.Center,
                    Background        = Brushes.DarkCyan,
                    BorderThickness   = new Thickness(0),
                    Foreground        = new SolidColorBrush(Colors.White),
                    Name = "cardTitle_ManualSearchControl",
                    Text = CardReviewForUiUtils.GetRatingLabel(new HashSet <CardGuess>()
                    {
                        newGuess
                    }),
                    FontWeight = FontWeights.Bold,
                    Padding    = new Thickness(5, 5, 5, 5),
                    Width      = 175,
                };
                Utils.MakePanelDraggable(searchedCommentsPanel, HolderCanvas, this, null);
                Utils.UpdateFontSizeToFit(cardTitle);
                titleCommentsPanel.Children.Add(cardTitle);
                searchedCommentsPanel.RegisterName(cardTitle.Name, cardTitle);

                Button closeBtn = new Button()
                {
                    Content             = "X",
                    Height              = 20,
                    Width               = 20,
                    Background          = Brushes.DarkCyan,
                    HorizontalAlignment = HorizontalAlignment.Right,
                    Margin              = new Thickness(10, 0, 10, 0),
                    Foreground          = new SolidColorBrush(Colors.White),
                    Padding             = new Thickness(5, 0, 5, 0),
                };
                titleCommentsPanel.Children.Add(closeBtn);
                closeBtn.Click += (e, args) =>
                {
                    searchedCommentsPanel.Visibility = Visibility.Hidden;
                };

                TextBox comments = new TextBox
                {
                    Width  = 210,
                    Height = 300,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    Padding             = new Thickness(0, 20, 0, 0),
                    TextWrapping        = TextWrapping.Wrap,
                    CaretBrush          = new SolidColorBrush(Colors.Transparent),
                    Background          = backgroundBrush,
                    Foreground          = new SolidColorBrush(Colors.White),
                    BorderThickness     = new Thickness(0),
                    Name = "textbox_ManualSearchControl",
                    Text = CardReviewForUiUtils.GetCommentsText(newGuess),
                };
                scrollViewerComments.Content = comments;

                searchedCommentsPanel.Children.Add(scrollViewerComments);
                searchedCommentsPanel.RegisterName(comments.Name, comments);
            }
            else
            {
                searchedCommentsPanel.Visibility = Visibility.Visible;
                (FindName("textbox_ManualSearchControl") as TextBox).Text   = CardReviewForUiUtils.GetCommentsText(newGuess);
                (FindName("cardTitle_ManualSearchControl") as TextBox).Text = CardReviewForUiUtils.GetRatingLabel(new HashSet <CardGuess>()
                {
                    newGuess
                });
            }
        }