mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-05-18 03:26:30 +02:00
[multiview] unify image files helper functions
Move everything related to image files detection to the 'multiview' module.
This commit is contained in:
parent
88c43fe316
commit
1cc2561a21
2 changed files with 24 additions and 26 deletions
|
@ -2,22 +2,29 @@
|
||||||
__version__ = "1.0"
|
__version__ = "1.0"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import fnmatch
|
|
||||||
import re
|
|
||||||
|
|
||||||
from meshroom.core.graph import Graph, GraphModification
|
from meshroom.core.graph import Graph, GraphModification
|
||||||
|
|
||||||
|
# Supported image extensions
|
||||||
|
imageExtensions = ('.jpg', '.jpeg', '.tif', '.tiff', '.png', '.exr', '.rw2', '.cr2', '.nef', '.arw')
|
||||||
|
|
||||||
def findFiles(folder, patterns):
|
|
||||||
rules = [re.compile(fnmatch.translate(pattern), re.IGNORECASE) for pattern in patterns]
|
def isImageFile(filepath):
|
||||||
outFiles = []
|
""" Return whether filepath is a path to an image file supported by Meshroom. """
|
||||||
for name in os.listdir(folder):
|
return os.path.splitext(filepath)[1].lower() in imageExtensions
|
||||||
for rule in rules:
|
|
||||||
if rule.match(name):
|
|
||||||
filepath = os.path.join(folder, name)
|
def findImageFiles(folder):
|
||||||
outFiles.append(filepath)
|
"""
|
||||||
break
|
Return all files that are images in 'folder' based on their extensions.
|
||||||
return outFiles
|
|
||||||
|
Args:
|
||||||
|
folder (str): the folder to look into
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: the list of image files.
|
||||||
|
"""
|
||||||
|
return [os.path.join(folder, filename) for filename in os.listdir(folder) if isImageFile(filename)]
|
||||||
|
|
||||||
|
|
||||||
def photogrammetry(inputFolder='', inputImages=(), inputViewpoints=(), inputIntrinsics=(), output=''):
|
def photogrammetry(inputFolder='', inputImages=(), inputViewpoints=(), inputIntrinsics=(), output=''):
|
||||||
|
@ -38,7 +45,7 @@ def photogrammetry(inputFolder='', inputImages=(), inputViewpoints=(), inputIntr
|
||||||
sfmNodes, mvsNodes = photogrammetryPipeline(graph)
|
sfmNodes, mvsNodes = photogrammetryPipeline(graph)
|
||||||
cameraInit = sfmNodes[0]
|
cameraInit = sfmNodes[0]
|
||||||
if inputFolder:
|
if inputFolder:
|
||||||
images = findFiles(inputFolder, ['*.jpg', '*.png'])
|
images = findImageFiles(inputFolder)
|
||||||
cameraInit.viewpoints.extend([{'path': image} for image in images])
|
cameraInit.viewpoints.extend([{'path': image} for image in images])
|
||||||
if inputImages:
|
if inputImages:
|
||||||
cameraInit.viewpoints.extend([{'path': image} for image in inputImages])
|
cameraInit.viewpoints.extend([{'path': image} for image in inputImages])
|
||||||
|
|
|
@ -99,8 +99,7 @@ class LiveSfmManager(QObject):
|
||||||
to include those images to the reconstruction.
|
to include those images to the reconstruction.
|
||||||
"""
|
"""
|
||||||
# Get all new images in the watched folder
|
# Get all new images in the watched folder
|
||||||
filesInFolder = [os.path.join(self._folder, f) for f in os.listdir(self._folder)]
|
imagesInFolder = multiview.findImageFiles(self._folder)
|
||||||
imagesInFolder = [f for f in filesInFolder if Reconstruction.isImageFile(f)]
|
|
||||||
newImages = set(imagesInFolder).difference(self.allImages)
|
newImages = set(imagesInFolder).difference(self.allImages)
|
||||||
for imagePath in newImages:
|
for imagePath in newImages:
|
||||||
# print('[LiveSfmManager] New image file : {}'.format(imagePath))
|
# print('[LiveSfmManager] New image file : {}'.format(imagePath))
|
||||||
|
@ -160,8 +159,6 @@ class Reconstruction(UIGraph):
|
||||||
Specialization of a UIGraph designed to manage a 3D reconstruction.
|
Specialization of a UIGraph designed to manage a 3D reconstruction.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
imageExtensions = ('.jpg', '.jpeg', '.tif', '.tiff', '.png', '.exr', '.rw2', '.cr2', '.nef', '.arw')
|
|
||||||
|
|
||||||
def __init__(self, graphFilepath='', parent=None):
|
def __init__(self, graphFilepath='', parent=None):
|
||||||
super(Reconstruction, self).__init__(graphFilepath, parent)
|
super(Reconstruction, self).__init__(graphFilepath, parent)
|
||||||
self._buildingIntrinsics = False
|
self._buildingIntrinsics = False
|
||||||
|
@ -332,11 +329,6 @@ class Reconstruction(UIGraph):
|
||||||
"""
|
"""
|
||||||
self.importImages(self.getImageFilesFromDrop(drop), cameraInit)
|
self.importImages(self.getImageFilesFromDrop(drop), cameraInit)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def isImageFile(filepath):
|
|
||||||
""" Return whether filepath is a path to an image file supported by Meshroom. """
|
|
||||||
return os.path.splitext(filepath)[1].lower() in Reconstruction.imageExtensions
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getImageFilesFromDrop(drop):
|
def getImageFilesFromDrop(drop):
|
||||||
urls = drop.property("urls")
|
urls = drop.property("urls")
|
||||||
|
@ -345,10 +337,9 @@ class Reconstruction(UIGraph):
|
||||||
for url in urls:
|
for url in urls:
|
||||||
localFile = url.toLocalFile()
|
localFile = url.toLocalFile()
|
||||||
if os.path.isdir(localFile): # get folder content
|
if os.path.isdir(localFile): # get folder content
|
||||||
files = [os.path.join(localFile, f) for f in os.listdir(localFile)]
|
images.extend(multiview.findImageFiles(localFile))
|
||||||
else:
|
elif multiview.isImageFile(localFile):
|
||||||
files = [localFile]
|
images.append(localFile)
|
||||||
images.extend([f for f in files if Reconstruction.isImageFile(f)])
|
|
||||||
return images
|
return images
|
||||||
|
|
||||||
def importImages(self, images, cameraInit):
|
def importImages(self, images, cameraInit):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue