Skip to content

Commit

Permalink
Merge pull request #1 from arknoll/timestamp
Browse files Browse the repository at this point in the history
Add date to exif data.
  • Loading branch information
arknoll authored Jun 28, 2021
2 parents acf6c27 + 9d63bd5 commit 26f07d5
Show file tree
Hide file tree
Showing 11 changed files with 8,721 additions and 2,424 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ Select the csv file created by PCPainter and the folder containing your camera i

Windows 10 distribution included. However, this can be run with any computer which has python 3.7+ by running:

`pip install Gooey piexif`
`pip install Gooey piexif pyproj gps-time`

`python exifwrite.py`

## Development

conda create --name exifwriter python=3.8.3

pip install Gooey piexif pyinstaller pyproj
pip install Gooey piexif pyinstaller pyproj gps-time

pyinstaller --noconsole --onefile --windowed exifwrite.py
1,032 changes: 719 additions & 313 deletions build/exifwrite/Analysis-00.toc

Large diffs are not rendered by default.

402 changes: 225 additions & 177 deletions build/exifwrite/EXE-00.toc

Large diffs are not rendered by default.

Binary file modified build/exifwrite/PKG-00.pkg
Binary file not shown.
400 changes: 224 additions & 176 deletions build/exifwrite/PKG-00.toc

Large diffs are not rendered by default.

Binary file modified build/exifwrite/PYZ-00.pyz
Binary file not shown.
632 changes: 495 additions & 137 deletions build/exifwrite/PYZ-00.toc

Large diffs are not rendered by default.

104 changes: 94 additions & 10 deletions build/exifwrite/warn-exifwrite.txt

Large diffs are not rendered by default.

8,544 changes: 6,941 additions & 1,603 deletions build/exifwrite/xref-exifwrite.html

Large diffs are not rendered by default.

Binary file modified dist/exifwrite.exe
Binary file not shown.
27 changes: 21 additions & 6 deletions exifwrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from gooey import Gooey
from gooey import GooeyParser
from pyproj import Transformer
from datetime import datetime
from gps_time.core import GPSTime

@Gooey(progress_regex=r"^progress: (?P<current>\d+)/(?P<total>\d+)$",
progress_expr="current / total * 100")
Expand Down Expand Up @@ -79,9 +81,11 @@ def main():
beforeDiff = float(before[1]) - imageStart
afterDiff = imageStart - float(after[1])
if beforeDiff < afterDiff:
set_gps_location(photo, float(before[4]), float(before[3]), float(before[5]))
photo_date = get_photo_date(before[0], before[1])
set_gps_location(photo, float(before[4]), float(before[3]), float(before[5]), photo_date)
else:
set_gps_location(photo, float(after[4]), float(after[3]), float(after[5]))
photo_date = get_photo_date(after[0], after[1])
set_gps_location(photo, float(after[4]), float(after[3]), float(after[5]), photo_date)
photo_num = photo_num + 1
print('progress: ' + str(photo_num) + '/' + str(total_photos))

Expand All @@ -99,12 +103,18 @@ def main():
if os.path.exists(args.base_camera_dir + os.sep + photoname):
photo = args.base_camera_dir + os.sep + photoname
reproject = reproject_point(line[3], line[4], 'epsg:' + line[2])

set_gps_location(photo, float(reproject[1]), float(reproject[0]), float(line[5]))
photo_date = get_photo_date(line[0], line[1])
set_gps_location(photo, float(reproject[1]), float(reproject[0]), float(line[5]), photo_date)

i = i + 1
print('progress: ' + str(i) + '/' + str(total_lines))

def get_photo_date(gpsweek, seconds):
float_val = float(seconds)
int_val = int(float_val)
gps_time = GPSTime(gpsweek, int_val)
return gps_time.to_datetime().strftime("%Y:%m:%d %H:%M:%S")

def reproject_point(x, y, in_crs, out_crs = 'epsg:4326'):
try:
transformer = Transformer.from_crs(in_crs, out_crs, always_xy=True)
Expand Down Expand Up @@ -141,7 +151,7 @@ def change_to_rational(number):
return (f.numerator, f.denominator)


def set_gps_location(file_name, lat, lng, altitude):
def set_gps_location(file_name, lat, lng, altitude, photo_date):
"""Adds GPS position as EXIF metadata
Keyword arguments:
file_name -- image file
Expand All @@ -168,13 +178,18 @@ def set_gps_location(file_name, lat, lng, altitude):
piexif.GPSIFD.GPSLongitude: exiv_lng,
}

gps_exif = {"GPS": gps_ifd}
gps_exif = {
"GPS": gps_ifd
}

# get original exif data first!
exif_data = piexif.load(file_name)

# update original exif data to include GPS tag
exif_data.update(gps_exif)
exif_data["0th"][piexif.ImageIFD.DateTime] = photo_date
exif_data["Exif"][piexif.ExifIFD.DateTimeOriginal] = photo_date
exif_data["Exif"][piexif.ExifIFD.DateTimeDigitized] = photo_date
exif_bytes = piexif.dump(exif_data)

piexif.insert(exif_bytes, file_name)
Expand Down

0 comments on commit 26f07d5

Please sign in to comment.