-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregenerate_direction.py
72 lines (54 loc) · 2.73 KB
/
regenerate_direction.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/python3
import sys
import os
import subprocess
def get_args():
import argparse
p = argparse.ArgumentParser(description='Geotag one or more photos with location and orientation from GPX file.')
p.add_argument('path', help='Path containing JPG files, or location of one JPG file.')
return p.parse_args()
def progress(count, total, status=''):
bar_len = 60
filled_len = int(round(bar_len * count / float(total)))
percents = round(100.0 * count / float(total), 1)
bar = '=' * filled_len + '-' * (bar_len - filled_len)
sys.stdout.write('[%s] %s%s ...%s\r' % (bar, percents, '%', status))
sys.stdout.flush() # As suggested by Rom Ruben (see: http://stackoverflow.com/questions/3173320/text-progress-bar-in-the-console/27871113#comment50529068_27871113)
if __name__ == '__main__':
args = get_args()
if args.path.lower().endswith(".jpg"):
# single file
file_list = [args.path]
else:
file_list = []
for root, sub_folders, files in os.walk(args.path):
file_list += [os.path.join(root, filename) for filename in files if filename.lower().endswith(".jpg")]
print("===\nStarting update of {0} images .\n===".format(len(file_list)))
index = 0
for filepath in file_list:
total = len(file_list)
index = index+1
if index > total:
index=total
progress(index, total, status='Add information to '+str(total) + ' photos')
#command='exiftool -overwrite_original -P -ProjectionType="equirectangular" -UsePanoramaViewer="True" -"GPSImgDirection<$exif:GPSImgDirection" -"PoseHeadingDegrees<$exif:GPSImgDirection" -"CroppedAreaImageWidthPixels<$ImageWidth" -"CroppedAreaImageHeightPixels<$ImageHeight" -"FullPanoWidthPixels<$ImageWidth" -"FullPanoHeightPixels<$ImageHeight" -CroppedAreaLeftPixels="0" -CroppedAreaTopPixels="0" "' + filepath + '"'
cmd=[]
cmd.append('exiftool')
cmd.append('-overwrite_original')
cmd.append('-P')
cmd.append('-ProjectionType=equirectangular')
cmd.append('-UsePanoramaViewer="True"')
cmd.append('-"GPSImgDirection<$exif:GPSImgDirection"')
cmd.append('-"PoseHeadingDegrees<$exif:GPSImgDirection"')
cmd.append('-"CroppedAreaImageWidthPixels<$ImageWidth"')
cmd.append('-"CroppedAreaImageHeightPixels<$ImageHeight"')
cmd.append('-"FullPanoWidthPixels<$ImageWidth"')
cmd.append('-"FullPanoHeightPixels<$ImageHeight"')
cmd.append('-"CroppedAreaImageWidthPixels<$ImageWidth"')
cmd.append('-CroppedAreaLeftPixels=0')
cmd.append('-CroppedAreaTopPixels=0')
cmd.append(filepath)
#print command
subprocess.run(cmd)
import time
time.sleep(5)