diff --git a/meshroom/multiview.py b/meshroom/multiview.py index 73fe6fa5f3..99983a6661 100644 --- a/meshroom/multiview.py +++ b/meshroom/multiview.py @@ -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 diff --git a/meshroom/ui/app.py b/meshroom/ui/app.py index 5e6589a364..b8c124d659 100644 --- a/meshroom/ui/app.py +++ b/meshroom/ui/app.py @@ -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) @@ -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) diff --git a/meshroom/ui/graph.py b/meshroom/ui/graph.py index f735882cde..566c122c58 100644 --- a/meshroom/ui/graph.py +++ b/meshroom/ui/graph.py @@ -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" diff --git a/meshroom/ui/reconstruction.py b/meshroom/ui/reconstruction.py index 085508c449..cc77a44bb7 100755 --- a/meshroom/ui/reconstruction.py +++ b/meshroom/ui/reconstruction.py @@ -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. """