Inheritance: INode
Beispiel #1
0
        /// <summary>
        ///   IsFit checks if given a specified side, it can be fit with a shreds's edge
        ///   This Also returns a match object
        /// </summary>
        /// <param name="root"> </param>
        /// <param name="shred"> </param>
        /// <param name="side"> </param>
        /// <returns> </returns>
        private static Tuple <Match, Direction> IsFit(INode root, Shred shred, Side side)
        {
            Side  query;
            Match match;

            if (side.Orientation != shred.Orientation)
            {
                query = new Side(shred, Enumeration.Opposite(side.Direction), shred.Orientation);
                match = Match.Inverted;
            }
            else
            {
                query = side;
                match = Match.NonInverted;
            }

            // If Directions match AND The Availablility then return match, otherwise impossible
            if (query.Direction == Direction.FromLeft && root.LeftEdge() == shred.LeftEdge())
            {
                return(new Tuple <Match, Direction>(match, Direction.FromLeft));
            }
            if (query.Direction == Direction.FromRight && root.RightEdge() == shred.RightEdge())
            {
                return(new Tuple <Match, Direction>(match, Direction.FromRight));
            }
            return(new Tuple <Match, Direction>(Match.Impossible, Direction.FromLeft));
        }
Beispiel #2
0
 public static void ShredFactory(string filepath)
 {
     Shred shred = new Shred(filepath, false);
     shred.VisualizeChamfers(Direction.FromLeft);
     shred.VisualizeChamfers(Direction.FromRight);
     shred.VisualizeChamfers(Direction.FromTop);
     shred.VisualizeChamfers(Direction.FromBottom);
 }
Beispiel #3
0
        /// <summary>
        ///   Given two shreds, calculate the offset value at which the two shreds are most similar
        /// </summary>
        /// <param name="first"> The first shred staged for comparison </param>
        /// <param name="second"> The other shred staged for comparison </param>
        /// <param name="directionA"> Direction of this shred to be compared </param>
        /// <param name="orientationA"> Orientation of this shred to be compared </param>
        /// <param name="directionB"> Direction of the other shred to be compared </param>
        /// <param name="orientationB"> Orientiation of the other shred to be compared </param>
        /// <returns> Tuple containing the max similarity value and the offset at which that occured </returns>
        public static MatchData CompareShred(Shred first,
                                             Shred second,
                                             Direction directionA,
                                             Orientation orientationA,
                                             Direction directionB,
                                             Orientation orientationB)
        {
            Side   sideA   = new Side(first, directionA, orientationA);
            Side   sideB   = new Side(second, directionB, orientationB);
            double penalty = 1.0;

            if (ORIENTATION_PENALTY)
            {
                if (first.TrueOrienation != null && second.TrueOrienation != null)
                {
                    if (!(
                            (first.TrueOrienation == orientationA && second.TrueOrienation == orientationB) ||
                            (first.TrueOrienation == Enumeration.Opposite(orientationA) && second.TrueOrienation == Enumeration.Opposite(orientationB))))
                    {
                        penalty = 0.15;
                    }
                }
            }

            if (NORMALIZATION_ENABLED)
            {
                double max = Chamfer.NormalizedSimilarity(
                    first.GetChamfer(directionA, orientationA),
                    second.GetChamfer(directionB, orientationB));
                double[] scan = new double[1];

                return(new MatchData(max * penalty, 0, scan, sideA, sideB));
            }
            else
            {
                double[] scan = Chamfer.ScanSimilarity(
                    first.GetChamfer(directionA, orientationA),
                    second.GetChamfer(directionB, orientationB));

                Tuple <double, int> maxData = Utility.Max(scan);
                double max  = maxData.Item1;
                int    best = maxData.Item2;
                return(new MatchData(max * penalty, best, scan, sideA, sideB));
            }
        }
Beispiel #4
0
 private static void WriteLeaf(Shred shred, JsonTextWriter writer)
 {
 }
Beispiel #5
0
 private static void WriteLeaf(Shred shred, JsonTextWriter writer)
 {
 }
Beispiel #6
0
        /// <summary>
        ///   Given two shreds, calculate the offset value at which the two shreds are most similar
        /// </summary>
        /// <param name="first"> The first shred staged for comparison </param>
        /// <param name="second"> The other shred staged for comparison </param>
        /// <param name="directionA"> Direction of this shred to be compared </param>
        /// <param name="orientationA"> Orientation of this shred to be compared </param>
        /// <param name="directionB"> Direction of the other shred to be compared </param>
        /// <param name="orientationB"> Orientiation of the other shred to be compared </param>
        /// <returns> Tuple containing the max similarity value and the offset at which that occured </returns>
        public static MatchData CompareShred(Shred first,
                                             Shred second,
                                             Direction directionA,
                                             Orientation orientationA,
                                             Direction directionB,
                                             Orientation orientationB)
        {
            Side sideA = new Side(first, directionA, orientationA);
            Side sideB = new Side(second, directionB, orientationB);
            double penalty = 1.0;

            if (ORIENTATION_PENALTY)
            {
                if (first.TrueOrienation != null && second.TrueOrienation != null)
                {
                    if (!(
                        (first.TrueOrienation == orientationA && second.TrueOrienation == orientationB) ||
                        (first.TrueOrienation == Enumeration.Opposite(orientationA) && second.TrueOrienation == Enumeration.Opposite(orientationB))))
                    {
                        penalty = 0.15;
                    }
                }
            }

            if (NORMALIZATION_ENABLED)
            {
                double max = Chamfer.NormalizedSimilarity(
                    first.GetChamfer(directionA, orientationA),
                    second.GetChamfer(directionB, orientationB));
                double[] scan = new double[1];

                return new MatchData(max*penalty, 0, scan, sideA, sideB);
            }
            else
            {
                double[] scan = Chamfer.ScanSimilarity(
                    first.GetChamfer(directionA, orientationA),
                    second.GetChamfer(directionB, orientationB));

                Tuple<double, int> maxData = Utility.Max(scan);
                double max = maxData.Item1;
                int best = maxData.Item2;
                return new MatchData(max*penalty, best, scan, sideA, sideB);
            }
        }
