public async Task RetrieveLabels() { if (retrievingLabels) { return; } retrievingLabels = true; try { Dictionary <string, double> r = null; if (Labeler.PreferredMethod == Labeler.Method.ByUrl) { r = await Labeler.GetLabelsAsync(URL); } else if (img != null) { r = await Labeler.GetLabelsAsync(img); } if (r != null) { r = r.OrderByDescending(kv => kv.Value) .Take(Settings.Default.NFirstLabels) .ToDictionary(kv => kv.Key, kv => kv.Value); foreach (var keyvalue in r) { labels.Add(new ImageLabel(keyvalue.Key, keyvalue.Value)); } labelsRetrieved = true; LabelsRetrieved?.Invoke(this); } } catch (Exception ex) { Reporter.Report(ex); } finally { retrievingLabels = false; } }
public MainFrm() { InitializeComponent(); urlGrid.DataSource = urls; urls.AllowNew = urls.AllowEdit = urls.AllowRemove = true; Icon appIcon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location); iconBox.Image = appIcon.ToBitmap(); mWidth.Text = Settings.Default.MinWidth.ToString(); mHeight.Text = Settings.Default.MinHeight.ToString(); Labeler.Reset(); }
public async Task RetrieveMatches() { while (retrievingLabels) { ; } if (retrievingSimilar || labels == null) { return; } retrievingSimilar = true; var list = new List <string>(); list.AddRange(labels.Select(l => l.Label)); bool skip = false; var flist = new List <string>(); foreach (string fl in FileLabels.Split(' ').Take(Settings.Default.FileNameLabels)) { foreach (string label in list) { if (label.Contains(fl)) { skip = true; break; } } if (skip) { break; } flist.Add(fl); } if (!skip) { list.AddRange(flist); } await ImageLookup.GetSimilar(list.ToArray(), async (imgUrl, size) => { if (imgUrl == null) { similarRetrieved = true; if (Labeler.CurrentLabeler.CanRecommend) { var thread = new Thread(() => { var r = Labeler.GetRecommended(img, matches.Take(Settings.Default.RecCap).Select(i => i.GetFullImage()).ToArray()).Result; SetSelectedMatch(r); RecommendationMade?.Invoke(this); }); thread.Start(); } retrievingSimilar = false; return; } //if (size.Width < Settings.Default.MinWidth && size.Height < Settings.Default.MinHeight) return; ImageWrapper iw; if (!Cache.Lookup(imgUrl, out iw)) { iw = new ImageWrapper(imgUrl); Cache.Stash(imgUrl, iw); } matches.Add(iw); SimilarFound?.Invoke(this); }); }