Пример #1
0
        public Dictionary<string, PictureInformation> doworkCAM(string logFile, string dirWithImages)
        {
            // Lets start over 
            Dictionary<string, PictureInformation> picturesInformationTemp =
                new Dictionary<string, PictureInformation>();

            TXT_outputlog.AppendText("Using AMSL Altitude " + useAMSLAlt + "\n");

            // If we are required to use AMSL then GPS messages should be used until CAM messages includes AMSL in the coming AC versions
            // Or if the user enter shutter lag and thus we have to look for GPS messages ahead in time
            if (useAMSLAlt || millisShutterLag > 0)
            {
                TXT_outputlog.AppendText("Reading log for GPS Messages in order to get AMSL Altitude\n");
                if (vehicleLocations == null || vehicleLocations.Count <= 0)
                {
                    vehicleLocations = readGPSMsgInLog(logFile);

                    if (vehicleLocations == null || vehicleLocations.Count <= 0)
                    {
                        TXT_outputlog.AppendText("Log file problem. Aborting....\n");
                        return null;
                    }
                }
                TXT_outputlog.AppendText("Log Read for GPS Messages\n");
            }


            //logFile = @"C:\Users\hog\Pictures\farm 1-10-2011\100SSCAM\2011-10-01 11-48 1.log";
            TXT_outputlog.AppendText("Reading log for CAM Messages\n");

            var list = readCAMMsgInLog(logFile);

            if (list == null)
            {
                TXT_outputlog.AppendText("Log file problem. Aborting....\n");
                return null;
            }

            TXT_outputlog.AppendText("Log Read with - " + list.Count + " - CAM Messages found\n");

            //dirWithImages = @"C:\Users\hog\Pictures\farm 1-10-2011\100SSCAM";

            TXT_outputlog.AppendText("Read images\n");

            string[] files = Directory.GetFiles(dirWithImages, "*.jpg");

            TXT_outputlog.AppendText("Images read : " + files.Length + "\n");

            // Check that we have same number of CAMs than files
            if (files.Length != list.Count)
            {
                TXT_outputlog.AppendText("CAM Msgs and Files discrepancy. Check it!\n");
                return null;
            }

            Array.Sort(files, Comparer.DefaultInvariant);

            // Each file corresponds to one CAM message
            // We assume that picture names are in ascending order in time
            int i = -1;
            foreach (var currentCAM in list.Values)
            {
                i++;
                PictureInformation p = new PictureInformation();

                // Fill shot time in Picture
                p.ShotTimeReportedByCamera = getPhotoTime(files[i]);

                DateTime dCAMMsgTime = currentCAM.Time;

                if (millisShutterLag == 0)
                {
                    // Lets puts GPS time
                    p.Time = dCAMMsgTime;

                    p.Lat = currentCAM.Lat;
                    p.Lon = currentCAM.Lon;
                    p.AltAMSL = currentCAM.AltAMSL;
                    p.RelAlt = currentCAM.RelAlt;

                    VehicleLocation cameraLocationFromGPSMsg = null;

                    string logAltMsg = "RelAlt";

                    if (useAMSLAlt)
                    {
                        cameraLocationFromGPSMsg = LookForLocation(p.Time, vehicleLocations);
                        if (cameraLocationFromGPSMsg != null)
                        {
                            logAltMsg = "AMSL Alt " + (cameraLocationFromGPSMsg.Time - p.Time).Milliseconds + " ms away" +
                                        " offset: " + (p.ShotTimeReportedByCamera - dCAMMsgTime).TotalSeconds;
                            p.AltAMSL = cameraLocationFromGPSMsg.AltAMSL;
                        }
                        else
                            logAltMsg = "AMSL Alt NOT found";
                    }


                    p.Pitch = currentCAM.Pitch;
                    p.Roll = currentCAM.Roll;
                    p.Yaw = currentCAM.Yaw;

                    p.Path = files[i];

                    string picturePath = files[i];

                    picturesInformationTemp.Add(picturePath, p);

                    TXT_outputlog.AppendText("Photo " + Path.GetFileNameWithoutExtension(picturePath) +
                                             " processed from CAM Msg with " + millisShutterLag + " ms shutter lag. " +
                                             logAltMsg + "\n");
                }
                else
                {
                    // Look fot GPS Message ahead
                    DateTime dCorrectedWithLagPhotoTime = dCAMMsgTime;
                    dCorrectedWithLagPhotoTime = dCorrectedWithLagPhotoTime.AddMilliseconds(millisShutterLag);

                    VehicleLocation cameraLocationFromGPSMsg = LookForLocation(dCorrectedWithLagPhotoTime,
                        vehicleLocations);

                    // Check which GPS Position is closer in time.
                    if (cameraLocationFromGPSMsg != null)
                    {
                        System.TimeSpan diffGPSTimeCAMTime = cameraLocationFromGPSMsg.Time - dCAMMsgTime;

                        if (diffGPSTimeCAMTime.Milliseconds > 2*millisShutterLag)
                        {
                            // Stay with CAM Message as it is closer to CorrectedTime
                            p.Time = dCAMMsgTime;

                            p.Lat = currentCAM.Lat;
                            p.Lon = currentCAM.Lon;
                            p.AltAMSL = currentCAM.AltAMSL;
                            p.RelAlt = currentCAM.RelAlt;

                            string logAltMsg = "RelAlt";

                            cameraLocationFromGPSMsg = null;
                            if (useAMSLAlt)
                            {
                                cameraLocationFromGPSMsg = LookForLocation(p.Time, vehicleLocations);
                                if (cameraLocationFromGPSMsg != null)
                                {
                                    logAltMsg = "AMSL Alt " + (cameraLocationFromGPSMsg.Time - p.Time).Milliseconds +
                                                " ms away";
                                    p.AltAMSL = cameraLocationFromGPSMsg.AltAMSL;
                                }
                                else
                                    logAltMsg = "AMSL Alt NOT found";
                            }


                            TXT_outputlog.AppendText("Photo " + Path.GetFileNameWithoutExtension(files[i]) +
                                                     " processed with CAM Msg. Shutter lag too small. " + logAltMsg +
                                                     "\n");
                        }
                        else
                        {
                            // Get GPS Time as it is closer to CorrectedTime
                            // Lets puts GPS time
                            p.Time = cameraLocationFromGPSMsg.Time;

                            p.Lat = cameraLocationFromGPSMsg.Lat;
                            p.Lon = cameraLocationFromGPSMsg.Lon;
                            p.AltAMSL = cameraLocationFromGPSMsg.AltAMSL;
                            p.RelAlt = cameraLocationFromGPSMsg.RelAlt;

                            string logAltMsg = useAMSLAlt ? "AMSL Alt" : "RelAlt";

                            TXT_outputlog.AppendText("Photo " + Path.GetFileNameWithoutExtension(files[i]) +
                                                     " processed with GPS Msg : " + diffGPSTimeCAMTime.Milliseconds +
                                                     " ms ahead of CAM Msg. " + logAltMsg + "\n");
                        }

                        p.Pitch = currentCAM.Pitch;
                        p.Roll = currentCAM.Roll;
                        p.Yaw = currentCAM.Yaw;

                        p.Path = files[i];

                        string picturePath = files[i];

                        picturesInformationTemp.Add(picturePath, p);
                    }
                    else
                    {
                        TXT_outputlog.AppendText("Photo " + Path.GetFileNameWithoutExtension(files[i]) +
                                                 " NOT Processed. Time not found in log. Too large Shutter Lag? Try setting it to 0\n");
                    }
                }
            }

            return picturesInformationTemp;
        }
Пример #2
0
        private Dictionary<string, PictureInformation> doworkTRIG(string logFile, string dirWithImages)
        {
            // Lets start over 
            Dictionary<string, PictureInformation> picturesInformationTemp =
                new Dictionary<string, PictureInformation>();

            TXT_outputlog.AppendText("Using AMSL Altitude " + useAMSLAlt + "\n");

            TXT_outputlog.AppendText("Reading log for TRIG Messages\n");

            vehicleLocations = readTRIGMsgInLog(logFile);

            if (vehicleLocations == null)
            {
                TXT_outputlog.AppendText("Log file problem. No TRIG messages. Aborting....\n");
                return null;
            }

            TXT_outputlog.AppendText("Log Read with - " + vehicleLocations.Count + " - TRIG Messages found\n");

            TXT_outputlog.AppendText("Read images\n");

            string[] files = Directory.GetFiles(dirWithImages, "*.jpg");

            TXT_outputlog.AppendText("Images read : " + files.Length + "\n");

            // Check that we have same number of CAMs than files
            if (files.Length != vehicleLocations.Count)
            {
                TXT_outputlog.AppendText(string.Format("TRIG Msgs and Files discrepancy. Check it! files: {0} vs TRIG msg: {1}\n", files.Length, vehicleLocations.Count));
                return null;
            }

            Array.Sort(files, compareFileByPhotoTime);

            // Each file corresponds to one CAM message
            // We assume that picture names are in ascending order in time
            int i = -1;
            foreach (var currentTRIG in vehicleLocations.Values)
            {
                i++;
                PictureInformation p = new PictureInformation();

                // Fill shot time in Picture
                p.ShotTimeReportedByCamera = getPhotoTime(files[i]);

                DateTime dCAMMsgTime = currentTRIG.Time;

                // Lets puts GPS time
                p.Time = dCAMMsgTime;

                p.Lat = currentTRIG.Lat;
                p.Lon = currentTRIG.Lon;
                p.AltAMSL = currentTRIG.AltAMSL;
                p.RelAlt = currentTRIG.RelAlt;


                p.Pitch = currentTRIG.Pitch;
                p.Roll = currentTRIG.Roll;
                p.Yaw = currentTRIG.Yaw;

                p.SAlt = currentTRIG.SAlt;

                p.Path = files[i];

                string picturePath = files[i];

                picturesInformationTemp.Add(picturePath, p);

                TXT_outputlog.AppendText("Photo " + Path.GetFileNameWithoutExtension(picturePath) +
                                         " processed from CAM Msg with " + millisShutterLag + " ms shutter lag. " +
                                         "\n");

            }

            return picturesInformationTemp;
        }
Пример #3
0
        public Dictionary<string, PictureInformation> doworkGPSOFFSET(string logFile, string dirWithImages, float offset)
        {
            // Lets start over 
            Dictionary<string, PictureInformation> picturesInformationTemp =
                new Dictionary<string, PictureInformation>();

            // Read Vehicle Locations from log. GPS Messages. Will have to do it anyway
            if (vehicleLocations == null || vehicleLocations.Count <= 0)
            {
                if (chk_cammsg.Checked)
                {
                    TXT_outputlog.AppendText("Reading log for CAM Messages\n");

                    vehicleLocations = readCAMMsgInLog(logFile);
                }
                else
                {
                    TXT_outputlog.AppendText("Reading log for GPS-ATT Messages\n");

                    vehicleLocations = readGPSMsgInLog(logFile);
                }
            }

            if (vehicleLocations == null)
            {
                TXT_outputlog.AppendText("Log file problem. Aborting....\n");
                return null;
            }

            TXT_outputlog.AppendText("Read images\n");

            List<string> filelist = new List<string>();
            string[] exts = PHOTO_FILES_FILTER.Split(';');
            foreach (var ext in exts)
            {
                filelist.AddRange(Directory.GetFiles(dirWithImages, ext));
            }

            string[] files = filelist.ToArray();

            TXT_outputlog.AppendText("Images read : " + files.Length + "\n");

            // Check that we have at least one picture
            if (files.Length <= 0)
            {
                TXT_outputlog.AppendText("Not enought files found.  Aborting..... \n");
                return null;
            }

            Array.Sort(files, Comparer.DefaultInvariant);

            // Each file corresponds to one CAM message
            // We assume that picture names are in ascending order in time
            for (int i = 0; i < files.Length; i++)
            {
                string filename = files[i];

                PictureInformation p = new PictureInformation();

                // Fill shot time in Picture
                p.ShotTimeReportedByCamera = getPhotoTime(filename);

                // Lookfor corresponding Location in vehicleLocationList
                DateTime correctedTime = p.ShotTimeReportedByCamera.AddSeconds(-offset);
                VehicleLocation shotLocation = LookForLocation(correctedTime, vehicleLocations, 5000);

                if (shotLocation == null)
                {
                    TXT_outputlog.AppendText("Photo " + Path.GetFileNameWithoutExtension(filename) +
                                             " NOT PROCESSED. No GPS match in the log file. Please take care\n");
                }
                else
                {
                    p.Lat = shotLocation.Lat;
                    p.Lon = shotLocation.Lon;
                    p.AltAMSL = shotLocation.AltAMSL;

                    p.RelAlt = shotLocation.RelAlt;

                    p.Pitch = shotLocation.Pitch;
                    p.Roll = shotLocation.Roll;
                    p.Yaw = shotLocation.Yaw;

                    p.Time = shotLocation.Time;

                    p.Path = filename;


                    picturesInformationTemp.Add(filename, p);

                    TXT_outputlog.AppendText("Photo " + Path.GetFileNameWithoutExtension(filename) +
                                             " PROCESSED with GPS position found " +
                                             (shotLocation.Time - correctedTime).Milliseconds + " ms away\n");
                }
            }

            return picturesInformationTemp;
        }
