private void AppendText(string text) { var inv = new MethodInvoker(delegate { TXT_outputlog.AppendText(text); TXT_outputlog.Refresh(); }); this.Invoke(inv); }
private void BUT_estoffset_Click(object sender, EventArgs e) { TXT_outputlog.Clear(); double offset = georef.EstimateOffset(TXT_logfile.Text, TXT_jpgdir.Text, UseGpsorGPS2(), chk_cammsg.Checked, AppendText); AppendText("Offset around : " + offset.ToString(CultureInfo.InvariantCulture) + "\n\n"); }
private void button_getFile_Click(object sender, EventArgs e) { DirectoryInfo di = new DirectoryInfo(TXT_workPath.Text); subDi = di.GetDirectories();//获取子文件夹列表 folderCount = subDi.Count(); //check number of images //set progress bar processedImageCount = 0; imageSum = imageNum * folderCount; progressBar1.Minimum = 0; progressBar1.Maximum = imageSum; foreach (DirectoryInfo s_di in subDi) { if (!checkImageNumbers(s_di, imageNum)) { MessageBox.Show("Improper file numbers in " + s_di.FullName + " ,should be " + imageNum); return; } } //geotag images foreach (DirectoryInfo s_di in subDi) { currentWorkingPath = s_di.FullName; //string geoTagFolder = currentWorkingPath + Path.DirectorySeparatorChar + "geotagged"; currentWorkingFolderName = currentWorkingPath.Substring(currentWorkingPath.LastIndexOf("\\") + 1); //string geoTagFolder = foldPath + Path.DirectorySeparatorChar + "geotagged" + Path.DirectorySeparatorChar + currentWorkingFolderName; string geoTagFolder = foldPath + "_geotagged" + Path.DirectorySeparatorChar + currentWorkingFolderName; bool isExists = System.IO.Directory.Exists(geoTagFolder); // delete old files and folder if (isExists) { Directory.Delete(geoTagFolder, true); } // create it again System.IO.Directory.CreateDirectory(geoTagFolder); FileInfo[] imageFiles = s_di.GetFiles(); for (int i = 0; i < imageFiles.Length; i++) { PosReader.posInfomation pos = mposReader.posInfo[i]; WriteCoordinatesToImage(imageFiles[i].FullName, pos.latitude, pos.longitude, pos.height); processedImageCount++; progressBar1.Value = processedImageCount; } } TXT_outputlog.AppendText("Geotag finished " + "\n"); TXT_outputlog.AppendText("Images saved to " + foldPath + "_geotagged\n"); MessageBox.Show("Geotag finished"); System.Diagnostics.Process.Start("explorer.exe", foldPath + "_geotagged"); }
private void AppendText(string text) { log.Info(text); var inv = new MethodInvoker(delegate { text.Replace("\n", Environment.NewLine); TXT_outputlog.AppendText(text); TXT_outputlog.Refresh(); }); this.BeginInvoke(inv); }
private void BUT_doit_Click(object sender, EventArgs e) { string dirPictures = TXT_jpgdir.Text; string logFilePath = TXT_logfile.Text; if (!File.Exists(logFilePath)) { return; } if (!Directory.Exists(dirPictures)) { return; } float seconds = 0; if (selectedProcessingMode == PROCESSING_MODE.TIME_OFFSET) { if ( float.TryParse(TXT_offsetseconds.Text, NumberStyles.Float, CultureInfo.InvariantCulture, out seconds) == false) { AppendText("Offset number not in correct format. Use . as decimal separator\n"); return; } } BUT_doit.Enabled = false; TXT_outputlog.Clear(); try { switch (selectedProcessingMode) { case PROCESSING_MODE.TIME_OFFSET: georef.picturesInfo = georef.doworkGPSOFFSET(logFilePath, dirPictures, seconds, UseGpsorGPS2(), chk_cammsg.Checked, AppendText); if (georef.picturesInfo != null) { georef.CreateReportFiles(georef.picturesInfo, dirPictures, seconds, (double)num_camerarotation.Value, (double)num_hfov.Value, (double)num_vfov.Value, AppendText, httpGeoRefKML); } break; case PROCESSING_MODE.CAM_MSG: georef.picturesInfo = georef.doworkCAM(logFilePath, dirPictures, UseGpsorGPS2(), AppendText); if (georef.picturesInfo != null) { georef.CreateReportFiles(georef.picturesInfo, dirPictures, seconds, (double)num_camerarotation.Value, (double)num_hfov.Value, (double)num_vfov.Value, AppendText, httpGeoRefKML, chk_camusegpsalt.Checked); } break; case PROCESSING_MODE.TRIG: georef.picturesInfo = georef.doworkTRIG(logFilePath, dirPictures, UseGpsorGPS2(), AppendText); if (georef.picturesInfo != null) { georef.CreateReportFiles(georef.picturesInfo, dirPictures, seconds, (double)num_camerarotation.Value, (double)num_hfov.Value, (double)num_vfov.Value, AppendText, httpGeoRefKML, chk_trigusergpsalt.Checked); } break; } } catch (Exception ex) { AppendText("Error " + ex.ToString()); } GMapRoute route = new GMapRoute("vehicle"); if (georef.vehicleLocations != null) { foreach (var vehicleLocation in georef.vehicleLocations) { route.Points.Add(new PointLatLngAlt(vehicleLocation.Value.Lat, vehicleLocation.Value.Lon, vehicleLocation.Value.AltAMSL)); } } myGMAP1.Overlays[0].Markers.Clear(); if (georef.picturesInfo != null) { foreach (var pictureLocation in georef.picturesInfo) { myGMAP1.Overlays[0].Markers.Add( new GMarkerGoogle(new PointLatLngAlt(pictureLocation.Value.Lat, pictureLocation.Value.Lon, pictureLocation.Value.AltAMSL), GMarkerGoogleType.green) { IsHitTestVisible = true, ToolTipMode = MarkerTooltipMode.OnMouseOver, ToolTipText = Path.GetFileName(pictureLocation.Value.Path) }); } } myGMAP1.Overlays[0].Routes.Clear(); myGMAP1.Overlays[0].Routes.Add(route); myGMAP1.ZoomAndCenterRoutes(myGMAP1.Overlays[0].Id); BUT_doit.Enabled = true; BUT_Geotagimages.Enabled = true; }
private void WriteCoordinatesToImage(string Filename, double dLat, double dLong, double alt) { using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(Filename))) { TXT_outputlog.AppendText("GeoTagging " + Filename + "\n"); Application.DoEvents(); using (Image Pic = Image.FromStream(ms)) { PropertyItem[] pi = Pic.PropertyItems; pi[0].Id = 0x0004; pi[0].Type = 5; pi[0].Len = sizeof(ulong) * 3; pi[0].Value = coordtobytearray(dLong); Pic.SetPropertyItem(pi[0]); pi[0].Id = 0x0002; pi[0].Type = 5; pi[0].Len = sizeof(ulong) * 3; pi[0].Value = coordtobytearray(dLat); Pic.SetPropertyItem(pi[0]); pi[0].Id = 0x0006; pi[0].Type = 5; pi[0].Len = 8; pi[0].Value = new Rational(alt).GetBytes(); Pic.SetPropertyItem(pi[0]); pi[0].Id = 1; pi[0].Len = 2; pi[0].Type = 2; if (dLat < 0) { pi[0].Value = new byte[] { (byte)'S', 0 }; } else { pi[0].Value = new byte[] { (byte)'N', 0 }; } Pic.SetPropertyItem(pi[0]); pi[0].Id = 3; pi[0].Len = 2; pi[0].Type = 2; if (dLong < 0) { pi[0].Value = new byte[] { (byte)'W', 0 }; } else { pi[0].Value = new byte[] { (byte)'E', 0 }; } Pic.SetPropertyItem(pi[0]); // Save file into Geotag folder //string rootFolder = TXT_jpgdir.Text; string geoTagFolder = foldPath + "_geotagged" + Path.DirectorySeparatorChar + currentWorkingFolderName; string outputfilename = geoTagFolder + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(Filename) + "_geotag" + Path.GetExtension(Filename); // Just in case File.Delete(outputfilename); Pic.Save(outputfilename); } } }