Пример #1
0
        public void IndexFiles(FileInfo[] imageFiles, BackgroundWorker IndexBgWorker, object argument = null)
        {
            BKTree<CEDDTreeNode> ceddtree = new BKTree<CEDDTreeNode>();

            double[] ceddDiscriptor = null;
            int totalFileCount = imageFiles.Length;
            CEDD cedd = new CEDD();
            for (int i = 0; i < totalFileCount; i++)
            {
                var fi = imageFiles[i];
                using (Bitmap bmp = new Bitmap(Image.FromFile(fi.FullName)))
                {
                    ceddDiscriptor = cedd.Apply(bmp);
                }

                CEDDTreeNode ceddTreeNode = new CEDDTreeNode
                {
                    Id = i,
                    ImageName = fi.Name,
                    ImagePath = fi.FullName,
                    CEDDDiscriptor = ceddDiscriptor
                };
                ceddtree.add(ceddTreeNode);
                IndexBgWorker.ReportProgress(i);
            }
            CEDDRepository<BKTree<CEDDTreeNode>> repo = new CEDDRepository<BKTree<CEDDTreeNode>>();
            repo.Save(ceddtree);
            CacheHelper.Remove("CeddIndexTree");
        }
Пример #2
0
        public void IndexFiles(FileInfo[] imageFiles, BackgroundWorker IndexBgWorker, object argument = null)
        {
            List<CEDDRecord> listOfRecords = new List<CEDDRecord>();

            double[] ceddDiscriptor = null;
            int totalFileCount = imageFiles.Length;
            CEDD cedd = new CEDD();
            for (int i = 0; i < totalFileCount; i++)
            {
                var fi = imageFiles[i];
                using (Bitmap bmp = new Bitmap(Image.FromFile(fi.FullName)))
                {
                    ceddDiscriptor = cedd.Apply(bmp);
                }

                CEDDRecord record = new CEDDRecord
                {
                    Id = i,
                    ImageName = fi.Name,
                    ImagePath = fi.FullName,
                    CEDDDiscriptor = ceddDiscriptor
                };
                listOfRecords.Add(record);
                IndexBgWorker.ReportProgress(i);
            }
            BinaryAlgoRepository<List<CEDDRecord>> repo = new BinaryAlgoRepository<List<CEDDRecord>>();
            repo.Save(listOfRecords);
        }
Пример #3
0
        public void IndexFilesAsync(FileInfo[] imageFiles, BackgroundWorker IndexBgWorker, object argument = null)
        {
            ConcurrentBag<CEDDRecord> listOfRecords = new ConcurrentBag<CEDDRecord>();

            double[] ceddDiscriptor = null;
            int totalFileCount = imageFiles.Length;
            CEDD cedd = new CEDD();

            int i = 0; long nextSequence;
            //In the class scope:
            Object lockMe = new Object();

            Parallel.ForEach(imageFiles, currentImageFile =>
            {
                var fi = currentImageFile;
                using (Bitmap bmp = new Bitmap(Image.FromFile(fi.FullName)))
                {
                    ceddDiscriptor = cedd.Apply(bmp);
                }

                lock (lockMe)
                {
                    nextSequence = i++;
                }

                CEDDRecord record = new CEDDRecord
                {
                    Id = nextSequence,
                    ImageName = fi.Name,
                    ImagePath = fi.FullName,
                    CEDDDiscriptor = ceddDiscriptor
                };
                listOfRecords.Add(record);
                IndexBgWorker.ReportProgress(i);
            });
            BinaryAlgoRepository<List<CEDDRecord>> repo = new BinaryAlgoRepository<List<CEDDRecord>>();
            repo.Save(listOfRecords.ToList());
        }