public List <ImageItem> Query(Image <Bgr, Byte> queryImage, ImageFeatureSelection features) { List <ImageItem> sortedResults = new List <ImageItem>(); List <Task> tasks = new List <Task>(); Task <List <KeyValuePair <ImageItem, float> > > phistTask = null; Task <List <KeyValuePair <ImageItem, int> > > surfTask = null; if (features.HasFlag(ImageFeatureSelection.PHistogram)) { phistTask = Task <List <KeyValuePair <ImageItem, float> > > .Factory.StartNew(() => QueryUsingPHistogram(queryImage)); tasks.Add(phistTask); } if (features.HasFlag(ImageFeatureSelection.Surf)) { surfTask = Task <List <KeyValuePair <ImageItem, int> > > .Factory.StartNew(() => QueryUsingSurf(queryImage)); tasks.Add(surfTask); } Task[] computeSimilarityTasks = tasks.ToArray(); Task.WaitAll(computeSimilarityTasks); HashSet <string> files = new HashSet <string>(); if (phistTask != null) { List <KeyValuePair <ImageItem, float> > phistResults = phistTask.Result; foreach (var kvp in phistResults) { sortedResults.Add(kvp.Key); files.Add(kvp.Key.Path); } } if (surfTask != null) { List <KeyValuePair <ImageItem, int> > surfResults = surfTask.Result; foreach (var kvp in surfResults) { if (!files.Contains(kvp.Key.Path)) { sortedResults.Add(kvp.Key); } } } return(sortedResults); }
private void Search() { ImageFeatureSelection features = new ImageFeatureSelection(); if (surfCheckBox.Checked) { features |= ImageFeatureSelection.Surf; } if (phistCheckBox.Checked) { features |= ImageFeatureSelection.PHistogram; } Stopwatch stopwatch = new Stopwatch(); toolStripStatusLabel.Text = ""; try { stopwatch.Start(); var results = _imageDatabase.Query(queryImageBox.ImageLocation, features); imageList.Images.Clear(); imageList.ColorDepth = ColorDepth.Depth24Bit; listView.Items.Clear(); listView.View = View.LargeIcon; int index = 0; foreach (var result in results) { imageList.Images.Add(ImageHelper.GetThumbnailImage(result.Path, 128)); listView.Items.Add(""); listView.Items[index].ImageIndex = index; listView.Items[index].Tag = result; ++index; } stopwatch.Stop(); toolStripStatusLabel.Text = string.Format("Took {0} seconds to finish.", (float)stopwatch.ElapsedMilliseconds / 1000.0f); } catch (IOException) { } }
public List <ImageItem> Query(FileInfo queryFile, ImageFeatureSelection features) { return(Query(queryFile.FullName, features)); }
public List <ImageItem> Query(string filePath, ImageFeatureSelection features) { return(Query(new Image <Bgr, Byte>(filePath), features)); }