Example #1
0
        public void SerializeTest()
        {
            var images = BagOfVisualWordsTest.images.DeepClone();

            Accord.Math.Tools.SetupGenerator(0);

            BagOfVisualWords bow = new BagOfVisualWords(10);

            bow.Compute(images);

            double[][] expected = new double[images.Length][];
            for (int i = 0; i < expected.Length; i++)
            {
                expected[i] = bow.GetFeatureVector(images[i]);
            }

            MemoryStream    stream = new MemoryStream();
            BinaryFormatter fmt    = new BinaryFormatter();

            fmt.Serialize(stream, bow);
            stream.Seek(0, SeekOrigin.Begin);
            bow = (BagOfVisualWords)fmt.Deserialize(stream);

            double[][] actual = new double[expected.Length][];
            for (int i = 0; i < actual.Length; i++)
            {
                actual[i] = bow.GetFeatureVector(images[i]);
            }


            Assert.IsTrue(expected.IsEqual(actual));
        }
        public void GetFeatureVectorTest()
        {
            var images = GetImages();

            Accord.Math.Random.Generator.Seed = 0;
            Bitmap image = new Bitmap(images[0]);

            // The Bag-of-Visual-Words model converts arbitrary-size images
            // into fixed-length feature vectors. In this example, we will
            // be setting the codebook size to 10. This means all generated
            // feature vectors will have the same length of 10.

            // Create a new Bag-of-Visual-Words (BoW) model
            BagOfVisualWords bow = new BagOfVisualWords(10);

            bow.ParallelOptions.MaxDegreeOfParallelism = 1;

            // Compute the model using
            // a set of training images
            bow.Compute(images);

            // After this point, we will be able to translate
            // images into double[] feature vectors using
            double[] feature = bow.GetFeatureVector(image);

            Assert.AreEqual(10, feature.Length);


            double[][] expected =
            {
                new double[] { 47, 44, 42,  4, 23, 22, 28, 53,  50,  96 },
                new double[] { 26, 91, 71, 49, 99, 70, 59, 28, 155,  79 },
                new double[] { 71, 34, 51, 33, 53, 25, 44, 64,  32, 145 }
            };

            double[][] actual = new double[expected.Length][];
            for (int i = 0; i < actual.Length; i++)
            {
                actual[i] = bow.GetFeatureVector(images[i]);
            }

            //string str = actual.ToString(CSharpJaggedMatrixFormatProvider.InvariantCulture);
            //Assert.IsNullOrEmpty(str);

            for (int i = 0; i < actual.Length; i++)
            {
                for (int j = 0; j < actual[i].Length; j++)
                {
                    Assert.IsTrue(expected[i].Contains(actual[i][j]));
                }
            }
        }
Example #3
0
        public void GetFeatureVectorTest()
        {
            var images = GetImages();

            Accord.Math.Random.Generator.Seed = 0;

            // The Bag-of-Visual-Words model converts arbitrary-size images
            // into fixed-length feature vectors. In this example, we will
            // be setting the codebook size to 10. This means all generated
            // feature vectors will have the same length of 10.

            // Create a new Bag-of-Visual-Words (BoW) model
            BagOfVisualWords bow = new BagOfVisualWords(10);

            bow.ParallelOptions.MaxDegreeOfParallelism = 1;

            // Compute the model using
            // a set of training images
            bow.Compute(images);

            // After this point, we will be able to translate
            // images into double[] feature vectors using
            double[] feature = bow.GetFeatureVector(images[0]);

            Assert.AreEqual(10, feature.Length);


            double[][] expected = new double[][]
            {
                new double[] { 4, 28, 24, 68, 51, 97, 60, 35, 18, 24 },
                new double[] { 53, 111, 89, 70, 24, 80, 130, 46, 50, 74 },
                new double[] { 31, 29, 57, 102, 63, 142, 40, 18, 37, 33 }
            };

            double[][] actual = new double[expected.Length][];
            for (int i = 0; i < actual.Length; i++)
            {
                actual[i] = bow.GetFeatureVector(images[i]);
            }

            string str = actual.ToCSharp();

            for (int i = 0; i < actual.Length; i++)
            {
                for (int j = 0; j < actual[i].Length; j++)
                {
                    Assert.IsTrue(expected[i].Contains(actual[i][j]));
                }
            }
        }
Example #4
0
        public override int ProcessImages(List <ImageData> images, out double[][] inputs, out int[] outputs)
        {
            outputs = new int[images.Count];
            inputs  = new double[images.Count][];

            var imageData = new List <Bitmap>();

            foreach (var image in images)
            {
                using (var stream = new MemoryStream(image.Image))
                {
                    imageData.Add(new Bitmap(stream));
                }
            }

            var converter = new CornerFeaturesDetector(_detector);

            _bagOfVisualWords = new BagOfVisualWords <CornerFeaturePoint>(converter, NumberOfWords);

            _bagOfVisualWords.Compute(imageData.ToArray());

            for (var i = 0; i < images.Count; i++)
            {
                inputs[i]  = _bagOfVisualWords.GetFeatureVector(imageData[i]);
                outputs[i] = Utilities.GetIntFromClass(images[i].Type);
            }

            return(images.Count);
        }
        public void GetFeatureVectorTest()
        {
            Accord.Math.Tools.SetupGenerator(0);
            Bitmap image = images[0];

            // The Bag-of-Visual-Words model converts arbitrary-size images
            // into fixed-length feature vectors. In this example, we will
            // be setting the codebook size to 10. This means all generated
            // feature vectors will have the same length of 10.

            // Create a new Bag-of-Visual-Words (BoW) model
            BagOfVisualWords bow = new BagOfVisualWords(10);

            // Compute the model using
            // a set of training images
            bow.Compute(images);

            // After this point, we will be able to translate
            // images into double[] feature vectors using
            double[] feature = bow.GetFeatureVector(image);

            Assert.AreEqual(10, feature.Length);


            double[][] expected =
            {
                new double[] { 102,  58, 42,  24, 47, 53,  29, 26,  3, 22 },
                new double[] {  90, 135, 71, 101, 26, 28, 105, 61, 62, 48 },
                new double[] { 138,  36, 55,  56, 71, 61,  30, 47, 33, 22 }
            };

            double[][] actual = new double[expected.Length][];
            for (int i = 0; i < actual.Length; i++)
            {
                actual[i] = bow.GetFeatureVector(images[i]);
            }

            // string str = actual.ToString(CSharpJaggedMatrixFormatProvider.InvariantCulture);

            for (int i = 0; i < actual.Length; i++)
            {
                for (int j = 0; j < actual[i].Length; j++)
                {
                    Assert.IsTrue(expected[i].Contains(actual[i][j]));
                }
            }
        }
Example #6
0
        public void GetFeatureVectorTest()
        {
            Accord.Math.Tools.SetupGenerator(0);
            Bitmap image = (Bitmap)images[0].Clone();

            // The Bag-of-Visual-Words model converts arbitrary-size images
            // into fixed-length feature vectors. In this example, we will
            // be setting the codebook size to 10. This means all generated
            // feature vectors will have the same length of 10.

            // Create a new Bag-of-Visual-Words (BoW) model
            BagOfVisualWords bow = new BagOfVisualWords(10);

            // Compute the model using
            // a set of training images
            bow.Compute(images);

            // After this point, we will be able to translate
            // images into double[] feature vectors using
            double[] feature = bow.GetFeatureVector(image);

            Assert.AreEqual(10, feature.Length);


            double[][] expected =
            {
                new double[] { 43,  39, 27, 21,  34,  30,  98, 51, 61,  5 },
                new double[] { 69, 100, 61, 41, 114, 125,  85, 27, 34, 71 },
                new double[] { 52,  46, 44, 19,  20,  51, 143, 73, 69, 35 }
            };

            double[][] actual = new double[expected.Length][];
            for (int i = 0; i < actual.Length; i++)
            {
                actual[i] = bow.GetFeatureVector(images[i]);
            }

            // string str = actual.ToString(CSharpJaggedMatrixFormatProvider.InvariantCulture);

            for (int i = 0; i < actual.Length; i++)
            {
                for (int j = 0; j < actual[i].Length; j++)
                {
                    Assert.IsTrue(expected[i].Contains(actual[i][j]));
                }
            }
        }
        public void CalculateSampleFeatures(BagOfVisualWords bow)
        {
            List<double[]> features = new List<double[]>();
            foreach(var img in Images)
            {
                var vector = bow.GetFeatureVector(img.BitmapImage);
                features.Add(vector);
            }

            SampleFeatures = features.ToArray();
        }
Example #8
0
        /// <summary>
        ///   This methods computes the Bag-of-Visual-Words with the training images.
        /// </summary>
        ///
        private void btnBagOfWords_Click(object sender, EventArgs e)
        {
            int numberOfWords = (int)numWords.Value;

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

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

            if (cbExtended.Checked)
            {
                bow.Detector.ComputeDescriptors = SpeededUpRobustFeatureDescriptorType.Extended;
            }

            Stopwatch sw1 = Stopwatch.StartNew();

            // Compute the BoW codebook using training images only
            var points = bow.Compute(originalTrainImages.Values.ToArray());

            sw1.Stop();


            Stopwatch sw2 = Stopwatch.StartNew();

            // Extract features for all images
            foreach (ListViewItem item in listView1.Items)
            {
                // Get item image
                Bitmap image = originalImages[item.ImageKey] as Bitmap;

                // Process image
                double[] featureVector = bow.GetFeatureVector(image);
                string   featureString = featureVector.ToString(DefaultArrayFormatProvider.InvariantCulture);

                if (item.SubItems.Count == 2)
                {
                    item.SubItems[1].Text = featureString;
                }
                else
                {
                    item.SubItems.Add(featureString);
                }

                int classLabel = (item.Tag as Tuple <double[], int>).Item2;
                item.Tag = Tuple.Create(featureVector, classLabel);
            }

            sw2.Stop();

            lbStatus.Text = "BoW constructed in " + sw1.Elapsed + "s. Features extracted in " + sw2.Elapsed + "s.";
            btnSampleRunAnalysis.Enabled = true;
        }
Example #9
0
        public void SerializeTest2()
        {
            var images = BagOfVisualWordsTest.images.DeepClone();

            Accord.Math.Tools.SetupGenerator(0);

            FastCornersDetector fast = new FastCornersDetector();

            FastRetinaKeypointDetector freak = new FastRetinaKeypointDetector(fast);

            var kmodes = new KModes <byte>(5, Distance.BitwiseHamming);

            var bow = new BagOfVisualWords <FastRetinaKeypoint, byte[]>(freak, kmodes);

            bow.Compute(images);


            double[][] expected = new double[images.Length][];
            for (int i = 0; i < expected.Length; i++)
            {
                expected[i] = bow.GetFeatureVector(images[i]);
            }

            MemoryStream    stream = new MemoryStream();
            BinaryFormatter fmt    = new BinaryFormatter();

            fmt.Serialize(stream, bow);
            stream.Seek(0, SeekOrigin.Begin);
            bow = (BagOfVisualWords <FastRetinaKeypoint, byte[]>)fmt.Deserialize(stream);

            double[][] actual = new double[expected.Length][];
            for (int i = 0; i < actual.Length; i++)
            {
                actual[i] = bow.GetFeatureVector(images[i]);
            }


            Assert.IsTrue(expected.IsEqual(actual));
        }
Example #10
0
        public void SerializeTest2()
        {
            var images = GetImages();

            Accord.Math.Random.Generator.Seed = 0;

            FastCornersDetector fast = new FastCornersDetector();

            FastRetinaKeypointDetector freak = new FastRetinaKeypointDetector(fast);

            var kmodes = new KModes <byte>(5, new Hamming());

            kmodes.ParallelOptions.MaxDegreeOfParallelism = 1;

            var bow = new BagOfVisualWords <FastRetinaKeypoint, byte[]>(freak, kmodes);

            bow.Compute(images);

            double[][] expected = new double[images.Length][];
            for (int i = 0; i < expected.Length; i++)
            {
                expected[i] = bow.GetFeatureVector(images[i]);
            }

            MemoryStream    stream = new MemoryStream();
            BinaryFormatter fmt    = new BinaryFormatter();

            fmt.Serialize(stream, bow);
            stream.Seek(0, SeekOrigin.Begin);
            bow = (BagOfVisualWords <FastRetinaKeypoint, byte[]>)fmt.Deserialize(stream);

            double[][] actual = new double[expected.Length][];
            for (int i = 0; i < actual.Length; i++)
            {
                actual[i] = bow.GetFeatureVector(images[i]);
            }

            Assert.IsTrue(expected.IsEqual(actual));
        }
