とらりもんHOME  Index  Search  Changes  Login

GoPro street view photos

Correct timestamp

$ exiftool -alldates+="0:0:0 0:0:2" *JPG
$ rm *JPG_original

rename with time stamp

for i in *.JPG; do
head=`jhead $i | grep Date/Time | sed 's/:/ /g' | awk '{print $2"_"$3$4"_"$5$6}'`
o=`echo ${head}_${i} | sed 's/__/_/g'`
mv $i ${o%JPG}jpg
done

Delete images taken at the same position (such as waiting for the red traffic signal)

$ cat /home/nishida/bin/digicam_stay_GPS.py

#!/usr/bin/env python3
# Pick up digicam images staying a same position by using GPS
# use:     $ digicam_saty_GPS.py
# note: This is Python 2 script. It cannot work in Python 3 (because of lack of pyexiv2).
# (for i in GSAF????.JPG; do convert -fill '#333333' -draw 'rectangle 0,1900 5760,2880' $i p/${i%.JPG}p.JPG; done) &
import sys
import os
import pyexiv2
import glob
import shutil
import numpy as np
dist_stay = 1.0
deg2meter = 110000.0
if len(sys.argv)==2:
  dist_stay=float(sys.argv[1])

filelist=glob.glob("*.jpg")+glob.glob("*.JPG")
filelist.sort()

destdirname="stay"
os.makedirs(destdirname, exist_ok=True)
x0, y0 = 0.0, 0.0
print("stay distance = ", dist_stay, "m", "... less than this implies the camera was at stay.")
for file in filelist:
 # get Exif metadata from a file
 meta=pyexiv2.Image(file).read_exif()

 # check whether GPS data exists
 if not 'Exif.GPSInfo.GPSLongitude' in meta:
   print("Error ... GPS info not included in "+file+" -> move to the directory "+destdirname)
   shutil.move(file, destdirname+"/"+file)
   continue

 d,m,s=[eval(x) for x in meta['Exif.GPSInfo.GPSLongitude'].split(' ')]
 x = d + (m+s/60.0)/60.0
 d,m,s=[eval(x) for x in meta['Exif.GPSInfo.GPSLatitude'].split(' ')]
 y = d + (m+s/60.0)/60.0
 dist = np.sqrt(((x-x0)*np.cos(x*np.pi/180))**2 + (y-y0)**2)*deg2meter
 if dist < dist_stay:
    print(file, '{:.4g}'.format(dist), "m", " ... stay! -> move to the directory "+destdirname)
    shutil.move(file, destdirname+"/"+file)
 elif x == 0 and y==0:
    print(file, " ... strange GPS! -> move to the directory "+destdirname)
    shutil.move(file, destdirname+"/"+file)
 else:
    print(file, '{:.4g}'.format(dist), "m")
 x0, y0 = x, y

Rewrite file timestamp with GPS time

#!/usr/bin/env python3
# rewrite timestamp with GPS time
# use:     $ digicam_rewrite_time_by_GPS.py
import sys
import os
import pyexiv2
import glob
import shutil
import datetime
import numpy as np

filelist=glob.glob("*.jpg")+glob.glob("*.JPG")
filelist.sort()

destdirname="./"
garbagedirname="no_timestamp/"
os.makedirs(destdirname+garbagedirname, exist_ok=True)
for file in filelist:
   # get Exif metadata from a file
   # meta=pyexiv2.Image(file).read_exif()
   img=pyexiv2.Image(file)
   meta=img.read_exif()
   if not 'Exif.GPSInfo.GPSDateStamp' in meta:
       print("Error ... GPS info not included in "+file+" -> move to the directory "+destdirname+garbagedirname)
       shutil.move(file, destdirname+garbagedirname+file)
       continue
   date=meta['Exif.GPSInfo.GPSDateStamp']
   h, m, s = meta['Exif.GPSInfo.GPSTimeStamp'].replace('/', ' ').split(' ')[0:5:2] 
   time=h.zfill(2)+":"+m.zfill(2)+":"+s.zfill(2)
   newdatetime=datetime.datetime.strptime(date+" "+time, '%Y:%m:%d %H:%M:%S')+datetime.timedelta(hours=9)
   newdatetime_str=newdatetime.strftime('%Y:%m:%d %H:%M:%S')
   print(meta['Exif.Photo.DateTimeOriginal'] + " --> " + newdatetime_str)
   meta['Exif.Photo.DateTimeOriginal'] = newdatetime_str
   meta['Exif.Image.DateTime'] = newdatetime_str
   img.modify_exif(meta)
   img.close()

Mask out the useless part (like rooftop at the camera foot) in the images

$ for k in *JPG; do convert -fill '#333333' -draw 'rectangle 0,2300 5760,2880' $k tmp/$k; done
$ for k in *JPG; do 
convert -fill '#333333' -draw 'rectangle 0,2400 5760,2880' -draw 'rectangle 0,2200 1400,2400' -draw 'rectangle 4200,2200 5760,2400' $k tmp/$k
done

Upload to Mapillary

$ pip3 install mapillary_tools
$ mapillary_tools process_and_upload --import_path "./" --user_name "xxxxxxxx"
Last modified:2023/07/20 14:24:17
Keyword(s):
References: