Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions linux/osmbundler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -208,26 +208,26 @@ 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:
ccdWidth = float(userInput)
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']
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -321,15 +321,15 @@ 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:
featureExtractor = getattr(features, self.featureExtractor)
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
Expand Down Expand Up @@ -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
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added linux/osmbundler/__pycache__/defaults.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion linux/osmbundler/features/sift.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys, os, logging

from extractor import FeatureExtractor
from .extractor import FeatureExtractor

class Sift(FeatureExtractor):

Expand Down
4 changes: 2 additions & 2 deletions linux/osmbundler/features/siftlowe.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os, subprocess, gzip

from sift import Sift
from .sift import Sift

className = "LoweSift"
class LoweSift(Sift):
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions linux/osmbundler/features/siftvlfeat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os, subprocess, gzip, logging

from sift import Sift
from .sift import Sift

className = "VlfeatSift"
class VlfeatSift(Sift):
Expand All @@ -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
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion linux/osmbundler/matching/bundler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys,os,subprocess,logging

from engine import MatchingEngine
from .engine import MatchingEngine

className = "BundlerMatching"
class BundlerMatching(MatchingEngine):
Expand Down
2 changes: 1 addition & 1 deletion linux/osmbundler/matching/manual.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from engine import MatchingEngine
from .engine import MatchingEngine

className = "ManualMatching"
class ManualMatching(MatchingEngine):
Expand Down
24 changes: 12 additions & 12 deletions linux/osmcmvs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(".")
Expand Down Expand Up @@ -123,28 +123,28 @@ 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()
sys.exit(2)

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()

22 changes: 11 additions & 11 deletions linux/osmpmvs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(".")
Expand All @@ -102,24 +102,24 @@ 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()
sys.exit(2)

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()

4 changes: 2 additions & 2 deletions ppt_gui_start
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions to_jpg.py
Original file line number Diff line number Diff line change
@@ -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)