Ejemplo n.º 1
0
 internal void Add(ImageSearchResult param)
 {
     if (!ImagesToProcess.Where(k => k.Key == param).Any())
     {
         ImagesToProcess.Add(new KeyValuePair <ImageSearchResult, Emgu.CV.Image <Bgr, byte> >(param, null));
     }
 }
Ejemplo n.º 2
0
    void OnSearchCallback(ImageSearchResult result)
    {
        SearchButton.interactable = true;
        prevButton.interactable   = lastPageNo > 1;
        pageNo.text = lastPageNo.ToString("00");

        if (result == null)
        {
            Debug.LogError("Result Null", this);
            return;
        }

        Debug.Log($"Result Count: " + result.results.Count, this);
        Debug.Log("First Result:\n" + JsonUtility.ToJson(result.results[0], true), this);
        foreach (var item in result.results.Take(ShowMaxResultAmount))
        {
            var request = UnityWebRequestTexture.GetTexture(item.thumbnail).SendWebRequest();
            request.completed +=
                (ao) =>
            {
                if (ao.isDone)
                {
                    var image = Instantiate(ResultImagePrefab, ResultsLayout.transform);
                    image.texture = DownloadHandlerTexture.GetContent(request.webRequest);
                    resultImages.Add(image);
                }
            };
        }
    }