Пример #4
0
        public Dictionary<string, PictureInformation> doworkCAMOFFSET(string logFile, string dirWithImages)
        {
            // Lets start over 
            Dictionary<string, PictureInformation> picturesInformationTemp =
                new Dictionary<string, PictureInformation>();

            Dictionary<long, VehicleLocation> gpsvehicleLocations = null;

            TXT_outputlog.AppendText("Reading log for CAM Messages\n");
            vehicleLocations = readCAMMsgInLog(logFile);
            if (millisShutterLag != 0)
            {
                gpsvehicleLocations = readGPSMsgInLog(logFile);
            }

            TXT_outputlog.AppendText("Read images\n");

            List<string> filelist = new List<string>();
            string[] exts = PHOTO_FILES_FILTER.Split(';');
            foreach (var ext in exts)
            {
                filelist.AddRange(Directory.GetFiles(dirWithImages, ext));
            }

            string[] files = filelist.ToArray();
            TXT_outputlog.AppendText("Images read : " + files.Length + "\n");

            // Check that we have at least one picture
            if (files.Length <= 0)
            {
                TXT_outputlog.AppendText("Not enought files found.  Aborting..... \n");
                return null;
            }
            Array.Sort(files, Comparer.DefaultInvariant);

            // store all photos time
            TXT_outputlog.AppendText("Storing photos time.....\n");
            List<DateTime> photosTimes = new List<DateTime>();
            DateTime time;
            for (int i = 0; i < files.Length; i++)
            {
                time = getPhotoTime(files[i]);
                photosTimes.Add(time);
                //TXT_outputlog.AppendText("Img " + filename + ": " + ToMilliseconds(time) + "\n");
            }


            // estimate best CAM offset within 1sec across correctedTime
            double offset = 0;
            double bestOffset = 0;
            double score = 0;
            double bestScore = 0;
            int nbrPhotos = 0;
            int bestNbrPhotos = 0;
            VehicleLocation shotLocation = null;
            List<long> vecs = new List<long>(vehicleLocations.Keys);
            vecs.Sort();

            offset = (photosTimes[0] - FromUTCTimeMilliseconds(vecs[0])).TotalSeconds;
            for (double essai = offset - 1; essai <= offset + 1; essai += 0.2)
            {
                nbrPhotos = 0;
                score = 0;

                foreach (DateTime dt in photosTimes)
                {
                    //TXT_outputlog.AppendText("Debug : " + dt.ToShortTimeString() + "  " + essai.ToString());
                    DateTime correctedTime = dt.AddSeconds(-essai);
                    shotLocation = LookForClosestLocation(correctedTime, vehicleLocations, 1000);
                    if (shotLocation != null)
                    {
                        score += Math.Pow((correctedTime - shotLocation.Time).TotalSeconds, 2);
                        nbrPhotos++;
                    }

                }
                if (nbrPhotos != 0) score = score / nbrPhotos;
                TXT_outputlog.AppendText("offset " + essai + " ; Score :" + score + " ; Nbr Photo : " + nbrPhotos + "\n");

                // result
                if (nbrPhotos > bestNbrPhotos)
                {
                    bestNbrPhotos = nbrPhotos;
                    bestScore = score;
                    bestOffset = essai;
                }
                else if (nbrPhotos == bestNbrPhotos)
                {
                    if (Math.Abs(score) < Math.Abs(bestScore))
                    {
                        bestScore = score;
                        bestOffset = essai;
                    }
                }
            }
            offset = bestOffset;
            TXT_outputlog.AppendText("Best offset :" + offset + "....\n");


            // We assume that picture names are in ascending order in time
            for (int i = 0; i < files.Length; i++)
            {
                string filename = files[i];
                PictureInformation p = new PictureInformation();

                // Fill shot time in Picture
                p.ShotTimeReportedByCamera = photosTimes[i];
                DateTime correctedTime = p.ShotTimeReportedByCamera.AddSeconds(-offset);

                // Lookfor corresponding Location in vehicleLocationList
                // Look for the closest CAM msg. That could be an already used CAM msg, as pictures's precision is @1seconde and CAM/GPS msg precision is @200millisec
                // shutter lag offset ?
                if (millisShutterLag == 0)
                {
                    shotLocation = LookForClosestLocation(correctedTime, vehicleLocations, 2000);
                }
                else
                {
                    shotLocation = LookForClosestLocation(correctedTime.AddMilliseconds(millisShutterLag), gpsvehicleLocations, 2000);
                }


                if (shotLocation == null)
                {
                    TXT_outputlog.AppendText("Photo " + Path.GetFileNameWithoutExtension(filename) +
                                             " NOT PROCESSED. No CAM match in the log file. Please take care\n");
                }
                else
                {
                    p.Lat = shotLocation.Lat;
                    p.Lon = shotLocation.Lon;
                    p.AltAMSL = shotLocation.AltAMSL;
                    p.RelAlt = shotLocation.RelAlt;
                    p.Pitch = shotLocation.Pitch;
                    p.Roll = shotLocation.Roll;
                    p.Yaw = shotLocation.Yaw;
                    p.Time = shotLocation.Time;
                    p.Path = filename;
                    picturesInformationTemp.Add(filename, p);
                    if (millisShutterLag == 0)
                    {
                        TXT_outputlog.AppendText("Photo " + Path.GetFileNameWithoutExtension(filename) +
                                             " PROCESSED with CAM position found " +
                                             (shotLocation.Time - correctedTime).Milliseconds + " ms away\n");
                    }
                    else
                    {
                        TXT_outputlog.AppendText("Photo " + Path.GetFileNameWithoutExtension(filename) +
                                             " PROCESSED with GPS position found " +
                                             (shotLocation.Time - correctedTime).Milliseconds + " ms away\n");
                    }

                }

            }


            return picturesInformationTemp;
        }