diff --git a/linux/osmbundler/__init__.py b/linux/osmbundler/__init__.py index 9f0569e..4f48466 100755 --- a/linux/osmbundler/__init__.py +++ b/linux/osmbundler/__init__.py @@ -5,13 +5,13 @@ from PIL import Image from PIL.ExifTags import TAGS -import defaults +from . import defaults -import matching -from matching import * +from . import matching +from .matching import * -import features -from features import * +from . import features +from .features import * # a helper function to get list of photos from a directory def getPhotosFromDirectory(photoDir): @@ -86,7 +86,7 @@ def __init__(self): logging.info("Working directory created: "+self.workDir) if not (os.path.isdir(self.photosArg) or os.path.isfile(self.photosArg)): - raise Exception, "'%s' is neither directory nor a file name" % self.photosArg + raise Exception(f"{self.photosArg} is neither directory nor a file name") # initialize mathing engine based on command line arguments self.initMatchingEngine() @@ -152,7 +152,7 @@ def preparePhotos(self, *kargs, **kwargs): if os.path.isdir(self.photosArg): # directory with images photos = getPhotosFromDirectory(self.photosArg) - if len(photos)<3: raise Exception, "The directory with images should contain at least 3 .jpg photos" + if len(photos)<3: raise Exception("The directory with images should contain at least 3 .jpg photos") for photo in photos: photoInfo = dict(dirname=self.photosArg, basename=photo) self._preparePhoto(photoInfo) @@ -208,8 +208,8 @@ def checkCameraInDatabase(self, photoPath): ccdWidth = self.getCcdWidthFromDatabase(exifMake, exifModel) if ccdWidth==None: while True: - print "Type CCD width in mm for the camera %s, %s. Press Enter to skip the camera." % (exifMake, exifModel) - userInput = raw_input("CCD width in mm: ") + print("Type CCD width in mm for the camera %s, %s. Press Enter to skip the camera." % (exifMake, exifModel)) + userInput = input("CCD width in mm: ") # Enter key was pressed if not userInput: return try: @@ -217,17 +217,17 @@ def checkCameraInDatabase(self, photoPath): if ccdWidth==0: raise ZeroValueException self.dbCursor.execute("insert into cameras(make, model, ccd_width, source) values(?, ?, ?, 2)", (exifMake, exifModel, ccdWidth)) except ZeroValueException: - print "\nCCD width can not be equal to zero." + print("\nCCD width can not be equal to zero.") except ValueError: - print "\nIncorrect value for the CCD width. Please enter CCD width in mm." + print("\nIncorrect value for the CCD width. Please enter CCD width in mm.") except: - print "\nCan not insert CCD width to the database." + print("\nCan not insert CCD width to the database.") else: - print "CCD width %s for the cameras %s,%s has been successively inserted to the database" % (ccdWidth, exifMake, exifModel) + print("CCD width %s for the cameras %s,%s has been successively inserted to the database" % (ccdWidth, exifMake, exifModel)) return - else: - print "Camera is already inserted into the database" - return + else: + print("Camera is already inserted into the database") + return def _preparePhoto(self, photoInfo): photo = photoInfo['basename'] @@ -288,7 +288,7 @@ def _getExif(self, photoHandle): exif = {} info = photoHandle._getexif() if info: - for attr, value in info.items(): + for attr, value in list(info.items()): decodedAttr = TAGS.get(attr, attr) if decodedAttr in exifAttrs: exif[decodedAttr] = value if 'FocalLength' in exif: exif['FocalLength'] = float(exif['FocalLength'][0])/float(exif['FocalLength'][1]) @@ -321,7 +321,7 @@ def initMatchingEngine(self): matchingEngineClass = getattr(matchingEngine, matchingEngine.className) self.matchingEngine = matchingEngineClass(os.path.join(distrPath, "software")) except: - raise Exception, "Unable initialize matching engine %s" % self.featureExtractor + raise Exception("Unable initialize matching engine %s" % self.featureExtractor) def initFeatureExtractor(self): try: @@ -329,7 +329,7 @@ def initFeatureExtractor(self): featureExtractorClass = getattr(featureExtractor, featureExtractor.className) self.featureExtractor = featureExtractorClass(os.path.join(distrPath, "software")) except: - raise Exception, "Unable initialize feature extractor %s" % self.featureExtractor + raise Exception("Unable initialize feature extractor %s" % self.featureExtractor) def extractFeatures(self, photo): # let self.featureExtractor do its job @@ -368,12 +368,14 @@ def printHelpExit(self): def openResult(self): if sys.platform == "win32": subprocess.call(["explorer", self.workDir]) - if sys.platform == "linux2": subprocess.call(["xdg-open", self.workDir]) - else: print "Thanks" + if sys.platform == "linux2": + subprocess.call(["xdg-open", self.workDir]) + else: + print("Thanks") def printHelp(self): helpFile = open(os.path.join(distrPath, "osmbundler/help.txt"), "r") - print helpFile.read() + print(helpFile.read()) helpFile.close() # a helper function to get CCD width from sqlite database diff --git a/linux/osmbundler/__pycache__/__init__.cpython-310.pyc b/linux/osmbundler/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..34cad69 Binary files /dev/null and b/linux/osmbundler/__pycache__/__init__.cpython-310.pyc differ diff --git a/linux/osmbundler/__pycache__/__init__.cpython-38.pyc b/linux/osmbundler/__pycache__/__init__.cpython-38.pyc new file mode 100644 index 0000000..0831268 Binary files /dev/null and b/linux/osmbundler/__pycache__/__init__.cpython-38.pyc differ diff --git a/linux/osmbundler/__pycache__/defaults.cpython-310.pyc b/linux/osmbundler/__pycache__/defaults.cpython-310.pyc new file mode 100644 index 0000000..030388f Binary files /dev/null and b/linux/osmbundler/__pycache__/defaults.cpython-310.pyc differ diff --git a/linux/osmbundler/__pycache__/defaults.cpython-38.pyc b/linux/osmbundler/__pycache__/defaults.cpython-38.pyc new file mode 100644 index 0000000..b704572 Binary files /dev/null and b/linux/osmbundler/__pycache__/defaults.cpython-38.pyc differ diff --git a/linux/osmbundler/features/__pycache__/__init__.cpython-310.pyc b/linux/osmbundler/features/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..4c3c0e0 Binary files /dev/null and b/linux/osmbundler/features/__pycache__/__init__.cpython-310.pyc differ diff --git a/linux/osmbundler/features/__pycache__/__init__.cpython-38.pyc b/linux/osmbundler/features/__pycache__/__init__.cpython-38.pyc new file mode 100644 index 0000000..6dd03f7 Binary files /dev/null and b/linux/osmbundler/features/__pycache__/__init__.cpython-38.pyc differ diff --git a/linux/osmbundler/features/__pycache__/extractor.cpython-310.pyc b/linux/osmbundler/features/__pycache__/extractor.cpython-310.pyc new file mode 100644 index 0000000..7a7209e Binary files /dev/null and b/linux/osmbundler/features/__pycache__/extractor.cpython-310.pyc differ diff --git a/linux/osmbundler/features/__pycache__/extractor.cpython-38.pyc b/linux/osmbundler/features/__pycache__/extractor.cpython-38.pyc new file mode 100644 index 0000000..4643671 Binary files /dev/null and b/linux/osmbundler/features/__pycache__/extractor.cpython-38.pyc differ diff --git a/linux/osmbundler/features/__pycache__/sift.cpython-310.pyc b/linux/osmbundler/features/__pycache__/sift.cpython-310.pyc new file mode 100644 index 0000000..d285b9d Binary files /dev/null and b/linux/osmbundler/features/__pycache__/sift.cpython-310.pyc differ diff --git a/linux/osmbundler/features/__pycache__/sift.cpython-38.pyc b/linux/osmbundler/features/__pycache__/sift.cpython-38.pyc new file mode 100644 index 0000000..eb18d2f Binary files /dev/null and b/linux/osmbundler/features/__pycache__/sift.cpython-38.pyc differ diff --git a/linux/osmbundler/features/__pycache__/siftlowe.cpython-310.pyc b/linux/osmbundler/features/__pycache__/siftlowe.cpython-310.pyc new file mode 100644 index 0000000..3e67c77 Binary files /dev/null and b/linux/osmbundler/features/__pycache__/siftlowe.cpython-310.pyc differ diff --git a/linux/osmbundler/features/__pycache__/siftlowe.cpython-38.pyc b/linux/osmbundler/features/__pycache__/siftlowe.cpython-38.pyc new file mode 100644 index 0000000..76d0bd3 Binary files /dev/null and b/linux/osmbundler/features/__pycache__/siftlowe.cpython-38.pyc differ diff --git a/linux/osmbundler/features/__pycache__/siftvlfeat.cpython-310.pyc b/linux/osmbundler/features/__pycache__/siftvlfeat.cpython-310.pyc new file mode 100644 index 0000000..21fe086 Binary files /dev/null and b/linux/osmbundler/features/__pycache__/siftvlfeat.cpython-310.pyc differ diff --git a/linux/osmbundler/features/__pycache__/siftvlfeat.cpython-38.pyc b/linux/osmbundler/features/__pycache__/siftvlfeat.cpython-38.pyc new file mode 100644 index 0000000..90bb87c Binary files /dev/null and b/linux/osmbundler/features/__pycache__/siftvlfeat.cpython-38.pyc differ diff --git a/linux/osmbundler/features/sift.py b/linux/osmbundler/features/sift.py index a5f5edb..f0851c2 100755 --- a/linux/osmbundler/features/sift.py +++ b/linux/osmbundler/features/sift.py @@ -1,6 +1,6 @@ import sys, os, logging -from extractor import FeatureExtractor +from .extractor import FeatureExtractor class Sift(FeatureExtractor): diff --git a/linux/osmbundler/features/siftlowe.py b/linux/osmbundler/features/siftlowe.py index 04e13fb..86e55ce 100755 --- a/linux/osmbundler/features/siftlowe.py +++ b/linux/osmbundler/features/siftlowe.py @@ -1,6 +1,6 @@ import os, subprocess, gzip -from sift import Sift +from .sift import Sift className = "LoweSift" class LoweSift(Sift): @@ -19,7 +19,7 @@ def extract(self, photo, photoInfo): siftTextFile.close() # gzip SIFT file and remove it siftTextFile = open("%s.key" % photo, "r") - siftGzipFile = gzip.open("%s.key.gz" % photo, "wb") + siftGzipFile = gzip.open("%s.key.gz" % photo, "wt") siftGzipFile.writelines(siftTextFile) siftGzipFile.close() siftTextFile.close() diff --git a/linux/osmbundler/features/siftvlfeat.py b/linux/osmbundler/features/siftvlfeat.py index c967772..6632f0c 100755 --- a/linux/osmbundler/features/siftvlfeat.py +++ b/linux/osmbundler/features/siftvlfeat.py @@ -1,6 +1,6 @@ import os, subprocess, gzip, logging -from sift import Sift +from .sift import Sift className = "VlfeatSift" class VlfeatSift(Sift): @@ -16,7 +16,7 @@ def extract(self, photo, photoInfo): subprocess.call([self.executable, "%s.jpg.pgm" % photo, "-o", "%s.key" % photo]) # perform conversion to David Lowe's format vlfeatTextFile = open("%s.key" % photo, "r") - loweGzipFile = gzip.open("%s.key.gz" % photo, "wb") + loweGzipFile = gzip.open("%s.key.gz" % photo, "wt") featureStrings = vlfeatTextFile.readlines() numFeatures = len(featureStrings) # write header diff --git a/linux/osmbundler/matching/__pycache__/__init__.cpython-310.pyc b/linux/osmbundler/matching/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..8bf394c Binary files /dev/null and b/linux/osmbundler/matching/__pycache__/__init__.cpython-310.pyc differ diff --git a/linux/osmbundler/matching/__pycache__/__init__.cpython-38.pyc b/linux/osmbundler/matching/__pycache__/__init__.cpython-38.pyc new file mode 100644 index 0000000..1f50cba Binary files /dev/null and b/linux/osmbundler/matching/__pycache__/__init__.cpython-38.pyc differ diff --git a/linux/osmbundler/matching/__pycache__/bundler.cpython-310.pyc b/linux/osmbundler/matching/__pycache__/bundler.cpython-310.pyc new file mode 100644 index 0000000..2f2872c Binary files /dev/null and b/linux/osmbundler/matching/__pycache__/bundler.cpython-310.pyc differ diff --git a/linux/osmbundler/matching/__pycache__/bundler.cpython-38.pyc b/linux/osmbundler/matching/__pycache__/bundler.cpython-38.pyc new file mode 100644 index 0000000..269a2d6 Binary files /dev/null and b/linux/osmbundler/matching/__pycache__/bundler.cpython-38.pyc differ diff --git a/linux/osmbundler/matching/__pycache__/engine.cpython-310.pyc b/linux/osmbundler/matching/__pycache__/engine.cpython-310.pyc new file mode 100644 index 0000000..e3d1a5c Binary files /dev/null and b/linux/osmbundler/matching/__pycache__/engine.cpython-310.pyc differ diff --git a/linux/osmbundler/matching/__pycache__/engine.cpython-38.pyc b/linux/osmbundler/matching/__pycache__/engine.cpython-38.pyc new file mode 100644 index 0000000..eab6c81 Binary files /dev/null and b/linux/osmbundler/matching/__pycache__/engine.cpython-38.pyc differ diff --git a/linux/osmbundler/matching/__pycache__/manual.cpython-310.pyc b/linux/osmbundler/matching/__pycache__/manual.cpython-310.pyc new file mode 100644 index 0000000..5b889e1 Binary files /dev/null and b/linux/osmbundler/matching/__pycache__/manual.cpython-310.pyc differ diff --git a/linux/osmbundler/matching/__pycache__/manual.cpython-38.pyc b/linux/osmbundler/matching/__pycache__/manual.cpython-38.pyc new file mode 100644 index 0000000..c577ac4 Binary files /dev/null and b/linux/osmbundler/matching/__pycache__/manual.cpython-38.pyc differ diff --git a/linux/osmbundler/matching/bundler.py b/linux/osmbundler/matching/bundler.py index 298b830..078b1f1 100755 --- a/linux/osmbundler/matching/bundler.py +++ b/linux/osmbundler/matching/bundler.py @@ -1,6 +1,6 @@ import sys,os,subprocess,logging -from engine import MatchingEngine +from .engine import MatchingEngine className = "BundlerMatching" class BundlerMatching(MatchingEngine): diff --git a/linux/osmbundler/matching/manual.py b/linux/osmbundler/matching/manual.py index 6084d2c..d884f84 100755 --- a/linux/osmbundler/matching/manual.py +++ b/linux/osmbundler/matching/manual.py @@ -1,4 +1,4 @@ -from engine import MatchingEngine +from .engine import MatchingEngine className = "ManualMatching" class ManualMatching(MatchingEngine): diff --git a/linux/osmcmvs/__init__.py b/linux/osmcmvs/__init__.py index f86184f..9c5aa60 100755 --- a/linux/osmcmvs/__init__.py +++ b/linux/osmcmvs/__init__.py @@ -47,7 +47,7 @@ def __init__(self): logging.info("Working directory created: "+self.workDir) if not (os.path.isdir(self.bundleOutArg) or os.path.isfile(self.bundleOutArg)): - raise Exception, "'%s' is neither directory nor a file name" % self.bundleOutArg + raise Exception("'%s' is neither directory nor a file name" % self.bundleOutArg) def parseCommandLineFlags(self): try: @@ -77,21 +77,21 @@ def doBundle2PMVS(self): os.mkdir("pmvs/models") #$BASE_PATH/bin32/Bundle2PMVS.exe list.txt bundle/bundle.out - print "Running Bundle2PMVS to generate geometry and converted camera file" + print("Running Bundle2PMVS to generate geometry and converted camera file") subprocess.call([bundler2PmvsExecutable, "list.txt", "bundle/bundle.out"]) # Apply radial undistortion to the images - print "Running RadialUndistort to undistort input images" + print("Running RadialUndistort to undistort input images") subprocess.call([RadialUndistordExecutable, "list.txt", "bundle/bundle.out", "pmvs"]) - print "Running Bundle2Vis to generate vis.dat" + print("Running Bundle2Vis to generate vis.dat") subprocess.call([Bundle2VisExecutable, "pmvs/bundle.rd.out", "pmvs/vis.dat"]) os.chdir(os.path.join(self.workDir,"pmvs")) #Rename all the files to the correct name undistortTextFile = open("list.rd.txt", "r") imagesStrings = undistortTextFile.readlines() - print "Move files in the correct directory" + print("Move files in the correct directory") cpt = 0 for imageString in imagesStrings: image = imageString.split(".") @@ -123,16 +123,16 @@ def doCMVS(self): # for file in files: # if "option-" in file: # subprocess.call([pmvsExecutable, "./", file]) - print "Finished! See the results in the '%s' directory" % self.workDir + print("Finished! See the results in the '%s' directory" % self.workDir) if sys.platform == "win32": subprocess.call(["explorer", self.workDir]) if sys.platform == "linux2": subprocess.call(["xdg-open", self.workDir]) - else: print "Thanks" + else: print("Thanks") def doPMVS(self, path, optionFile): os.chdir(os.path.join(path,"pmvs")) - print "Run PMVS2 : %s " % pmvsExecutable + print("Run PMVS2 : %s " % pmvsExecutable) subprocess.call([pmvsExecutable, "./", optionFile]) - print "Finished! See the results in the '%s' directory" % self.workDir + print("Finished! See the results in the '%s' directory" % self.workDir) def printHelpExit(self): self.printHelp() @@ -140,11 +140,11 @@ def printHelpExit(self): def openResult(self): if sys.platform == "win32": subprocess.call(["explorer", self.workDir]) - else: print "See the results in the '%s' directory" % self.workDir + else: print("See the results in the '%s' directory" % self.workDir) def printHelp(self): - print "Error" + print("Error") helpFile = open(os.path.join(distrPath, "osmcmvs/help.txt"), "r") - print helpFile.read() + print(helpFile.read()) helpFile.close() diff --git a/linux/osmpmvs/__init__.py b/linux/osmpmvs/__init__.py index 02177d8..7de92b2 100755 --- a/linux/osmpmvs/__init__.py +++ b/linux/osmpmvs/__init__.py @@ -43,7 +43,7 @@ def __init__(self): logging.info("Working directory created: "+self.workDir) if not (os.path.isdir(self.bundleOutArg) or os.path.isfile(self.bundleOutArg)): - raise Exception, "'%s' is neither directory nor a file name" % self.bundleOutArg + raise Exception("'%s' is neither directory nor a file name" % self.bundleOutArg) def parseCommandLineFlags(self): try: @@ -71,21 +71,21 @@ def doBundle2PMVS(self): os.mkdir("pmvs/models") #$BASE_PATH/bin32/Bundle2PMVS.exe list.txt bundle/bundle.out - print "Running Bundle2PMVS to generate geometry and converted camera file" + print("Running Bundle2PMVS to generate geometry and converted camera file") subprocess.call([bundler2PmvsExecutable, "list.txt", "bundle/bundle.out"]) # Apply radial undistortion to the images - print "Running RadialUndistort to undistort input images" + print("Running RadialUndistort to undistort input images") subprocess.call([RadialUndistordExecutable, "list.txt", "bundle/bundle.out", "pmvs"]) - print "Running Bundle2Vis to generate vis.dat" + print("Running Bundle2Vis to generate vis.dat") subprocess.call([Bundle2VisExecutable, "pmvs/bundle.rd.out", "pmvs/vis.dat"]) os.chdir(os.path.join(self.workDir,"pmvs")) #Rename all the files to the correct name undistortTextFile = open("list.rd.txt", "r") imagesStrings = undistortTextFile.readlines() - print "Move files in the correct directory" + print("Move files in the correct directory") cpt = 0 for imageString in imagesStrings: image = imageString.split(".") @@ -102,12 +102,12 @@ def doBundle2PMVS(self): logging.info("Finished!") def doPMVS(self): - print "Run PMVS2 : %s " % pmvsExecutable + print("Run PMVS2 : %s " % pmvsExecutable) subprocess.call([pmvsExecutable, "./", "pmvs_options.txt"]) - print "Finished! See the results in the '%s' directory" % self.workDir + print("Finished! See the results in the '%s' directory" % self.workDir) if sys.platform == "win32": subprocess.call(["explorer", self.workDir]) if sys.platform == "linux2": subprocess.call(["xdg-open", self.workDir]) - else: print "Thanks" + else: print("Thanks") def printHelpExit(self): self.printHelp() @@ -115,11 +115,11 @@ def printHelpExit(self): def openResult(self): if sys.platform == "win32": subprocess.call(["explorer", self.workDir]) - else: print "See the results in the '%s' directory" % self.workDir + else: print("See the results in the '%s' directory" % self.workDir) def printHelp(self): - print "Error" + print("Error") helpFile = open(os.path.join(distrPath, "osmpmvs/help.txt"), "r") - print helpFile.read() + print(helpFile.read()) helpFile.close() diff --git a/ppt_gui_start b/ppt_gui_start index cfdcfb6..e7b4bc6 100755 --- a/ppt_gui_start +++ b/ppt_gui_start @@ -1,4 +1,4 @@ #!/bin/sh -cd /home/steve/Desktop/3D/osm-bundler/linux/ -export LD_LIBRARY_PATH="/home/steve/Desktop/3D/osm-bundler/linux/software/bundler/bin" +cd /home/casper/Documents/rendering/photogrammetry/linux/ +export LD_LIBRARY_PATH="/home/casper/Documents/rendering/photogrammetry/linux/software/bundler/bin" python ./ppt_gui.py diff --git a/to_jpg.py b/to_jpg.py new file mode 100644 index 0000000..ccaddb0 --- /dev/null +++ b/to_jpg.py @@ -0,0 +1,13 @@ +from PIL import Image +import os +PATH = "/home/casper/Documents/rendering/DATASET/1" + +files = os.listdir(PATH) # list of files in directory + +for file in files: + + if file.endswith('.png'): # check if file is png + file_path = f"{PATH}/{file}" + + im = Image.open(file_path).convert("RGB") # open file as an image object + im.save(f'{PATH}/jpgs/{file[:-4]}.jpg',quality=95, optimize=True) \ No newline at end of file