Ejemplo n.º 3
0
        public async void ImageSearch(string imgCode)
        {
            ImageSearchResult searchResult = await Run(() => Screen.ImageSearch(Itr, imgCode));

            if (searchResult.Found)
            {
                LogProgress("Image found at: " + searchResult.Point.ToString());
            }
            else
            {
                LogProgress("Image not found.");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// TODO: Move to other project.
        /// </summary>
        /// <param name="match"></param>
        /// <returns></returns>
        private Point[] perspectiveTransform(ImageSearchResult match)
        {
            Rectangle rect = new Rectangle(Point.Empty, match.MatchingView.Features.Image.Size);

            PointF[] pts = new PointF[]
            {
                new PointF(rect.Left, rect.Bottom),
                new PointF(rect.Right, rect.Bottom),
                new PointF(rect.Right, rect.Top),
                new PointF(rect.Left, rect.Top)
            };

            pts = CvInvoke.PerspectiveTransform(pts, match.Homography);

            return(Array.ConvertAll <PointF, Point>(pts, Point.Round));
        }
Ejemplo n.º 5
0
        public static ImageSearchResult ImageSearchResultForImageUrl(string imageUrl)
        {
            if (!WebHelper.IsStringUrl(imageUrl))
            {
                return(null);
            }
            var          result      = new ImageSearchResult();
            var          imageBytes  = WebHelper.BytesForImageUrl(imageUrl);
            IImageFormat imageFormat = null;

            using (Image <Rgba32> image = Image.Load(imageBytes, out imageFormat))
            {
                result.Height   = image.Height.ToString();
                result.Width    = image.Width.ToString();
                result.MediaUrl = imageUrl;
            }
            return(result);
        }
Ejemplo n.º 6
0
        public async Task <ImageSearchResult> GetProducts(Stream imageStream)
        {
            var searchTerm = await predictor.PredictSearchTerm(imageStream);

            var result = new ImageSearchResult {
                PredictedSearchTerm = searchTerm
            };

            var products = await productService.GetProducts(searchTerm : searchTerm);

            var searchResults = products.Select(p => new SearchProductItem
            {
                Id       = p.Id,
                ImageUrl = p.ImageUrl,
                Name     = p.Name,
                Price    = (float)p.Price
            });

            result.SearchResults = searchResults;

            return(result);
        }
Ejemplo n.º 7
0
        public async Task ImageSearch([Summary("The desired image index.")] int index, [Summary("The search query.")][Remainder] string query)
        {
            DateTime startTime = DateTime.Now;

            using (var typingState = await Context.Channel.EnterTypingState(Config.ImageManipulateTypeTime))
            {
                ImageSearchResult result = await ImageService.SearchImage(query, Math.Min(index, 100));

                EmbedBuilder builder = new EmbedBuilder();
                EmbedService.BuildFeedbackEmbed(builder);
                builder.Description = "";
                builder.Title       = $"Image Search: [{query}]";
                builder.WithImageUrl(result.Url);
                builder.WithFooter(footer =>
                {
                    footer.Text = $"⏰ {"Generated in:"}  {Math.Round((DateTime.Now.Subtract(startTime).TotalMilliseconds)).ToString()}ms";
                });
                await ReplyAsync("", embed : builder.Build());

                result.Image.Dispose();
            }
        }
 public ImageSearchResultDataGridItemModel(DockerCommandService dockerCommandService, ImageSearchResult searchResult)
 {
     this.dockerCommandService = dockerCommandService;
     Name        = searchResult.Name;
     Description = searchResult.Description;
     Stars       = searchResult.Stars;
     IsOffical   = searchResult.IsOffical;
     IsAutomated = searchResult.IsAutomated;
 }
Ejemplo n.º 9
0
        public async Task TopGameTime([Summary("The specified game.")][Remainder] string name)
        {
            try
            {
                DateTime     startTime    = DateTime.Now;
                EmbedBuilder embedBuilder = new EmbedBuilder()
                {
                    Title = $"{name} Leaderboard"
                };
                EmbedService.BuildSuccessEmbed(embedBuilder);
                embedBuilder.Description = "";
                ImageSearchResult result = await ImageService.SearchImage($"{name} icon", 1);

                embedBuilder.ThumbnailUrl = result.Url;
                using (BotDBContext DBContext = DBFactory.Create <BotDBContext>())
                {
                    SimpleStopWatch        watch          = new SimpleStopWatch();
                    List <DiscordGameTime> playerGameTime = DBContext.GameTime.FromSql("SELECT * FROM GameTime WHERE Name = {0} ORDER BY Minutes DESC LIMIT 5", name).AsNoTracking().ToList();
                    if (playerGameTime.Count == 0)
                    {
                        await ReplyAsync("", embed : EmbedService.MakeFailFeedbackEmbed($"No Gametime found for the game [{name.Bold()}]."));

                        return;
                    }

                    for (int i = 0; i < Math.Min(5, playerGameTime.Count()); i++)
                    {
                        var         gameTime = playerGameTime.ElementAt(i);
                        DiscordUser user     = DBContext.Users.FromSql("SELECT * FROM Users WHERE Id = {0} LIMIT 1", gameTime.Id.ToString()).AsNoTracking().ToList().SingleOrDefault();
                        if (user == null)
                        {
                            continue;
                        }

                        string text = StandardExtensions.GetAgeText(DateTime.Now.AddMinutes(-gameTime.Minutes));
                        embedBuilder.AddField(x =>
                        {
                            x.Name  = "#" + (i + 1) + " " + user.Username;
                            x.Value = new TimeSpan(0, (int)gameTime.Minutes, 0).ToNiceTime();
                        });
                    }

                    var totalGameTime = DBContext.GameTime.FromSql("SELECT * FROM GameTime WHERE Name = {0}", name).AsNoTracking().Sum(x => x.Minutes);

                    TimeSpan totalMinutes = new TimeSpan(0, (int)totalGameTime, 0);

                    //string txt = StandardExtensions.GetAgeText(DateTime.Now.AddMinutes(-totalMinutes));
                    //TimeSpan time = new TimeSpan(0, totalMinutes, 0);
                    embedBuilder.WithFooter(footer =>
                    {
                        footer.Text = $"⏰ {"Generated in:"}  {watch.Stop().TotalMilliseconds}ms";
                    });
                    embedBuilder.Description = $"{"Total Gametime:".Code()} {totalMinutes.ToNiceTime().ToString()} \n";
                }
                await ReplyAsync("", embed : embedBuilder);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }