Example #1
0
        static void SensorGaborFilterTest(int maxIterations)
        {
            string TrainingSetPath = Path.Combine("O:", "clean");

            var filter = new Gabor2DFilter();
            var writer = new MatrixToBitmapFileWriter("");

            var sensor = new BitmapPicture2DSensor(presentationsPerInput: 1, pathSpeed: 2, useRandomOrigin: true);
            sensor.SetTrainingFolder(TrainingSetPath);
            sensor.AddFilter(filter);
            sensor.OnFilteredMatrixOutput += writer.OutputWriterHandler;

            int nbIterations = 0;
            foreach (var input in sensor.GetTrainingInputs(true))
            {
                foreach (var iteration in input)
                {
                    nbIterations++;
                    if (nbIterations >= maxIterations)
                        break;
                }
                if (nbIterations >= maxIterations)
                    break;
            }
        }
        public void CanOutputBitmapFilesFromSensorGeneratedImagesUsingTwoSensorsAndOneOutputFolder()
        {
            var sensor = new BitmapPicture2DSensor(presentationsPerInput: 1, pathSpeed: 2);
            sensor.SetTrainingFolder(TrainingSetPath);
            var writer = new MatrixToBitmapFileWriter("SameFolder");
            sensor.OnTransformedMatrixOutput += writer.OutputWriterHandler;

            var nbIterations = 0;

            foreach (var input in sensor.GetTrainingInputs(true))
            {
                foreach (var iteration in input)
                {
                    nbIterations++;
                }
            }

            Assert.AreEqual(nbIterations, writer.OutputFolder.GetFiles().Length);

            var sensor2 = new BitmapPicture2DSensor(presentationsPerInput: 1, pathSpeed: 2);
            sensor2.SetTrainingFolder(TrainingSetPath);
            var writer2 = new MatrixToBitmapFileWriter("sameFolder");
            sensor2.OnTransformedMatrixOutput += writer2.OutputWriterHandler;

            var nbIterations2 = 0;

            foreach (var input in sensor2.GetTrainingInputs(true))
            {
                foreach (var iteration in input)
                {
                    nbIterations2++;
                }
            }

            Assert.AreEqual(nbIterations2, writer2.OutputFolder.GetFiles().Length);
        }
        public void GenerateInputsAlwaysInsideSensor()
        {
            var sensor = new BitmapPicture2DSensor(pathSpeed: 100);
            sensor.SetTrainingFolder(TrainingSetPath);
            var writer = new MatrixToBitmapFileWriter();
            sensor.OnTransformedMatrixOutput += writer.OutputWriterHandler;
            var nbInputIterationsOutside = 0;

            foreach (var input in sensor.GetTrainingInputs(true))
            {
                Assert.IsNotNull(input.CurrentFile);
                Assert.IsFalse(string.IsNullOrWhiteSpace(input.CategoryName));

                foreach (var iteration in input)
                {
                    if (sensor.IsCurrentInputOutsideField())
                        nbInputIterationsOutside++;
                }
            }

            Assert.AreEqual(0, nbInputIterationsOutside);
        }
        public void CanOutputFilterFromGabor2DFilter()
        {
            var filter = new Gabor2DFilter();
            var writer = new MatrixToBitmapFileWriter("");
            filter.OnFilterCreated += writer.OutputWriterHandler;

            var r = filter.FilterMatricesReal.Length;
            var i = filter.FilterMatricesImaginary.Length;

            Assert.AreEqual(r + i, writer.OutputFolder.GetFiles().Length);
        }
        public void CanOutputFilteredInputsFromGabor2DFilter()
        {
            var filter = new Gabor2DFilter();
            var writer = new MatrixToBitmapFileWriter("");

            var sensor = new BitmapPicture2DSensor(presentationsPerInput: 1, pathSpeed: 2, useRandomOrigin: true);
            sensor.SetTrainingFolder(TrainingSetPath);
            sensor.AddFilter(filter);
            sensor.OnFilteredMatrixOutput += writer.OutputWriterHandler;
            int maxIterations = 100, nbIterations = 0;

            var begin = DateTime.Now;
            foreach (var input in sensor.GetTrainingInputs(true))
            {
                foreach (var iteration in input)
                {
                    nbIterations++;
                    if (nbIterations >= maxIterations)
                        break;
                }
                if (nbIterations >= maxIterations)
                    break;
            }
            var end = DateTime.Now;

            Debug.WriteLine(begin);
            Debug.WriteLine("{0} (duration: {1:D} ms)", end, (int)(end - begin).TotalMilliseconds);

            Assert.AreEqual(maxIterations, writer.OutputFolder.GetFiles().Length);
        }
        public void CanOutputBitmapFilesFromSensorTransformedInputsWithTranslationRotationAndScaling()
        {
            var sensor = new BitmapPicture2DSensor(presentationsPerInput: 1, pathSpeed: 2,
                rotationAngleMaxDegrees:180.0f, rotationSpeed:10.0f, scalingMin:0.5f, scalingMax:2.0f, scalingSpeed:0.1f);
            sensor.SetTrainingFolder(TrainingSetPath);
            var writer = new MatrixToBitmapFileWriter("");
            sensor.OnTransformedMatrixOutput += writer.OutputWriterHandler;

            var nbIterations = 0;

            foreach (var input in sensor.GetTrainingInputs(true))
            {
                foreach (var iteration in input)
                {
                    nbIterations++;
                }
            }

            Assert.AreEqual(nbIterations, writer.OutputFolder.GetFiles().Length);
        }
        public void CanOutputBitmapFilesFromSensorTransformedInputsWithTranslation()
        {
            var sensor = new BitmapPicture2DSensor(presentationsPerInput: 1, pathSpeed: 2, useRandomOrigin: false);
            sensor.SetTrainingFolder(TrainingSetPath);
            var writer = new MatrixToBitmapFileWriter("");
            sensor.OnTransformedMatrixOutput += writer.OutputWriterHandler;

            var realNbInputs = sensor.TrainingFolder.EnumerateFiles("*.bmp", SearchOption.AllDirectories).Count();

            var nbIterations = 0;
            var nbInputs = 0;

            foreach (var input in sensor.GetTrainingInputs(true))
            {
                bool newInput = true;
                foreach (var iteration in input)
                {
                    if (newInput)
                    {
                        nbInputs++;
                        newInput = false;
                    }
                    nbIterations++;
                }
            }

            Assert.AreEqual(realNbInputs, nbInputs, "nbInputs");
            Assert.AreEqual(nbIterations, writer.OutputFolder.GetFiles().Length, "nbIterations");
        }