Ejemplo n.º 1
0
        public static void createBoW()
        {
            string[] files = Directory.GetFiles ("testset");
            Dictionary<string, Bitmap> testImages = new Dictionary<string, Bitmap>();

            for (int i = 0; i < files.Length; i++) {
                string name = Path.GetFileNameWithoutExtension (files [i]);
                testImages.Add(name, (Bitmap)Bitmap.FromFile(files[i]));
            }

            int numberOfWords = 6; // number of cluster centers: typically >>100

            // Create a Binary-Split clustering algorithm
            BinarySplit binarySplit = new BinarySplit(numberOfWords);

            // Create bag-of-words (BoW) with the given algorithm
            BagOfVisualWords surfBow = new BagOfVisualWords(binarySplit);

            // Compute the BoW codebook using training images only
            Bitmap[] bmps = new Bitmap[testImages.Count];
            testImages.Values.CopyTo(bmps, 0);
            surfBow.Compute(bmps);

            surfBow.Save ("bagOfWords");
        }