public void SymbolRecognitionBySVM(string positivePath, string negativePath, string testPath)
        {
            double[][] inputs, testInputs;
            int[] outputs;
            Image<Bgr, Byte>[] Positives, Negatives;
            Image<Bgr, Byte> test;
            int total = 0;
            int counter = 0;
            _scanImage = new ScanImage();
            _descriptor = new Descriptor();
            _scanImage.SetImages(positivePath, negativePath, testPath, out Positives, out Negatives, out test);
            if (Negatives != null && Negatives.Length != 0)
                total += Negatives.Length;
            if (Positives != null && Positives.Length != 0)
                total += Positives.Length;
            inputs = new double[total][];
            outputs = new Int32[total];

            if (Negatives != null || Negatives.Length != 0)
                for (int i = 0; i < Negatives.Length; i++)
                {
                    inputs[counter] = _descriptor.GetImageVector(Negatives[i], 100);
                    outputs[counter++] = 0;
                }
            if (Positives != null || Positives.Length != 0)
                for (int i = 0; i < Positives.Length; i++)
                {
                    inputs[counter] = _descriptor.GetImageVector(Positives[i], 100);
                    outputs[counter++] = 1;
                }

            _scanImage.ScanByPixel(@"C:\Users\simakmo\Documents\Sima\Symbol Reconition\data\", test, Positives[0], 50, 50);

            string[] filePaths = Directory.GetFiles(@"C:\Users\simakmo\Documents\Sima\Symbol Reconition\data\Intermediate", "*.jpg");
            testInputs = new double[filePaths.Length][];
             counter = 0;
            foreach (string path in filePaths)
                testInputs[counter++] = _descriptor.GetImageVector(new Image<Bgr, Byte>(path), 150);
            _machineLearning = new MachineLearning();

            int dimention = Positives[0].Height * Positives[0].Width;

            int[] testOutputs = _machineLearning.ApplySVMByGussianKernel(2, 2.5, 0.001, 0.2, inputs, outputs, dimention, testInputs);
            List<Point> results = new List<Point>();
            for (int j = 0; j < testOutputs.Length; j++)
            {
                int x, y, num;
                if (testOutputs[j] == 1)
                {
                    GetImageParameters(out x, out y, out num, filePaths[j]);
                    results.Add(new Point(x, y));
                }
            }
            Visualization.DrawResults(results, Positives[0].Size, test, testPath);
        }
Beispiel #2
0
        public void SymbolRecognitionBySVM(string positivePath, string negativePath, string testPath)
        {
            double[][]          inputs, testInputs;
            int[]               outputs;
            Image <Bgr, Byte>[] Positives, Negatives;
            Image <Bgr, Byte>   test;
            int total   = 0;
            int counter = 0;

            _scanImage  = new ScanImage();
            _descriptor = new Descriptor();
            _scanImage.SetImages(positivePath, negativePath, testPath, out Positives, out Negatives, out test);
            if (Negatives != null && Negatives.Length != 0)
            {
                total += Negatives.Length;
            }
            if (Positives != null && Positives.Length != 0)
            {
                total += Positives.Length;
            }
            inputs  = new double[total][];
            outputs = new Int32[total];

            if (Negatives != null || Negatives.Length != 0)
            {
                for (int i = 0; i < Negatives.Length; i++)
                {
                    inputs[counter]    = _descriptor.GetImageVector(Negatives[i], 100);
                    outputs[counter++] = 0;
                }
            }
            if (Positives != null || Positives.Length != 0)
            {
                for (int i = 0; i < Positives.Length; i++)
                {
                    inputs[counter]    = _descriptor.GetImageVector(Positives[i], 100);
                    outputs[counter++] = 1;
                }
            }

            _scanImage.ScanByPixel(@"C:\Users\simakmo\Documents\Sima\Symbol Reconition\data\", test, Positives[0], 50, 50);



            string[] filePaths = Directory.GetFiles(@"C:\Users\simakmo\Documents\Sima\Symbol Reconition\data\Intermediate", "*.jpg");
            testInputs = new double[filePaths.Length][];
            counter    = 0;
            foreach (string path in filePaths)
            {
                testInputs[counter++] = _descriptor.GetImageVector(new Image <Bgr, Byte>(path), 150);
            }
            _machineLearning = new MachineLearning();

            int dimention = Positives[0].Height * Positives[0].Width;

            int[]        testOutputs = _machineLearning.ApplySVMByGussianKernel(2, 2.5, 0.001, 0.2, inputs, outputs, dimention, testInputs);
            List <Point> results     = new List <Point>();

            for (int j = 0; j < testOutputs.Length; j++)
            {
                int x, y, num;
                if (testOutputs[j] == 1)
                {
                    GetImageParameters(out x, out y, out num, filePaths[j]);
                    results.Add(new Point(x, y));
                }
            }
            Visualization.DrawResults(results, Positives[0].Size, test, testPath);
        }