Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command line adjustments #759

Merged
merged 4 commits into from
Jan 20, 2020
Merged
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
18 changes: 13 additions & 5 deletions meshroom/multiview.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,20 @@ def findFilesByTypeInFolder(folder, recursive=False):
if os.path.isfile(currentFolder):
output.addFile(currentFolder)
continue
if recursive:
for root, directories, files in os.walk(currentFolder):
for filename in files:
output.addFile(os.path.join(root, filename))
elif os.path.isdir(currentFolder):
if recursive:
for root, directories, files in os.walk(currentFolder):
for filename in files:
output.addFile(os.path.join(root, filename))
else:
output.addFiles([os.path.join(currentFolder, filename) for filename in os.listdir(currentFolder)])
else:
output.addFiles([os.path.join(currentFolder, filename) for filename in os.listdir(currentFolder)])
# if not a diretory or a file, it may be an expression
import glob
paths = glob.glob(currentFolder)
filesByType = findFilesByTypeInFolder(paths, recursive=recursive)
output.extend(filesByType)

return output


Expand Down
28 changes: 28 additions & 0 deletions meshroom/ui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,25 @@ def __init__(self, args):
help='Import images or folder with images to reconstruct.')
parser.add_argument('-I', '--importRecursive', metavar='FOLDERS', type=str, nargs='*',
help='Import images to reconstruct from specified folder and sub-folders.')
parser.add_argument('-s', '--save', metavar='PROJECT.mg', type=str, default='',
help='Save the created scene.')
parser.add_argument('-p', '--pipeline', metavar='MESHROOM_FILE/photogrammetry/hdri', type=str, default=os.environ.get("MESHROOM_DEFAULT_PIPELINE", "photogrammetry"),
help='Override the default Meshroom pipeline with this external graph.')
parser.add_argument("--verbose", help="Verbosity level", default='warning',
choices=['fatal', 'error', 'warning', 'info', 'debug', 'trace'],)

args = parser.parse_args(args[1:])

logStringToPython = {
'fatal': logging.FATAL,
'error': logging.ERROR,
'warning': logging.WARNING,
'info': logging.INFO,
'debug': logging.DEBUG,
'trace': logging.DEBUG,
}
logging.getLogger().setLevel(logStringToPython[args.verbose])

QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)

super(MeshroomApp, self).__init__(QtArgs)
Expand Down Expand Up @@ -137,6 +151,20 @@ def __init__(self, args):
if args.importRecursive:
r.importImagesFromFolder(args.importRecursive, recursive=True)

if args.save:
if os.path.isfile(args.save):
raise RuntimeError(
"Meshroom Command Line Error: Cannot save the new Meshroom project as the file (.mg) already exists.\n"
"Invalid value: '{}'".format(args.save))
projectFolder = os.path.dirname(args.save)
if not os.path.isdir(projectFolder):
if not os.path.isdir(os.path.dirname(projectFolder)):
raise RuntimeError(
"Meshroom Command Line Error: Cannot save the new Meshroom project file (.mg) as the parent of the folder does not exists.\n"
"Invalid value: '{}'".format(args.save))
os.mkdir(projectFolder)
r.saveAs(args.save)

self.engine.load(os.path.normpath(url))

@Slot(str, result=str)
Expand Down
5 changes: 4 additions & 1 deletion meshroom/ui/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,10 @@ def loadUrl(self, url):

@Slot(QUrl)
def saveAs(self, url):
localFile = url.toLocalFile()
if isinstance(url, (str)):
localFile = url
else:
localFile = url.toLocalFile()
# ensure file is saved with ".mg" extension
if os.path.splitext(localFile)[-1] != ".mg":
localFile += ".mg"
Expand Down
16 changes: 3 additions & 13 deletions meshroom/ui/reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,19 +648,9 @@ def importImagesFromFolder(self, path, recursive=False):
recursive: List files in folders recursively.

"""
images = []
paths = []
if isinstance(path, (list, tuple)):
paths = path
else:
paths.append(path)
for p in paths:
if os.path.isdir(p): # get folder content
images.extend(multiview.findFilesByTypeInFolder(p, recursive))
elif multiview.isImageFile(p):
images.append(p)
if images:
self.buildIntrinsics(self.cameraInit, images)
filesByType = multiview.findFilesByTypeInFolder(path, recursive)
if filesByType.images:
self.buildIntrinsics(self.cameraInit, filesByType.images)

def importImagesAsync(self, images, cameraInit):
""" Add the given list of images to the Reconstruction. """
Expand Down