Example #11
0
        public void GetFeatureVectorTest()
        {
            Accord.Math.Tools.SetupGenerator(0);
            Bitmap image = images[0];

            // The Bag-of-Visual-Words model converts arbitrary-size images
            // into fixed-length feature vectors. In this example, we will
            // be setting the codebook size to 10. This means all generated
            // feature vectors will have the same length of 10.

            // Create a new Bag-of-Visual-Words (BoW) model
            BagOfVisualWords bow = new BagOfVisualWords(10);

            // Compute the model using
            // a set of training images
            bow.Compute(images);

            // After this point, we will be able to translate
            // images into double[] feature vectors using
            double[] feature = bow.GetFeatureVector(image);

            Assert.AreEqual(10, feature.Length);


            double[][] expected =
            {
                new double[] { 26,  58, 102,  24, 53, 22, 47,  29, 42,  3 },
                new double[] { 61, 135,  90, 101, 28, 48, 26, 105, 71, 62 },
                new double[] { 47,  36, 138,  56, 61, 22, 71,  30, 55, 33 },
            };

            double[][] actual = new double[expected.Length][];
            for (int i = 0; i < actual.Length; i++)
            {
                actual[i] = bow.GetFeatureVector(images[i]);
            }

            Assert.IsTrue(expected.IsEqual(actual));
        }
Example #12
0
        public void BagOfVisualWordsConstructorTest3()
        {
            Accord.Math.Random.Generator.Seed = 0;

            var images = GetImages();

            MoravecCornersDetector moravec  = new MoravecCornersDetector();
            CornerFeaturesDetector detector = new CornerFeaturesDetector(moravec);

            var bow = new BagOfVisualWords <CornerFeaturePoint>(detector, numberOfWords: 10);

            bow.ParallelOptions.MaxDegreeOfParallelism = 1;

#pragma warning disable 612, 618
            var points = bow.Compute(images, 1e-3);
#pragma warning restore 612, 618
            double[] vector = bow.GetFeatureVector(images[0]);

            Assert.AreEqual(10, bow.NumberOfWords);
            Assert.AreEqual(6, points.Length);
            Assert.AreEqual(10, vector.Length);

            Assert.AreEqual(2800, points[0].Count);
            Assert.AreEqual(4532, points[1].Count);
            Assert.AreEqual(2282, points[2].Count);
            Assert.AreEqual(1173, points[3].Count);
            Assert.AreEqual(4860, points[4].Count);
            Assert.AreEqual(5730, points[5].Count);

            Assert.AreEqual(596, points[0][0].Descriptor[0]);
            Assert.AreEqual(51, points[0][0].Descriptor[1]);
            Assert.AreEqual(points[0][0].Descriptor[0], points[0][0].X);
            Assert.AreEqual(points[0][0].Descriptor[1], points[0][0].Y);

            Assert.AreEqual(461, points[3][7].Descriptor[0]);
            Assert.AreEqual(8, points[2][3].Descriptor[1]);

            Assert.AreEqual(991, points[2][52].Descriptor[0]);
            Assert.AreEqual(82, points[1][11].Descriptor[1]);

            Assert.AreEqual(430, points[0][42].Descriptor[0]);
            Assert.AreEqual(135, points[4][125].Descriptor[1]);
        }
Example #13
0
        public void BagOfVisualWordsConstructorTest3()
        {
            MoravecCornersDetector moravec  = new MoravecCornersDetector();
            CornerFeaturesDetector detector = new CornerFeaturesDetector(moravec);

            var bow = new BagOfVisualWords <CornerFeaturePoint>(detector, numberOfWords: 10);

            var points = bow.Compute(images, 1e-3);

            double[] vector = bow.GetFeatureVector(images[0]);

            Assert.AreEqual(10, bow.NumberOfWords);
            Assert.AreEqual(6, points.Length);
            Assert.AreEqual(10, vector.Length);

            Assert.AreEqual(2800, points[0].Count);
            Assert.AreEqual(4532, points[1].Count);
            Assert.AreEqual(2282, points[2].Count);
            Assert.AreEqual(1173, points[3].Count);
            Assert.AreEqual(4860, points[4].Count);
            Assert.AreEqual(5730, points[5].Count);

            Assert.AreEqual(596, points[0][0].Descriptor[0]);
            Assert.AreEqual(51, points[0][0].Descriptor[1]);
            Assert.AreEqual(points[0][0].Descriptor[0], points[0][0].X);
            Assert.AreEqual(points[0][0].Descriptor[1], points[0][0].Y);

            Assert.AreEqual(461, points[3][7].Descriptor[0]);
            Assert.AreEqual(8, points[2][3].Descriptor[1]);

            Assert.AreEqual(991, points[2][52].Descriptor[0]);
            Assert.AreEqual(82, points[1][11].Descriptor[1]);

            Assert.AreEqual(430, points[0][42].Descriptor[0]);
            Assert.AreEqual(135, points[4][125].Descriptor[1]);
        }
Example #14
0
        public void SerializeTest()
        {
            Accord.Math.Tools.SetupGenerator(0);

            BagOfVisualWords bow = new BagOfVisualWords(10);

            bow.Compute(images);

            double[][] expected = new double[images.Length][];
            for (int i = 0; i < expected.Length; i++)
                expected[i] = bow.GetFeatureVector(images[i]);

            MemoryStream stream = new MemoryStream();
            BinaryFormatter fmt = new BinaryFormatter();
            fmt.Serialize(stream, bow);
            stream.Seek(0, SeekOrigin.Begin);
            bow = (BagOfVisualWords)fmt.Deserialize(stream);

            double[][] actual = new double[expected.Length][];
            for (int i = 0; i < actual.Length; i++)
                actual[i] = bow.GetFeatureVector(images[i]);


            Assert.IsTrue(expected.IsEqual(actual));
        }
Example #15
0
        public void GetFeatureVectorTest()
        {
            Accord.Math.Tools.SetupGenerator(0);
            Bitmap image = images[0];

            // The Bag-of-Visual-Words model converts arbitrary-size images 
            // into fixed-length feature vectors. In this example, we will
            // be setting the codebook size to 10. This means all generated
            // feature vectors will have the same length of 10.

            // Create a new Bag-of-Visual-Words (BoW) model
            BagOfVisualWords bow = new BagOfVisualWords(10);

            // Compute the model using
            // a set of training images
            bow.Compute(images);

            // After this point, we will be able to translate
            // images into double[] feature vectors using
            double[] feature = bow.GetFeatureVector(image);

            Assert.AreEqual(10, feature.Length);


            double[][] expected = 
            {
                new double[] { 26, 58, 102, 24, 53, 22, 47, 29, 42, 3 },
                new double[] { 61, 135, 90, 101, 28, 48, 26, 105, 71, 62 },
                new double[] { 47, 36, 138, 56, 61, 22, 71, 30, 55, 33 },
            };

            double[][] actual = new double[expected.Length][];
            for (int i = 0; i < actual.Length; i++)
                actual[i] = bow.GetFeatureVector(images[i]);

            Assert.IsTrue(expected.IsEqual(actual));
        }
Example #16
0
        public void BagOfVisualWordsConstructorTest3()
        {
            MoravecCornersDetector moravec = new MoravecCornersDetector();
            CornerFeaturesDetector detector = new CornerFeaturesDetector(moravec);

            var bow = new BagOfVisualWords<CornerFeaturePoint>(detector, numberOfWords: 10);

            var points = bow.Compute(images, 1e-3);

            double[] vector = bow.GetFeatureVector(images[0]);

            Assert.AreEqual(10, bow.NumberOfWords);
            Assert.AreEqual(6, points.Length);
            Assert.AreEqual(10, vector.Length);

            Assert.AreEqual(2800, points[0].Count);
            Assert.AreEqual(4532, points[1].Count);
            Assert.AreEqual(2282, points[2].Count);
            Assert.AreEqual(1173, points[3].Count);
            Assert.AreEqual(4860, points[4].Count);
            Assert.AreEqual(5730, points[5].Count);

            Assert.AreEqual(596, points[0][0].Descriptor[0]);
            Assert.AreEqual(51, points[0][0].Descriptor[1]);
            Assert.AreEqual(points[0][0].Descriptor[0], points[0][0].X);
            Assert.AreEqual(points[0][0].Descriptor[1], points[0][0].Y);

            Assert.AreEqual(461, points[3][7].Descriptor[0]);
            Assert.AreEqual(8, points[2][3].Descriptor[1]);

            Assert.AreEqual(991, points[2][52].Descriptor[0]);
            Assert.AreEqual(82, points[1][11].Descriptor[1]);

            Assert.AreEqual(430, points[0][42].Descriptor[0]);
            Assert.AreEqual(135, points[4][125].Descriptor[1]);
        }