Beispiel #7
0
        /// <summary>
        ///   IsFit checks if given a specified side, it can be fit with a shreds's edge
        ///   This Also returns a match object
        /// </summary>
        /// <param name="root"> </param>
        /// <param name="shred"> </param>
        /// <param name="side"> </param>
        /// <returns> </returns>
        private static Tuple<Match, Direction> IsFit(INode root, Shred shred, Side side)
        {
            Side query;
            Match match;

            if (side.Orientation != shred.Orientation)
            {
                query = new Side(shred, Enumeration.Opposite(side.Direction), shred.Orientation);
                match = Match.Inverted;
            }
            else
            {
                query = side;
                match = Match.NonInverted;
            }

            // If Directions match AND The Availablility then return match, otherwise impossible
            if (query.Direction == Direction.FromLeft && root.LeftEdge() == shred.LeftEdge())
            {
                return new Tuple<Match, Direction>(match, Direction.FromLeft);
            }
            if (query.Direction == Direction.FromRight && root.RightEdge() == shred.RightEdge())
            {
                return new Tuple<Match, Direction>(match, Direction.FromRight);
            }
            return new Tuple<Match, Direction>(Match.Impossible, Direction.FromLeft);
        }
        public static void DisplayTestShred()
        {
            //Create original Square
            Point[] patch1 = new Point[4];
            patch1[0] = new Point(0, 0);
            patch1[1] = new Point(0, 10);
            patch1[2] = new Point(99, 10);
            patch1[3] = new Point(99, 0);

            Point[] patch2 = new Point[4];
            patch2[0] = new Point(0, 50);
            patch2[1] = new Point(0, 60);
            patch2[2] = new Point(99, 60);
            patch2[3] = new Point(99, 50);

            // Create a Tester Square to compare
            Point[] patch3 = new Point[4];
            patch3[0] = new Point(0, 110);
            patch3[1] = new Point(0, 120);
            patch3[2] = new Point(99, 120);
            patch3[3] = new Point(99, 110);

            Point[] patch4 = new Point[4];
            patch4[0] = new Point(0, 160);
            patch4[1] = new Point(0, 170);
            patch4[2] = new Point(99, 170);
            patch4[3] = new Point(99, 160);

            // Create an Original Image
            var original = new Image<Bgr, Byte>(100, 100, new Bgr(Color.HotPink));
            original.FillConvexPoly(patch1, new Bgr(Color.Gray));
            original.FillConvexPoly(patch2, new Bgr(Color.Gray));

            //Create Image to compare with
            var tester = new Image<Bgr, Byte>(100, 200, new Bgr(Color.HotPink));
            tester.FillConvexPoly(patch3, new Bgr(Color.Gray));
            tester.FillConvexPoly(patch4, new Bgr(Color.Gray));

            //ImageViewer display = new ImageViewer(original, "TestBitmap");
            //display.ShowDialog();
            //ImageViewer display2 = new ImageViewer(tester, "Test Image");
            //display2.ShowDialog();

            const string filepath = "originalshrd.bmp";
            const string filepath2 = "testshred.bmp";

            if (File.Exists(filepath))
            {
                File.Delete(filepath);
            }

            if (File.Exists(filepath2))
            {
                File.Delete(filepath2);
            }
            original.ToBitmap().Save(filepath);
            tester.ToBitmap().Save(filepath2);
            Shred originalshred = new Shred(filepath);
            Shred testershred = new Shred(filepath2);
            originalshred.VisualizeLuminousity(Direction.FromLeft);
            originalshred.VisualizeThresholded(Direction.FromLeft);
            originalshred.VisualizeChamfers(Direction.FromLeft);
            testershred.VisualizeThresholded(Direction.FromLeft);
            testershred.VisualizeLuminousity(Direction.FromLeft);
            testershred.VisualizeChamfers(Direction.FromRight);
        }
Beispiel #9
0
 public Side(Shred shred, Direction direction, Orientation orientation)
 {
     Shred = shred;
     Direction = direction;
     Orientation = orientation;
 }
Beispiel #10
0
 public Edge(Shred shred, Direction direction)
 {
     _shred       = shred;
     _direction   = direction;
     _orientation = shred.Orientation;
 }
Beispiel #11
0
 public static Edge New(Shred shred, Direction direction)
 {
     return(new Edge(shred, direction));
 }
Beispiel #12
0
 public static Edge New(Shred shred, Direction direction)
 {
     return new Edge(shred, direction);
 }
Beispiel #13
0
 public Edge(Shred shred, Direction direction)
 {
     _shred = shred;
     _direction = direction;
     _orientation = shred.Orientation;
 }
Beispiel #14
0
 /// <summary>
 ///   Serialize Shred to binary file on disk
 /// </summary>
 /// <param name="shred"> Shred Object </param>
 /// <param name="filename"> Destination File path </param>
 public static void Save(Shred shred, string filename)
 {
     Logger.Info("Serializing shred id={0} to filename={1}", shred.Id, filename);
     Stream stream = File.Open(filename, FileMode.Create);
     BinaryFormatter binaryFormatter = new BinaryFormatter();
     binaryFormatter.Serialize(stream, shred);
     stream.Flush();
     stream.Close();
 }
Beispiel #15
0
 public Side(Shred shred, Direction direction, Orientation orientation)
 {
     Shred       = shred;
     Direction   = direction;
     Orientation = orientation;
 }