public void IndexFiles(FileInfo[] imageFiles, System.ComponentModel.BackgroundWorker IndexBgWorker, object argument = null) { List <RGBProjectionRecord> listOfRecords = new List <RGBProjectionRecord>(); RgbProjections projections = null; int totalFileCount = imageFiles.Length; for (int i = 0; i < totalFileCount; i++) { var fi = imageFiles[i]; using (Bitmap bitmap = ImageUtility.ResizeBitmap(new Bitmap(fi.FullName), 100, 100)) { projections = new RgbProjections(ImageUtility.GetRgbProjections(bitmap)); } RGBProjectionRecord record = new RGBProjectionRecord { Id = i, ImageName = fi.Name, ImagePath = fi.FullName, RGBProjection = projections }; listOfRecords.Add(record); IndexBgWorker.ReportProgress(i); } BinaryAlgoRepository <List <RGBProjectionRecord> > repo = new BinaryAlgoRepository <List <RGBProjectionRecord> >(); repo.Save(listOfRecords); }
public List <DTOs.ImageRecord> QueryImage(string queryImagePath, object argument = null) { List <ImageRecord> rtnImageList = new List <ImageRecord>(); RgbProjections queryProjections; using (Bitmap bitmap = ImageUtility.ResizeBitmap(new Bitmap(queryImagePath), 100, 100)) { queryProjections = new RgbProjections(ImageUtility.GetRgbProjections(bitmap)); } BinaryAlgoRepository <List <RGBProjectionRecord> > repo = new BinaryAlgoRepository <List <RGBProjectionRecord> >(); List <RGBProjectionRecord> AllImage = repo.Load(); foreach (var imgInfo in AllImage) { var dist = imgInfo.RGBProjection.CalculateSimilarity(queryProjections); if (dist > 0.8d) { imgInfo.Distance = dist; rtnImageList.Add(imgInfo); } } rtnImageList = rtnImageList.OrderByDescending(x => x.Distance).ToList(); return(rtnImageList); }
public void IndexFilesAsync(FileInfo[] imageFiles, System.ComponentModel.BackgroundWorker IndexBgWorker, object argument = null) { ConcurrentBag <RGBProjectionRecord> listOfRecords = new ConcurrentBag <RGBProjectionRecord>(); RgbProjections projections = null; int totalFileCount = imageFiles.Length; int i = 0; long nextSequence; //In the class scope: Object lockMe = new Object(); Parallel.ForEach(imageFiles, currentImageFile => { var fi = currentImageFile; using (Bitmap bitmap = ImageUtility.ResizeBitmap(new Bitmap(fi.FullName), 100, 100)) { projections = new RgbProjections(ImageUtility.GetRgbProjections(bitmap)); } lock (lockMe) { nextSequence = i++; } RGBProjectionRecord record = new RGBProjectionRecord { Id = nextSequence, ImageName = fi.Name, ImagePath = fi.FullName, RGBProjection = projections }; listOfRecords.Add(record); IndexBgWorker.ReportProgress(i); }); BinaryAlgoRepository <List <RGBProjectionRecord> > repo = new BinaryAlgoRepository <List <RGBProjectionRecord> >(); repo.Save(listOfRecords.ToList()); }