mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-05-17 19:16:26 +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"
|
||||
|
||||
import os
|
||||
import fnmatch
|
||||
import re
|
||||
|
||||
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]
|
||||
outFiles = []
|
||||
for name in os.listdir(folder):
|
||||
for rule in rules:
|
||||
if rule.match(name):
|
||||
filepath = os.path.join(folder, name)
|
||||
outFiles.append(filepath)
|
||||
break
|
||||
return outFiles
|
||||
|
||||
def isImageFile(filepath):
|
||||
""" Return whether filepath is a path to an image file supported by Meshroom. """
|
||||
return os.path.splitext(filepath)[1].lower() in imageExtensions
|
||||
|
||||
|
||||
def findImageFiles(folder):
|
||||
"""
|
||||
Return all files that are images in 'folder' based on their extensions.
|
||||
|
||||
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=''):
|
||||
|
@ -38,7 +45,7 @@ def photogrammetry(inputFolder='', inputImages=(), inputViewpoints=(), inputIntr
|
|||
sfmNodes, mvsNodes = photogrammetryPipeline(graph)
|
||||
cameraInit = sfmNodes[0]
|
||||
if inputFolder:
|
||||
images = findFiles(inputFolder, ['*.jpg', '*.png'])
|
||||
images = findImageFiles(inputFolder)
|
||||
cameraInit.viewpoints.extend([{'path': image} for image in images])
|
||||
if inputImages:
|
||||
cameraInit.viewpoints.extend([{'path': image} for image in inputImages])
|
||||
|
|
|
@ -99,8 +99,7 @@ class LiveSfmManager(QObject):
|
|||
to include those images to the reconstruction.
|
||||
"""
|
||||
# Get all new images in the watched folder
|
||||
filesInFolder = [os.path.join(self._folder, f) for f in os.listdir(self._folder)]
|
||||
imagesInFolder = [f for f in filesInFolder if Reconstruction.isImageFile(f)]
|
||||
imagesInFolder = multiview.findImageFiles(self._folder)
|
||||
newImages = set(imagesInFolder).difference(self.allImages)
|
||||
for imagePath in newImages:
|
||||
# print('[LiveSfmManager] New image file : {}'.format(imagePath))
|
||||
|
@ -160,8 +159,6 @@ class Reconstruction(UIGraph):
|
|||
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):
|
||||
super(Reconstruction, self).__init__(graphFilepath, parent)
|
||||
self._buildingIntrinsics = False
|
||||
|
@ -332,11 +329,6 @@ class Reconstruction(UIGraph):
|
|||
"""
|
||||
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
|
||||
def getImageFilesFromDrop(drop):
|
||||
urls = drop.property("urls")
|
||||
|
@ -345,10 +337,9 @@ class Reconstruction(UIGraph):
|
|||
for url in urls:
|
||||
localFile = url.toLocalFile()
|
||||
if os.path.isdir(localFile): # get folder content
|
||||
files = [os.path.join(localFile, f) for f in os.listdir(localFile)]
|
||||
else:
|
||||
files = [localFile]
|
||||
images.extend([f for f in files if Reconstruction.isImageFile(f)])
|
||||
images.extend(multiview.findImageFiles(localFile))
|
||||
elif multiview.isImageFile(localFile):
|
||||
images.append(localFile)
|
||||
return images
|
||||
|
||||
def importImages(self, images, cameraInit):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue