예제 #1
0
        public void PrimitiveTest()
        {
            var shreds = Helpers.BootstrapPrimitiveThree();
            // 3 Shreds
            var a = shreds[0];
            var b = shreds[1];
            var c = shreds[2];

            var dataAB = MatchData.CompareShred(a, b,
                                                Direction.FromRight,
                                                Orientation.Regular,
                                                Direction.FromLeft,
                                                Orientation.Regular);
            var dataBA = MatchData.CompareShred(a, b,
                                                Direction.FromLeft,
                                                Orientation.Regular,
                                                Direction.FromRight,
                                                Orientation.Regular);

            Assert.IsTrue(dataAB.ChamferSimilarity > dataBA.ChamferSimilarity);

            var dataBC = MatchData.CompareShred(b, c,
                                                Direction.FromRight,
                                                Orientation.Regular,
                                                Direction.FromLeft,
                                                Orientation.Regular);

            var dataCB = MatchData.CompareShred(b, c,
                                                Direction.FromLeft,
                                                Orientation.Regular,
                                                Direction.FromRight,
                                                Orientation.Regular);

            Assert.IsTrue(dataBC.ChamferSimilarity > dataCB.ChamferSimilarity);

            var dataAC = MatchData.CompareShred(a, c,
                                                Direction.FromRight,
                                                Orientation.Regular,
                                                Direction.FromLeft,
                                                Orientation.Regular);

            Assert.IsTrue(dataBC.ChamferSimilarity > dataAC.ChamferSimilarity);
        }
예제 #2
0
        public static PriorityQueue <MatchData, double> BuildQueue(List <Shred> shreds)
        {
            PriorityQueue <MatchData, double> queue = new PriorityQueue <MatchData, double>(PriorityQueueType.Maximum);

            foreach (Shred shred in shreds)
            {
                foreach (Shred other in shreds)
                {
                    if (shred.Id == other.Id)
                    {
                        continue;
                    }

                    MatchData matchDataForwardsRegular = MatchData.CompareShred(shred, other,
                                                                                Direction.FromRight,
                                                                                Orientation.Regular,
                                                                                Direction.FromLeft,
                                                                                Orientation.Regular);
                    MatchData matchDataBackwardsRegular = MatchData.CompareShred(shred, other,
                                                                                 Direction.FromLeft,
                                                                                 Orientation.Regular,
                                                                                 Direction.FromRight,
                                                                                 Orientation.Regular);
                    MatchData matchDataForwardsReverse = MatchData.CompareShred(shred, other,
                                                                                Direction.FromRight,
                                                                                Orientation.Reversed,
                                                                                Direction.FromLeft,
                                                                                Orientation.Regular);
                    MatchData matchDataBackwardsReverse = MatchData.CompareShred(shred, other,
                                                                                 Direction.FromLeft,
                                                                                 Orientation.Reversed,
                                                                                 Direction.FromRight,
                                                                                 Orientation.Regular);

                    queue.Enqueue(matchDataForwardsRegular, matchDataForwardsRegular.ChamferSimilarity);
                    queue.Enqueue(matchDataBackwardsRegular, matchDataBackwardsRegular.ChamferSimilarity);
                    queue.Enqueue(matchDataForwardsReverse, matchDataForwardsReverse.ChamferSimilarity);
                    queue.Enqueue(matchDataBackwardsReverse, matchDataBackwardsReverse.ChamferSimilarity);
                }
            }
            return(queue);
        }
