Skip to content

Instantly share code, notes, and snippets.

@Franc-Brs
Last active January 11, 2022 12:15
Show Gist options
  • Save Franc-Brs/8612fecdf2e2a3a026eb4b62785da372 to your computer and use it in GitHub Desktop.
Save Franc-Brs/8612fecdf2e2a3a026eb4b62785da372 to your computer and use it in GitHub Desktop.
draft

GoProFusion

creare collegamento nella cartella di lavoro per facilità (>crea collegamento e cercati FUsionStudio_x64.exe o simile) fonti utili https://github.com/anafaggiano/Mapillary Per una immagine

.\FusionStudio_x64.exe.lnk --back C:\path\in\windowsBAck\GB010005.JPG --front C:\path\in\windowsFront\GF010005.JPG --output C:\path\in\windowsOutput\image.jpg -p 0 --pc 0 -videoCodec 4

Python

per il virtual env https://uoa-eresearch.github.io/eresearch-cookbook/recipe/2014/11/26/python-virtual-env/ una volta creato attivalo se vuoi dalla cartella cogni source mapillary/Scripts/activate

Mapillary

scarica https://github.com/mapillary/mapillary_tools/releases/tag/v0.8.0 e gioca https://github.com/mapillary/mapillary_tools#quickstart

from cmd

C:\path\to\exe>mapillary_tools_win.exe process_and_upload .\output --user_name "FrancescoBrs1"

Mantenere i processi in win

usare da powershell

query user

usare tscon dalla cartella sustem32 e mettere nome sessione al posto di tscon etc etc

C:\WINDOWS\system32> .\tscon.exe rdp-tcp#11 /dest:console
from subprocess import check_call
import sys, fnmatch, os
from os import path as oSpath
from PIL import Image
import logging
from info import start
from PIL.ExifTags import TAGS, GPSTAGS
def initLogger(name):
"""
Keep things as simple as possible for the moment
"""
path = os.path.dirname(os.path.realpath(__file__))
logfile = f"{path}/{name}.log"
logging.basicConfig(
format="%(asctime)s\t%(levelname)s\t%(message)s",
filemode="a",
filename=logfile,
level=logging.INFO,
)
def check_GoPro(fcwd):
"""
check the existance of the gopro.exe in the same folder of this script
"""
if not (oSpath.isfile(os.path.join(fcwd, "FusionStudio_x64.exe.lnk"))):
logging.error("Stai facendo andare lo script dalla cartella sbagliata")
sys.exit()
return
def get_num_pixels(path):
"""
get number of pixel of an image
"""
width, height = Image.open(path).size
return width * height
def mk_output_folder(path, folder):
"""
if a folder (with name "folder") does not exist, it is created
"""
if not oSpath.exists(oSpath.join(path, folder)):
os.makedirs(oSpath.join(path, folder))
return
def get_exif(path):
"""
from
https://developer.here.com/blog/getting-started-with-geocoding-exif-image-metadata-in-python3
"""
image = Image.open(path)
image.verify()
return image._getexif()
def get_geotagging(exif, filepath):
"""
from
https://developer.here.com/blog/getting-started-with-geocoding-exif-image-metadata-in-python3
filepath needs only for logging
"""
if not exif:
raise ValueError("No EXIF metadata found")
geotagging = {}
for (idx, tag) in TAGS.items():
if tag == "GPSInfo":
if idx not in exif:
logging.error(f"No EXIF geotagging found for {filepath}")
return
# raise ValueError("No EXIF geotagging found")
for (key, val) in GPSTAGS.items():
if key in exif[idx]:
geotagging[val] = exif[idx][key]
return geotagging
def use_GoPro(froot, fname, front, output):
"""
launch the FusionStudio_x64.exe from the cmd
"""
args = [
f"--back {oSpath.join(froot, fname)}",
f"--front {front}",
f"--output {output}",
]
str1 = f".\FusionStudio_x64.exe.lnk {args[0]} {args[1]} {args[2]} -p 0 --pc 0 --width 5760"
logging.info(str1)
# do il comando da prompt
#check_call(str1, shell=True)
check_call(["cmd","/c",".\FusionStudio_x64.exe.lnk","--back",oSpath.join(froot, fname),"--front",front,"--output",output])
return
def main():
LOGFILENAME = os.path.basename(__file__).split(".")[0]
initLogger(LOGFILENAME)
cwd = os.getcwd()
check_GoPro(cwd)
# pattern = "GB*.jpg" # idealmente il pattern cerca il file di BACK GB*.jpg
# pattern = "GB013988.JPG"
pattern = "GB01000*.jpg"
datiInput = oSpath.join(start)
# controlliamo che esista o meno la cartella output ed eventualmente creiamola
mk_output_folder(datiInput, "output")
outputFolder = oSpath.join(datiInput, "output")
for root, dirs, files in os.walk(datiInput, topdown=False):
for name in files:
if fnmatch.fnmatch(name, pattern):
# GB010001.jpg --> 010001
outputStringName = name[2:-4]
# percorso della cartella che contiene FRONT e BACK
folderNamePath = oSpath.dirname(root)
# nome della cartella che contiene FRONT e BACK
foldername = oSpath.basename(folderNamePath)
# name of the FRONT folder (deve contenere FRNT)
nameFront = oSpath.basename(root).split("BACK")[0] + "FRNT"
frontFolderFile = oSpath.join(
folderNamePath, nameFront, f"GF{outputStringName}.jpg"
)
mk_output_folder(outputFolder, foldername)
# file di output i chiamer stich01...jpg
outputFolderFile = oSpath.join(
outputFolder, foldername, f"stich{outputStringName}.jpg"
)
if (oSpath.isfile(outputFolderFile)) and (get_num_pixels(outputFolderFile) == 16588800):
exif = get_exif(outputFolderFile)
# dict of 8 elements
geotags = get_geotagging(exif, outputFolderFile)
logging.info(
f"Esiste già {outputFolderFile} con dimensione {get_num_pixels(outputFolderFile)} e posizione {geotags}"
)
continue
use_GoPro(root, name, frontFolderFile, outputFolderFile)
if __name__ == "__main__":
main()
@Franc-Brs
Copy link
Author

Franc-Brs commented Jan 10, 2022

todo

  • add logging instead of print
  • shell true in subprocess
  • check exif
  • migliorare lo script (get_geotagging non è scritta bene così)
  • add mapllary subprocess

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment