Exemple #1
0
        public void Index(DirectoryInfo folder)
        {
            var imagesOnDisk = FileHelper.GetImages(folder);

            _images.Clear();
            _imageGlobalColorDescriptors.Clear();
            _imageLocalDescriptors.Clear();

            foreach (var image in imagesOnDisk)
            {
                ColorHistogramPerRegionImageFeature colorFeature = new ColorHistogramPerRegionImageFeature();
                SurfImageFeatures features = new SurfImageFeatures();
                using (Image <Bgr, Byte> tempImage = new Image <Bgr, Byte>(image.FullName))
                {
                    using (Image <Gray, Byte> tempGrayImage = tempImage.Convert <Gray, byte>())
                    {
                        colorFeature.Compute(tempImage);
                        features.Compute(tempGrayImage);

                        var imageItem = new ImageItem(image.Name, image.FullName, features.Descriptors, colorFeature.Descriptors);

                        if ((colorFeature.Descriptors != null) && (features.Descriptors != null))
                        {
                            _images.Add(imageItem);
                            _imageGlobalColorDescriptors.Add(colorFeature.Descriptors);
                            _imageLocalDescriptors.Add(features.Descriptors);
                        }
                    }
                }
            }

            _localSimilarityEngine.Index(_imageLocalDescriptors);
            _globalSimilarityEngine.Index(_imageGlobalColorDescriptors);
        }
Exemple #2
0
        private List <KeyValuePair <ImageItem, int> > QueryUsingSurf(Image <Bgr, Byte> queryImage)
        {
            List <KeyValuePair <ImageItem, int> > results = new List <KeyValuePair <ImageItem, int> >();
            SurfImageFeatures queryFeatures = new SurfImageFeatures();

            queryFeatures.Compute(queryImage.Convert <Gray, byte>());
            _localSimilarityEngine.ComputeSimilarities(queryFeatures.Descriptors);

            int[] similarityVote = _localSimilarityEngine.SimilarityVote;
            for (int index = 0; index < _images.Count; ++index)
            {
                if (similarityVote[index] > 50)
                {
                    results.Add(new KeyValuePair <ImageItem, int>(_images.ImageItems[index], similarityVote[index]));
                }
            }

            results.Sort(delegate(KeyValuePair <ImageItem, int> first, KeyValuePair <ImageItem, int> second)
            {
                if (first.Value > second.Value)
                {
                    return(-1);
                }
                if (first.Value < second.Value)
                {
                    return(1);
                }

                return(0);
            });

            return(results);
        }
Exemple #3
0
        public Image <Bgr, Byte> Test(Image <Bgr, Byte> image1, Image <Bgr, Byte> image2)
        {
            ImageFeaturesMatcher imageMatcher = new ImageFeaturesMatcher();
            SurfImageFeatures    features1    = new SurfImageFeatures();
            SurfImageFeatures    features2    = new SurfImageFeatures();

            features1.Compute(image1.Convert <Gray, byte>());
            features2.Compute(image2.Convert <Gray, byte>());

            imageMatcher.Match(features1, features2);

            return(imageMatcher.Result);
        }