예제 #3
0
        public void DataMatchTest()
        {
            var shreds = Helpers.InitializeShreds();

            var a = shreds[0];
            var b = shreds[1];
            var c = shreds[2];
            var d = shreds[3];
            var e = shreds[4];

            // Merge A-B
            var abData = MatchData.CompareShred(a, b,
                                                Direction.FromRight,
                                                Orientation.Regular,
                                                Direction.FromLeft,
                                                Orientation.Regular);

            var cluster1 = MatchData.ClusterNodes(abData);

            Assert.IsNotNull(cluster1);
            Assert.IsTrue(cluster1.Right() == b);
            Assert.IsTrue(cluster1.Left() == a);
            Assert.IsTrue(a.Orientation == Orientation.Regular);
            Assert.IsTrue(b.Orientation == Orientation.Regular);
            Helpers.PrintFlatTree(cluster1);

            // Merge D'-C' should flip to a C-D merge
            var cdData = MatchData.CompareShred(c, d,
                                                Direction.FromLeft,
                                                Orientation.Reversed,
                                                Direction.FromRight,
                                                Orientation.Reversed);

            var cluster2 = MatchData.ClusterNodes(cdData);

            Assert.IsNotNull(cluster2);
            Assert.IsTrue(cluster2.Right() == d);
            Assert.IsTrue(cluster2.Left() == c);
            Assert.IsTrue(c.Orientation == Orientation.Regular);
            Assert.IsTrue(d.Orientation == Orientation.Regular);
            Helpers.PrintFlatTree(cluster2);

            // Merge with (A-B)-E by NonInverted
            var beData = MatchData.CompareShred(b, e,
                                                Direction.FromLeft,
                                                Orientation.Reversed,
                                                Direction.FromRight,
                                                Orientation.Reversed);
            var cluster3 = MatchData.ClusterNodes(beData);

            Assert.IsNotNull(cluster3);
            Assert.IsTrue(cluster3.Right() == e);
            Assert.IsTrue(cluster3.Left() == cluster1);
            Assert.IsTrue(a.Orientation == Orientation.Regular);
            Assert.IsTrue(b.Orientation == Orientation.Regular);
            Assert.IsTrue(e.Orientation == Orientation.Regular);
            Helpers.PrintFlatTree(cluster3);

            // (C-D)->(D'-C') and merge C and A essentially (D'-C')-((A-B)-E)
            var caData = MatchData.CompareShred(c, a,
                                                Direction.FromRight,
                                                Orientation.Reversed,
                                                Direction.FromLeft,
                                                Orientation.Regular);
            var cluster4 = MatchData.ClusterNodes(caData);

            Assert.IsNotNull(cluster4);
            Assert.IsTrue(cluster4.Size() == 5);
            Assert.IsTrue(cluster4.Right() == cluster3);
            Assert.IsTrue(cluster4.Left() == cluster2);
            Assert.IsTrue(c.Orientation == Orientation.Reversed);
            Assert.IsTrue(d.Orientation == Orientation.Reversed);
            Assert.IsTrue(a.Orientation == Orientation.Regular);
            Assert.IsTrue(b.Orientation == Orientation.Regular);
            Assert.IsTrue(e.Orientation == Orientation.Regular);
            Helpers.PrintFlatTree(cluster4);

            // Ensure it Flattens correctly;
            var actual = new List <Shred>(cluster4.Size());

            cluster4.Flatten(actual);

            var expected = new List <Shred>(5);

            expected.Add(d);
            expected.Add(c);
            expected.Add(a);
            expected.Add(b);
            expected.Add(e);

            Assert.IsTrue(actual.Zip(expected, (aa, ee) => aa.Id == ee.Id).All(item => item));
        }
예제 #4
0
        public void ShredChamferSimilarityTest()
        {
            //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, 100);
            patch3[1] = new Point(0, 110);
            patch3[2] = new Point(99, 110);
            patch3[3] = new Point(99, 100);

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

            // 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));

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

            // Delete Shred Files
            if (File.Exists(filepath))
            {
                File.Delete(filepath);
            }

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

            // Save bitmaps to load as shreds
            original.ToBitmap().Save(filepath);
            tester.ToBitmap().Save(filepath2);

            // Create new shreds
            Shred originalshred = new Shred(filepath);
            Shred testershred   = new Shred(filepath2);

            // Run Similarity test
            var actual = MatchData.CompareShred(
                originalshred,
                testershred,
                Direction.FromLeft,
                Orientation.Regular,
                Direction.FromRight,
                Orientation.Regular
                ).Offset;

            const int expected = 100;

            Assert.IsTrue(actual == expected);
        }