From 2498663543f51ff4e7b361bac41bea6c092c00c1 Mon Sep 17 00:00:00 2001 From: s-du <53427781+s-du@users.noreply.github.com> Date: Thu, 20 Jul 2023 14:36:29 +0200 Subject: [PATCH] Fix major bug with Agisoft install --- .../other/camera_calib_m3t_no_process.xml | 15 ------- tools/agisoft_part.py | 44 +++++++++++-------- tools/thermal_tools.py | 1 + 3 files changed, 27 insertions(+), 33 deletions(-) delete mode 100644 resources/other/camera_calib_m3t_no_process.xml diff --git a/resources/other/camera_calib_m3t_no_process.xml b/resources/other/camera_calib_m3t_no_process.xml deleted file mode 100644 index a456011..0000000 --- a/resources/other/camera_calib_m3t_no_process.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - frame - 640 - 512 - 1009.2550324346817 - -13.869239350341358 - 18.927372783525193 - -0.60468987861228396 - 0.37884919821313828 - -0.61661475665909271 - 0.0043840778545755138 - -0.0098188156513866823 - 2023-05-30T08:55:51Z - diff --git a/tools/agisoft_part.py b/tools/agisoft_part.py index 717f11c..e4e5ae6 100644 --- a/tools/agisoft_part.py +++ b/tools/agisoft_part.py @@ -1,27 +1,35 @@ import os import resources as res from PySide6 import QtCore, QtGui, QtWidgets -import subprocess import sys -import pkg_resources +if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'): + print('running in a PyInstaller bundle') -def install_agisoft_module(): - # install Metashape module if necessary - def install(package): - subprocess.check_call([sys.executable, "-m", "pip", "install", package]) +else: + print('running in a normal Python process') + # if run in Python process, then the app needs to check if Agisoft is installed + import subprocess + import pkg_resources - metashape_module = res.find('other/Metashape-2.0.1-cp37.cp38.cp39.cp310.cp311-none-win_amd64.whl') - install(metashape_module) -# check if module is installed -required = {'metashape'} -installed = {pkg.key for pkg in pkg_resources.working_set} -print(installed) -missing = required - installed -if missing: - print(r"Ok let's intall Agisoft!") - install_agisoft_module() + def install_agisoft_module(): + # install Metashape module if necessary + def install(package): + subprocess.check_call([sys.executable, "-m", "pip", "install", package]) + + metashape_module = res.find('other/Metashape-2.0.1-cp37.cp38.cp39.cp310.cp311-none-win_amd64.whl') + install(metashape_module) + + # check if module is installed + required = {'metashape'} + installed = {pkg.key for pkg in pkg_resources.working_set} + print(installed) + missing = required - installed + if missing: + print(r"Ok let's intall Agisoft!") + install_agisoft_module() + import Metashape @@ -75,9 +83,9 @@ def run(self): pdf_path = os.path.join(self.output_folder, 'thermal_document.pdf') # drone model specific data - if self.drone_model == 'MAVIC2-ENTERPRISE-ADVANCED': + if self.drone_model.name == 'MAVIC2-ENTERPRISE-ADVANCED': calib_file = res.find('other/camera_calib_m2t.xml') - elif self.drone_model == 'M3T': + elif self.drone_model.name == 'M3T': calib_file = res.find('other/camera_calib_m3t.xml') # compute number of steps diff --git a/tools/thermal_tools.py b/tools/thermal_tools.py index bb0ef78..1bb1923 100644 --- a/tools/thermal_tools.py +++ b/tools/thermal_tools.py @@ -35,6 +35,7 @@ class DroneModel(): def __init__(self,name): + self.name = name if name == 'MAVIC2-ENTERPRISE-ADVANCED': self.rgb_xml_path = m2t_rgb_xml_path self.ir_xml_path = m2t_ir_xml_path