private double EstimateOffset(string logFile, string dirWithImages)
{
if (vehicleLocations == null || vehicleLocations.Count <= 0)
vehicleLocations = readGPSMsgInLog(logFile);
if (vehicleLocations == null || vehicleLocations.Count <= 0)
return -1;
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();
if (files == null || files.Length == 0)
return -1;
Array.Sort(files, Comparer.DefaultInvariant);
// First Photo time
string firstPhoto = files[0];
DateTime photoTime = getPhotoTime(firstPhoto);
TXT_outputlog.AppendText("First Picture " + Path.GetFileNameWithoutExtension(firstPhoto) + " with DateTime: " + photoTime.ToString("yyyy:MM:dd HH:mm:ss") + "\n");
// First GPS Message in Log time
List<long> times = new List<long>(vehicleLocations.Keys);
times.Sort();
long firstTimeInGPSMsg = times[0];
DateTime logTime = FromUTCTimeMilliseconds(firstTimeInGPSMsg);
TXT_outputlog.AppendText("First GPS Log Msg: " + logTime.ToString("yyyy:MM:dd HH:mm:ss") + "\n");
return (double)(photoTime - logTime).TotalSeconds;
}