Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public double CalculateSimilarity(RgbProjections compare)
        {
            double num  = RgbProjections.CalculateProjectionSimilarity(this.horizontalProjection, compare.horizontalProjection);
            double num1 = RgbProjections.CalculateProjectionSimilarity(this.verticalProjection, compare.verticalProjection);

            return(Math.Max(num, num1));
        }
Exemplo n.º 3
0
 public ComparableImage(FileInfo file)
 {
     if (file == null)
     {
         throw new ArgumentNullException("file");
     }
     if (!file.Exists)
     {
         throw new ArgumentNullException("file");
     }
     this.file = file;
     using (Bitmap bitmap = ImageUtility.ResizeBitmap(new Bitmap(file.FullName), 100, 100))
     {
         this.projections = new RgbProjections(ImageUtility.GetRgbProjections(bitmap));
     }
 }
Exemplo n.º 4
0
 public ComparableImage(FileInfo file)
 {
     if (file == null)
     {
         throw new ArgumentNullException("file");
     }
     if (!file.Exists)
     {
         throw new ArgumentNullException("file");
     }
     this.file = file;
     using (Bitmap bitmap = ImageUtility.ResizeBitmap(new Bitmap(file.FullName), 100, 100))
     {
         this.projections = new RgbProjections(ImageUtility.GetRgbProjections(bitmap));
     }
 }
Exemplo n.º 5
0
        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());
        }
Exemplo n.º 6
0
        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;
        }
Exemplo n.º 7
0
 public double CalculateSimilarity(RgbProjections compare)
 {
     double num = RgbProjections.CalculateProjectionSimilarity(this.horizontalProjection, compare.horizontalProjection);
     double num1 = RgbProjections.CalculateProjectionSimilarity(this.verticalProjection, compare.verticalProjection);
     return Math.Max(num, num1);
 }