Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include gps metadata to extracted image #920

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
act better without gps data
  • Loading branch information
Charles Ellison authored and steven.l.bunkley committed Nov 3, 2022
commit 2060e578760e9ee44d53a98f8f6111885a248736
73 changes: 40 additions & 33 deletions guilib/src/DatabaseViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1479,8 1479,13 @@ void DatabaseViewer::extractImages()
progressDialog->show();

// Determine source of gps info for images
std::string graphSource = DatabaseViewer::selectGraph();
std::map<int, GPS> gpsValues = graphToGPS(graphSource);
std::string gpsSource = "None";
std::map<int, GPS> gpsValues;
if(!gpsPoses_.empty())
{
gpsSource = DatabaseViewer::selectGraph();
gpsValues = graphToGPS(gpsSource);
}

int imagesExported = 0;
for(int i=0; i<ids_.size(); i)
Expand Down Expand Up @@ -1535,39 1540,41 @@ void DatabaseViewer::extractImages()
id = QString::number(stamp, 'f');
}

gps = gpsValues[ids_.at(i)];

//fill out image metadata
std::time_t time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::time_point(std::chrono::duration_cast<std::chrono::seconds>(std::chrono::duration<double>(gps.stamp()))));
std::tm timestamp = *std::localtime(&time);
char datebuf[20] = { 0 };
std::strftime(datebuf, sizeof(datebuf), "%Y:%m:%d:%H:%M:%S", &timestamp);
std::string dateString(datebuf);

double latitude = gps.latitude();
double longitude = gps.longitude();
double altitude = gps.altitude();
exifData["Exif.Image.ProcessingSoftware"] = "RTABMAP";

writeExiv2Data(exifData, "EExif.GPSInfo.GPSMapDatum", "WGS-84");
writeExiv2Data(exifData, "Exif.GPSInfo.GPSDateStamp", dateString);
writeExiv2Data(exifData, "Exif.GPSInfo.GPSTimeStamp", toExifTimeStamp(dateString));
writeExiv2Data(exifData, "Exif.GPSInfo.GPSLatitude", toExifLatLonString(latitude));
writeExiv2Data(exifData, "Exif.GPSInfo.GPSLongitude", toExifLatLonString(longitude));
writeExiv2Data(exifData, "Exif.GPSInfo.GPSAltitude", toExifString(altitude));
writeExiv2Data(exifData, "Exif.GPSInfo.GPSLatitudeRef", (latitude<0 ? "S" : "N"));
writeExiv2Data(exifData, "Exif.GPSInfo.GPSLongitudeRef", (longitude<0 ? "W" : "E"));
writeExiv2Data(exifData, "Exif.GPSInfo.GPSAltitudeRef", (altitude < 0.0 ? "1" : "0"));

writeExiv2Data(exifData, "Exif.GPSInfo.GPSImgDirectionRef", "T");

float x,y,z,roll,pitch,yaw;
p.getTranslationAndEulerAngles(x,y,z,roll, pitch,yaw);
float bearing = (yaw/3.1416*180.0) 180.0;
if (bearing > 90) bearing -= 90.0;
else bearing = 270.0;
writeExiv2Data(exifData, "Exif.GPSInfo.GPSImgDirection", toExifString(bearing));

if(!(gpsSource == "None"))
{
gps = gpsValues[ids_.at(i)];

std::time_t time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::time_point(std::chrono::duration_cast<std::chrono::seconds>(std::chrono::duration<double>(gps.stamp()))));
std::tm timestamp = *std::localtime(&time);
char datebuf[20] = { 0 };
std::strftime(datebuf, sizeof(datebuf), "%Y:%m:%d:%H:%M:%S", &timestamp);
std::string dateString(datebuf);

double latitude = gps.latitude();
double longitude = gps.longitude();
double altitude = gps.altitude();

writeExiv2Data(exifData, "EExif.GPSInfo.GPSMapDatum", "WGS-84");
writeExiv2Data(exifData, "Exif.GPSInfo.GPSDateStamp", dateString);
writeExiv2Data(exifData, "Exif.GPSInfo.GPSTimeStamp", toExifTimeStamp(dateString));
writeExiv2Data(exifData, "Exif.GPSInfo.GPSLatitude", toExifLatLonString(latitude));
writeExiv2Data(exifData, "Exif.GPSInfo.GPSLongitude", toExifLatLonString(longitude));
writeExiv2Data(exifData, "Exif.GPSInfo.GPSAltitude", toExifString(altitude));
writeExiv2Data(exifData, "Exif.GPSInfo.GPSLatitudeRef", (latitude<0 ? "S" : "N"));
writeExiv2Data(exifData, "Exif.GPSInfo.GPSLongitudeRef", (longitude<0 ? "W" : "E"));
writeExiv2Data(exifData, "Exif.GPSInfo.GPSAltitudeRef", (altitude < 0.0 ? "1" : "0"));

writeExiv2Data(exifData, "Exif.GPSInfo.GPSImgDirectionRef", "T");

float x,y,z,roll,pitch,yaw;
p.getTranslationAndEulerAngles(x,y,z,roll, pitch,yaw);
float bearing = (yaw/3.1416*180.0) 180.0;
if (bearing > 90) bearing -= 90.0;
else bearing = 270.0;
writeExiv2Data(exifData, "Exif.GPSInfo.GPSImgDirection", toExifString(bearing));
}
}

if(!data.imageRaw().empty())
Expand Down