Example #17
0
        /// <summary>
        ///   This methods computes the Bag-of-Visual-Words with the training images.
        /// </summary>
        /// 
        private void btnBagOfWords_Click(object sender, EventArgs e)
        {
            int numberOfWords = (int)numWords.Value;

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

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

            if (cbExtended.Checked)
                bow.Detector.ComputeDescriptors = SpeededUpRobustFeatureDescriptorType.Extended;

            Stopwatch sw1 = Stopwatch.StartNew();

            // Compute the BoW codebook using training images only
            var points = bow.Compute(originalTrainImages.Values.ToArray());

            sw1.Stop();


            Stopwatch sw2 = Stopwatch.StartNew();

            // Extract features for all images
            foreach (ListViewItem item in listView1.Items)
            {
                // Get item image
                Bitmap image = originalImages[item.ImageKey] as Bitmap;

                // Process image
                double[] featureVector = bow.GetFeatureVector(image);
                string featureString = featureVector.ToString(DefaultArrayFormatProvider.InvariantCulture);

                if (item.SubItems.Count == 2)
                    item.SubItems[1].Text = featureString;
                else item.SubItems.Add(featureString);

                int classLabel = (item.Tag as Tuple<double[], int>).Item2;
                item.Tag = Tuple.Create(featureVector, classLabel);
            }

            sw2.Stop();

            lbStatus.Text = "BoW constructed in " + sw1.Elapsed + "s. Features extracted in " + sw2.Elapsed + "s.";
            btnSampleRunAnalysis.Enabled = true;
        }
        public void GetFeatureVectorTest()
        {
            Accord.Math.Tools.SetupGenerator(0);
            Bitmap image = images[0];

            // The Bag-of-Visual-Words model converts arbitrary-size images 
            // into fixed-length feature vectors. In this example, we will
            // be setting the codebook size to 10. This means all generated
            // feature vectors will have the same length of 10.

            // Create a new Bag-of-Visual-Words (BoW) model
            BagOfVisualWords bow = new BagOfVisualWords(10);

            // Compute the model using
            // a set of training images
            bow.Compute(images);

            // After this point, we will be able to translate
            // images into double[] feature vectors using
            double[] feature = bow.GetFeatureVector(image);

            Assert.AreEqual(10, feature.Length);


            double[][] expected = 
            {
                new double[] { 102, 58, 42, 24, 47, 53, 29, 26, 3, 22 },
                new double[] { 90, 135, 71, 101, 26, 28, 105, 61, 62, 48 },
                new double[] { 138, 36, 55, 56, 71, 61, 30, 47, 33, 22 } 
            };

            double[][] actual = new double[expected.Length][];
            for (int i = 0; i < actual.Length; i++)
                actual[i] = bow.GetFeatureVector(images[i]);

            // string str = actual.ToString(CSharpJaggedMatrixFormatProvider.InvariantCulture);

            for (int i = 0; i < actual.Length; i++)
            {
                for (int j = 0; j < actual[i].Length; j++)
                {
                    Assert.IsTrue(expected[i].Contains(actual[i][j]));
                }
            }
        }
        public void SerializeTest2()
        {
            Accord.Math.Tools.SetupGenerator(0);

            FastCornersDetector fast = new FastCornersDetector();

            FastRetinaKeypointDetector freak = new FastRetinaKeypointDetector(fast);

            var kmodes = new KModes<byte[]>(5, Distance.BitwiseHamming);

            var bow = new BagOfVisualWords<FastRetinaKeypoint, byte[]>(freak, kmodes);

            bow.Compute(images);



            double[][] expected = new double[images.Length][];
            for (int i = 0; i < expected.Length; i++)
                expected[i] = bow.GetFeatureVector(images[i]);

            MemoryStream stream = new MemoryStream();
            BinaryFormatter fmt = new BinaryFormatter();
            fmt.Serialize(stream, bow);
            stream.Seek(0, SeekOrigin.Begin);
            bow = (BagOfVisualWords<FastRetinaKeypoint, byte[]>)fmt.Deserialize(stream);

            double[][] actual = new double[expected.Length][];
            for (int i = 0; i < actual.Length; i++)
                actual[i] = bow.GetFeatureVector(images[i]);


            Assert.IsTrue(expected.IsEqual(actual));
        }
Example #20
0
 public override Double[] ProcessImages(Image ctx)
 {
     return(_bagOfVisualWords.GetFeatureVector(new Bitmap(ctx)));
 }
 public void CalculateFeatureVector(BagOfVisualWords bow)
 {
     FeatureVector = bow.GetFeatureVector(_image.BitmapImage);
 }