Пример #1
0
        public void TestThreeViewsCorrespondences()
        {
            MKeyPoint[] kps1 = new MKeyPoint[]
            {
                new MKeyPoint()
                {
                    Point = new PointF(0, 0)
                },
                new MKeyPoint()
                {
                    Point = new PointF(5, 2)
                },
                new MKeyPoint()
                {
                    Point = new PointF(5, 7)
                },
                new MKeyPoint()
                {
                    Point = new PointF(2, 1)
                },
                new MKeyPoint()
                {
                    Point = new PointF(-4, 2)
                },
            };

            MKeyPoint[] kps2a = new MKeyPoint[]
            {
                new MKeyPoint()
                {
                    Point = new PointF(0, 2)
                },
                new MKeyPoint()
                {
                    Point = new PointF(9, 0)
                },
                new MKeyPoint()
                {
                    Point = new PointF(9, -4)
                },
                new MKeyPoint()
                {
                    Point = new PointF(6, 1)
                },
                new MKeyPoint()
                {
                    Point = new PointF(-3, -3)
                },
            };

            MKeyPoint[] kps2b = new MKeyPoint[]
            {
                new MKeyPoint()
                {
                    Point = new PointF(0, 2)
                },
                new MKeyPoint()
                {
                    Point = new PointF(9, 0)
                },
                new MKeyPoint()
                {
                    Point = new PointF(9, -4)
                },
                new MKeyPoint()
                {
                    Point = new PointF(6, 1)
                },
                new MKeyPoint()
                {
                    Point = new PointF(-3, -3)
                },
            };

            MKeyPoint[] kps3 = new MKeyPoint[]
            {
                new MKeyPoint()
                {
                    Point = new PointF(0, 4)
                },
                new MKeyPoint()
                {
                    Point = new PointF(11, 2)
                },
                new MKeyPoint()
                {
                    Point = new PointF(11, -6)
                },
                new MKeyPoint()
                {
                    Point = new PointF(8, 1)
                },
                new MKeyPoint()
                {
                    Point = new PointF(-7, 0)
                },
            };

            MDMatch[] matches12 = new MDMatch[4]
            {
                new MDMatch {
                    QueryIdx = 1, TrainIdx = 0
                },
                new MDMatch {
                    QueryIdx = 0, TrainIdx = 3
                },
                new MDMatch {
                    QueryIdx = 2, TrainIdx = 1
                },
                new MDMatch {
                    QueryIdx = 4, TrainIdx = 2
                },
            };

            MDMatch[] matches23 = new MDMatch[4]
            {
                new MDMatch {
                    QueryIdx = 0, TrainIdx = 4
                },
                new MDMatch {
                    QueryIdx = 1, TrainIdx = 2
                },
                new MDMatch {
                    QueryIdx = 4, TrainIdx = 0
                },
                new MDMatch {
                    QueryIdx = 2, TrainIdx = 1
                },
            };

            MatchingResult match12 = new MatchingResult()
            {
                LeftKps  = kps1,
                RightKps = kps2a,
                Matches  = new Emgu.CV.Util.VectorOfDMatch(matches12)
            };
            MatchingResult match23 = new MatchingResult()
            {
                LeftKps  = kps2b,
                RightKps = kps3,
                Matches  = new Emgu.CV.Util.VectorOfDMatch(matches23)
            };

            List <Correspondences.MatchPair> correspondences = Correspondences.FindCorrespondences12to23(match12, match23);

            Assert.AreEqual(3, correspondences.Count);
            // They are sorted same as matches23
            var c = correspondences[0];

            Assert.AreEqual(1, c.Match12.QueryIdx);
            Assert.AreEqual(0, c.Match12.TrainIdx);
            Assert.AreEqual(0, c.Match23.QueryIdx);
            Assert.AreEqual(4, c.Match23.TrainIdx);

            Assert.AreEqual(kps1[1].Point, c.Kp1.Point);
            Assert.AreEqual(kps2a[0].Point, c.Kp2.Point);
            Assert.AreEqual(kps3[4].Point, c.Kp3.Point);

            c = correspondences[1];
            Assert.AreEqual(2, c.Match12.QueryIdx);
            Assert.AreEqual(1, c.Match12.TrainIdx);
            Assert.AreEqual(1, c.Match23.QueryIdx);
            Assert.AreEqual(2, c.Match23.TrainIdx);

            c = correspondences[2];
            Assert.AreEqual(4, c.Match12.QueryIdx);
            Assert.AreEqual(2, c.Match12.TrainIdx);
            Assert.AreEqual(2, c.Match23.QueryIdx);
            Assert.AreEqual(1, c.Match23.TrainIdx);
        }
Пример #2
0
        /// <summary>
        /// Start of console application specific logic.
        /// </summary>
        protected override void Execute()
        {
            // This is where magic happens

            // Fetch datasett fra en kommaseparert fil, der hver linje er en correspondence
            DatasourceReader reader = new DatasourceReader(this.Arguments.SourceFile);

            reader.ReadFile();

            Correspondences corrColl = new Correspondences()
            {
                SystemUserCode    = ConfigurationManager.AppSettings["systemUserCode"],
                ShipmentReference = Guid.NewGuid().ToString(),
                SequenceNo        = null,
                Correspondence    = new CorrespondencesCorrespondence[reader.Count]
            };

            int index = 0;

            // For datasettet lages en XML fil med alle correspence fra csv fila
            // systemUserCode hentes fra app.config
            foreach (CorrespondenceInput correspondence in reader.GetEnumerable())
            {
                corrColl.Correspondence[index++] = new CorrespondencesCorrespondence()
                {
                    Reportee         = correspondence.Reportee,
                    ServiceCode      = this.Arguments.ServiceCode,
                    ServiceEdition   = this.Arguments.ServiceEdition,
                    SendersReference = Guid.NewGuid().ToString(),
                    Content          = new CorrespondencesCorrespondenceContent()
                    {
                        LanguageCode   = correspondence.LanguageCode,
                        MessageTitle   = correspondence.MessageTitle,
                        MessageBody    = correspondence.MessageBody,
                        MessageSummary = correspondence.MessageSummary,
                    },
                    VisibleDateTime          = correspondence.VisibleDateTime,
                    VisibleDateTimeSpecified = true,
                    IsReservable             = correspondence.IsReservable,
                    IsReservableSpecified    = true,
                };
            }

            string destfolder = ConfigurationManager.AppSettings["localPathToFilesToUpload"];
            string name       = Path.GetFileName(this.Arguments.SourceFile);

            if (name == null)
            {
                return;
            }

            string fileName = name.Replace(".csv", ".xml");
            string destfile = destfolder.Contains("*")
                ? destfolder.Replace("*", fileName)
                : Path.Combine(destfolder, fileName);

            // XML filene lagres på local path ihht konfigurasjonen localPathToFilesToUpload
            using (FileStream fileStream = File.Create(destfile))
            {
                XmlSerializer serializer = new XmlSerializer(corrColl.GetType());
                serializer.Serialize(fileStream, corrColl);
            }

            XmlValidator.Validate(destfile);

            try
            {
                SftpClientHelper.TransferFiles();
                File.Delete(destfile);
            }
            catch (Exception)
            {
                throw;
            }
        }