コード例 #1
0
        public void EdgeTrackingTest()
        {
            var drive = new Drive(Path.Combine(Dir.CarusoTestDirectory, Dir.EdgeTrackingDirectory), Drive.Reason.Read);
            var image = new Bitmap(drive.Files("simple").First());
            var left  = EdgeDetector.EdgePoints(image, Direction.FromLeft);

            Assert.IsTrue(left[0] == -1);
            Assert.IsTrue(left[75] == 46);
            Assert.IsTrue(left[363] == 46);
            Assert.IsTrue(left[364] == 6);
            Assert.IsTrue(left[405] == 6);
            Assert.IsTrue(left[406] == 46);
            Assert.IsTrue(left[424] == 46);
            Assert.IsTrue(left[425] == -1);
            Assert.IsTrue(left[499] == -1);

            var right = EdgeDetector.EdgePoints(image, Direction.FromRight);

            Assert.IsTrue(right[0] == -1);
            Assert.IsTrue(right[75] == 154);
            Assert.IsTrue(right[218] == 154);
            Assert.IsTrue(right[219] == 188);
            Assert.IsTrue(right[294] == 188);
            Assert.IsTrue(right[295] == 154);
            Assert.IsTrue(right[424] == 154);
            Assert.IsTrue(right[425] == -1);
            Assert.IsTrue(right[499] == -1);
        }
コード例 #2
0
ファイル: Shred.cs プロジェクト: Algorithmix/Papyrus
        /// <summary>
        ///   Create a shred object given a filepath to a bitmap image
        /// </summary>
        /// <param name="filepath"> destination path of the shred image </param>
        /// <param name="ignoreTopBottom"> Default is true, set to false to scan top and bottom aswell </param>
        public Shred(string filepath, bool ignoreTopBottom = true)
        {
            InitializeINode();
            Filepath = filepath;
            Id       = _count++;

            Logger.Trace("Starting Chamfer From Left");

            int directions = ignoreTopBottom ? 4 : 8;

            Convolution = new List <double[]>(directions);
            Luminousity = new List <double[]>(directions);
            Chamfer     = new List <int[]>(directions);
            Thresholded = new List <double[]>(directions);
            Sparsity    = new List <long>(directions);
            Offsets     = new List <int[]>(directions);

            using (Bitmap source = new Bitmap(filepath))
            {
                var image = new Image <Bgra, Byte>(source);

                // Initialize List for Random Access
                for (int ii = 0; ii < directions; ii++)
                {
                    Convolution.Add(new double[0]);
                    Luminousity.Add(new double[0]);
                    Thresholded.Add(new double[0]);
                    Chamfer.Add(new int[0]);
                    Sparsity.Add((long)-1.0);
                    Offsets.Add(new int[0]);
                }

                foreach (int side in Enum.GetValues(typeof(Direction)))
                {
                    // 2 per side
                    if (side * 2 >= directions)
                    {
                        continue;
                    }

                    int regularIndex = Index((Direction)side, Orientation.Regular);
                    int reverseIndex = regularIndex + 1; //Index((Direction) side, Orientation.Reversed);

                    Logger.Trace("Measuring Side no:" + side);

                    int[] offset = EdgeDetector.EdgePoints(source, (Direction)side);
                    Offsets[regularIndex] = offset;
                    Offsets[reverseIndex] = Utility.Reverse(offset);

                    double[] luminousity = Forensics.Luminousity.RepresentativeLuminousity(image, BUFFER, SAMPLE_SIZE,
                                                                                           (Direction)side);
                    Luminousity[regularIndex] = luminousity;
                    Luminousity[reverseIndex] = Utility.Reverse(luminousity);

                    int[]    indicies     = Utility.GetKernelIndicies(ConvolutionKernel, -1);
                    double[] convolutions = Utility.Convolute(Luminousity[regularIndex], ConvolutionKernel, indicies);
                    Convolution[regularIndex] = convolutions;
                    Convolution[reverseIndex] = Utility.Reverse(convolutions);

                    double[] thresholded = Utility.Threshold(Utility.Absolute(Convolution[regularIndex]), THRESHOLD);
                    Thresholded[regularIndex] = thresholded;
                    Thresholded[reverseIndex] = Utility.Reverse(thresholded);

                    int[] chamfer = Forensics.Chamfer.Measure(Thresholded[regularIndex]);
                    Chamfer[regularIndex] = chamfer;
                    Chamfer[reverseIndex] = Utility.Reverse(chamfer);

                    long sparsity = Forensics.Chamfer.Sparsity(Chamfer[regularIndex]);
                    Sparsity[regularIndex] = sparsity;
                    Sparsity[reverseIndex] = sparsity;
                }
            }
        }