mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-06-06 21:01:59 +02:00
Merge remote-tracking branch 'origin/develop' into dev_memoryManagement
This commit is contained in:
commit
bf747f69d6
8 changed files with 92 additions and 64 deletions
|
@ -35,19 +35,25 @@ graph.update()
|
|||
|
||||
if args.node:
|
||||
# Execute the node
|
||||
node = graph.node(args.node)
|
||||
node = graph.findNode(args.node)
|
||||
submittedStatuses = [Status.SUBMITTED_LOCAL, Status.RUNNING]
|
||||
if not args.extern:
|
||||
submittedStatuses.append(Status.SUBMITTED_EXTERN)
|
||||
if not args.forceStatus and not args.forceCompute:
|
||||
for range in node.ranges:
|
||||
if node.status[range.iteration].status in submittedStatuses:
|
||||
print('Error: Node is already submitted with status "{}". See file: "{}"'.format(node.status[range.iteration].status.name, node.statusFile(range)))
|
||||
exit(-1)
|
||||
if not node.hasStatus(Status.SUCCESS) or args.forceCompute:
|
||||
if args.iteration != -1:
|
||||
node.processIteration(args.iteration)
|
||||
chunks = [node.chunks[args.iteration]]
|
||||
else:
|
||||
chunks = node.chunks
|
||||
for chunk in chunks:
|
||||
if chunk.status.status in submittedStatuses:
|
||||
print('Error: Node is already submitted with status "{}". See file: "{}"'.format(chunk.status.status.name, chunk.statusFile()))
|
||||
# exit(-1)
|
||||
if args.iteration != -1:
|
||||
chunk = node.chunks[args.iteration]
|
||||
if chunk.status.status != Status.SUCCESS or args.forceCompute:
|
||||
chunk.process()
|
||||
else:
|
||||
if not node.hasStatus(Status.SUCCESS) or args.forceCompute:
|
||||
node.process()
|
||||
else:
|
||||
if args.iteration != -1:
|
||||
|
|
|
@ -43,7 +43,7 @@ parser.add_argument("--verbose", help="Print full status information",
|
|||
args = parser.parse_args()
|
||||
|
||||
if not os.path.exists(args.graphFile):
|
||||
print('ERROR: No graph file "{}".'.format(args.node, args.graphFile))
|
||||
print('ERROR: No graph file "{}".'.format(args.graphFile))
|
||||
exit(-1)
|
||||
|
||||
graph = pg.loadGraph(args.graphFile)
|
||||
|
@ -53,10 +53,7 @@ graph.updateStatisticsFromCache()
|
|||
|
||||
nodes = []
|
||||
if args.node:
|
||||
if args.node not in graph.nodes.keys():
|
||||
print('ERROR: node "{}" does not exist in file "{}".'.format(args.node, args.graphFile))
|
||||
exit(-1)
|
||||
nodes = [graph.node(args.node)]
|
||||
nodes = [graph.findNode(args.node)]
|
||||
else:
|
||||
startNodes = None
|
||||
if args.graph:
|
||||
|
|
|
@ -44,7 +44,7 @@ class ListAttribute(Attribute):
|
|||
|
||||
def validateValue(self, value):
|
||||
if not (isinstance(value, collections.Iterable) and isinstance(value, basestring)):
|
||||
raise ValueError('ListAttribute only supports iterable input values.')
|
||||
raise ValueError('ListAttribute only supports iterable input values (param:{}, value:{}, type:{})'.format(self.name, value, type(value)))
|
||||
return value
|
||||
|
||||
|
||||
|
@ -61,7 +61,7 @@ class GroupAttribute(Attribute):
|
|||
|
||||
def validateValue(self, value):
|
||||
if not (isinstance(value, collections.Iterable) and isinstance(value, basestring)):
|
||||
raise ValueError('GroupAttribute only supports iterable input values.')
|
||||
raise ValueError('GroupAttribute only supports iterable input values (param:{}, value:{}, type:{})'.format(self.name, value, type(value)))
|
||||
return value
|
||||
|
||||
def retrieveChildrenUids(self):
|
||||
|
@ -88,7 +88,7 @@ class File(Attribute):
|
|||
|
||||
def validateValue(self, value):
|
||||
if not isinstance(value, basestring):
|
||||
raise ValueError('File only supports string input: "{}".'.format(value))
|
||||
raise ValueError('File only supports string input (param:{}, value:{}, type:{})'.format(self.name, value, type(value)))
|
||||
return os.path.normpath(value).replace('\\', '/') if value else ''
|
||||
|
||||
|
||||
|
@ -102,7 +102,7 @@ class BoolParam(Param):
|
|||
try:
|
||||
return bool(value)
|
||||
except:
|
||||
raise ValueError('BoolParam only supports bool value.')
|
||||
raise ValueError('BoolParam only supports bool value (param:{}, value:{}, type:{})'.format(self.name, value, type(value)))
|
||||
|
||||
|
||||
class IntParam(Param):
|
||||
|
@ -116,7 +116,7 @@ class IntParam(Param):
|
|||
try:
|
||||
return int(value)
|
||||
except:
|
||||
raise ValueError('IntParam only supports int value.')
|
||||
raise ValueError('IntParam only supports int value (param:{}, value:{}, type:{})'.format(self.name, value, type(value)))
|
||||
|
||||
range = Property(Variant, lambda self: self._range, constant=True)
|
||||
|
||||
|
@ -132,7 +132,7 @@ class FloatParam(Param):
|
|||
try:
|
||||
return float(value)
|
||||
except:
|
||||
raise ValueError('FloatParam only supports float value.')
|
||||
raise ValueError('FloatParam only supports float value (param:{}, value:{}, type:{})'.format(self.name, value, type(value)))
|
||||
|
||||
range = Property(Variant, lambda self: self._range, constant=True)
|
||||
|
||||
|
@ -152,7 +152,7 @@ class ChoiceParam(Param):
|
|||
newValues = [value]
|
||||
else:
|
||||
if not isinstance(value, collections.Iterable):
|
||||
raise ValueError('Non exclusive ChoiceParam value "{}" should be iterable.'.format(value))
|
||||
raise ValueError('Non exclusive ChoiceParam value should be iterable (param:{}, value:{}, type:{})'.format(self.name, value, type(value)))
|
||||
newValues = value
|
||||
for newValue in newValues:
|
||||
t = type(self._values[0]) # cast to value type
|
||||
|
@ -174,7 +174,7 @@ class StringParam(Param):
|
|||
|
||||
def validateValue(self, value):
|
||||
if not isinstance(value, basestring):
|
||||
raise ValueError('StringParam value "{}" should be a string.'.format(value))
|
||||
raise ValueError('StringParam value should be a string (param:{}, value:{}, type:{})'.format(self.name, value, type(value)))
|
||||
return value
|
||||
|
||||
|
||||
|
|
|
@ -692,7 +692,7 @@ class Node(BaseObject):
|
|||
return self.graph.getDepth(self)
|
||||
|
||||
def toDict(self):
|
||||
attributes = {k: v.getExportValue() for k, v in self._attributes.objects.items()}
|
||||
attributes = {k: v.getExportValue() for k, v in self._attributes.objects.items() if v.isInput}
|
||||
return {
|
||||
'nodeType': self.nodeType,
|
||||
'packageName': self.packageName,
|
||||
|
|
|
@ -24,13 +24,13 @@ def photogrammetryPipeline(output='', inputFolder='', inputImages=[], inputViewp
|
|||
cameraInit = graph.addNewNode('CameraInit')
|
||||
if inputFolder:
|
||||
images = findFiles(inputFolder, ['*.jpg', '*.png'])
|
||||
cameraInit.viewpoints.extend([{'image': image} for image in images])
|
||||
cameraInit.viewpoints.extend([{'path': image} for image in images])
|
||||
if inputImages:
|
||||
cameraInit.viewpoints.extend([{'image': image} for image in inputImages])
|
||||
cameraInit.viewpoints.extend([{'path': image} for image in inputImages])
|
||||
if inputViewpoints:
|
||||
cameraInit.viewpoints.extend(inputViewpoints)
|
||||
featureExtraction = graph.addNewNode('FeatureExtraction',
|
||||
input=cameraInit.outputSfm)
|
||||
input=cameraInit.output)
|
||||
imageMatching = graph.addNewNode('ImageMatching',
|
||||
input=featureExtraction.input,
|
||||
featuresDirectory=featureExtraction.output,
|
||||
|
|
|
@ -12,21 +12,35 @@ from meshroom.core.graph import GraphModification
|
|||
|
||||
|
||||
Viewpoint = [
|
||||
desc.IntParam(name="id", label="Id", description="Image UID", value=-1, uid=[0], range=(0, 200, 1)),
|
||||
desc.File(name="image", label="Image", description="Image Filepath", value="", uid=[0, 1]),
|
||||
desc.IntParam(name="viewId", label="Id", description="Image UID", value=-1, uid=[0], range=(0, 200, 1)),
|
||||
desc.IntParam(name="poseId", label="Pose Id", description="Pose Id", value=-1, uid=[0], range=(0, 200, 1)),
|
||||
desc.File(name="path", label="Image Path", description="Image Filepath", value="", uid=[0, 1]),
|
||||
desc.IntParam(name="intrinsicId", label="Intrinsic", description="Internal Camera Parameters", value=-1, uid=[0], range=(0, 200, 1)),
|
||||
desc.IntParam(name="rigId", label="Rig", description="Rig Parameters", value=-1, uid=[0], range=(0, 200, 1)),
|
||||
desc.IntParam(name="rigSubPoseId", label="Rig Sub-Pose", description="Rig Sub-Pose Parameters", value=-1, uid=[0], range=(0, 200, 1)),
|
||||
desc.IntParam(name="subPoseId", label="Rig Sub-Pose", description="Rig Sub-Pose Parameters", value=-1, uid=[0], range=(0, 200, 1)),
|
||||
]
|
||||
|
||||
Intrinsic = [
|
||||
desc.IntParam(name="id", label="Id", description="Intrinsic UID", value=-1, uid=[0], range=(0, 200, 1)),
|
||||
desc.IntParam(name="initialFocalLength", label="Initial Focal Length", description="Initial Guess on the Focal Length", value=-1, uid=[0], range=(0, 200, 1)),
|
||||
desc.IntParam(name="focalLength", label="Focal Length", description="Known/Calibrated Focal Length", value=-1, uid=[0], range=(0, 200, 1)),
|
||||
desc.ChoiceParam(name="cameraType", label="Camera Type", description="Camera Type", value="", values=['', 'pinhole', 'radial1', 'radial3', 'brown', 'fisheye4'], exclusive=True, uid=[0]),
|
||||
desc.StringParam(name="deviceMake", label="Make", description="Camera Make", value="", uid=[]),
|
||||
desc.StringParam(name="deviceModel", label="Model", description="Camera Model", value="", uid=[]),
|
||||
desc.StringParam(name="sensorWidth", label="Sensor Width", description="Camera Sensor Width", value="", uid=[0]),
|
||||
desc.IntParam(name="intrinsicId", label="Id", description="Intrinsic UID", value=-1, uid=[0], range=(0, 200, 1)),
|
||||
desc.FloatParam(name="pxInitialFocalLength", label="Initial Focal Length", description="Initial Guess on the Focal Length", value=-1.0, uid=[0], range=(0.0, 200.0, 1.0)),
|
||||
desc.FloatParam(name="pxFocalLength", label="Focal Length", description="Known/Calibrated Focal Length", value=-1.0, uid=[0], range=(0.0, 200.0, 1.0)),
|
||||
desc.ChoiceParam(name="type", label="Camera Type", description="Camera Type", value="", values=['', 'pinhole', 'radial1', 'radial3', 'brown', 'fisheye4'], exclusive=True, uid=[0]),
|
||||
# desc.StringParam(name="deviceMake", label="Make", description="Camera Make", value="", uid=[]),
|
||||
# desc.StringParam(name="deviceModel", label="Model", description="Camera Model", value="", uid=[]),
|
||||
# desc.StringParam(name="sensorWidth", label="Sensor Width", description="Camera Sensor Width", value="", uid=[0]),
|
||||
desc.IntParam(name="width", label="Width", description="Image Width", value=0, uid=[], range=(0, 10000, 1)),
|
||||
desc.IntParam(name="height", label="Height", description="Image Height", value=0, uid=[], range=(0, 10000, 1)),
|
||||
desc.StringParam(name="serialNumber", label="Serial Number", description="Device Serial Number (camera and lens combined)", value="", uid=[]),
|
||||
desc.GroupAttribute(name="principalPoint", label="Principal Point", description="", groupDesc=[
|
||||
desc.IntParam(name="x", label="x", description="", value=0, uid=[], range=(0, 10000, 1)),
|
||||
desc.IntParam(name="y", label="y", description="", value=0, uid=[], range=(0, 10000, 1)),
|
||||
]),
|
||||
desc.ListAttribute(
|
||||
name="distortionParams",
|
||||
elementDesc=desc.FloatParam(name="p", label="", description="", value=0.0, uid=[0], range=(-0.1, 0.1, 0.01)),
|
||||
label="Distortion Params",
|
||||
description="Distortion Parameters",
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
|
@ -37,16 +51,14 @@ class CameraInit(desc.CommandLineNode):
|
|||
inputs = [
|
||||
desc.ListAttribute(
|
||||
name="viewpoints",
|
||||
elementDesc=desc.GroupAttribute(name="viewpoint", label="Viewpoint", description="", groupDesc=Viewpoint,
|
||||
group="allParams"),
|
||||
elementDesc=desc.GroupAttribute(name="viewpoint", label="Viewpoint", description="", groupDesc=Viewpoint),
|
||||
label="Viewpoints",
|
||||
description="Input viewpoints",
|
||||
group="",
|
||||
),
|
||||
desc.ListAttribute(
|
||||
name="intrinsics",
|
||||
elementDesc=desc.GroupAttribute(name="intrinsic", label="Intrinsic", description="", groupDesc=Intrinsic,
|
||||
group="allParams"),
|
||||
elementDesc=desc.GroupAttribute(name="intrinsic", label="Intrinsic", description="", groupDesc=Intrinsic),
|
||||
label="Intrinsics",
|
||||
description="Camera Intrinsics",
|
||||
group="",
|
||||
|
@ -75,9 +87,9 @@ class CameraInit(desc.CommandLineNode):
|
|||
uid=[0],
|
||||
),
|
||||
desc.StringParam(
|
||||
name='defaultIntrinsics',
|
||||
label='Default Intrinsics',
|
||||
description='''Intrinsics Kmatrix "f;0;ppx;0;f;ppy;0;0;1".''',
|
||||
name='defaultIntrinsic',
|
||||
label='Default Intrinsic',
|
||||
description='''Intrinsic K matrix "f;0;ppx;0;f;ppy;0;0;1".''',
|
||||
value='',
|
||||
uid=[0],
|
||||
),
|
||||
|
@ -127,17 +139,9 @@ class CameraInit(desc.CommandLineNode):
|
|||
name='output',
|
||||
label='Output',
|
||||
description='''Output SfMData.''',
|
||||
value='{cache}/{nodeType}/{uid0}', # TODO
|
||||
value='{cache}/{nodeType}/{uid0}/cameraInit.sfm',
|
||||
uid=[],
|
||||
),
|
||||
desc.File(
|
||||
name='outputSfm',
|
||||
label='Output SfM',
|
||||
description='''''',
|
||||
value='{cache}/{nodeType}/{uid0}/sfm_data.json',
|
||||
uid=[],
|
||||
group='', # not a command line argument
|
||||
)
|
||||
]
|
||||
|
||||
def updateInternals(self, node):
|
||||
|
@ -166,41 +170,60 @@ class CameraInit(desc.CommandLineNode):
|
|||
subprocess.wait()
|
||||
if subprocess.returncode != 0:
|
||||
logging.warning('CameraInit: Error on updateInternals of node "{}".'.format(node.name))
|
||||
|
||||
# Reload result of aliceVision_cameraInit
|
||||
cameraInitSfM = localCmdVars['outputValue']
|
||||
jsonData = open(cameraInitSfM, 'r').read()
|
||||
data = json.loads(jsonData)
|
||||
|
||||
intrinsicsKeys = [i.name for i in Intrinsic]
|
||||
intrinsics = [{k: v for k, v in item.items() if k in intrinsicsKeys} for item in data.get("intrinsics", [])]
|
||||
for intrinsic in intrinsics:
|
||||
pp = intrinsic['principalPoint']
|
||||
intrinsic['principalPoint'] = {}
|
||||
intrinsic['principalPoint']['x'] = pp[0]
|
||||
intrinsic['principalPoint']['y'] = pp[1]
|
||||
# print('intrinsics:', intrinsics)
|
||||
viewsKeys = [v.name for v in Viewpoint]
|
||||
views = [{k: v for k, v in item.items() if k in viewsKeys} for item in data.get("views", [])]
|
||||
# print('views:', views)
|
||||
|
||||
with GraphModification(node.graph):
|
||||
node.viewpoints.value = views
|
||||
node.intrinsics.value = intrinsics
|
||||
node.attribute("_viewpointsUid").value = node.viewpoints.uid(1)
|
||||
|
||||
except Exception:
|
||||
logging.warning('CameraInit: Error on updateInternals of node "{}".'.format(node.name))
|
||||
raise
|
||||
finally:
|
||||
node._cmdVars = origCmdVars
|
||||
shutil.rmtree(tmpCache)
|
||||
# TODO: reload result of aliceVision_cameraInit
|
||||
# cameraInitSfM = node.viewpointsFile # localCmdVars['outputSfMValue']
|
||||
# jsonData = open(cameraInitSfM, 'r').read()
|
||||
# data = json.loads(jsonData)
|
||||
# with GraphModification(node.graph):
|
||||
# node.viewpoints.value = data.get("views", [])
|
||||
# node.intrinsics.value = data.get("intrinsics", [])
|
||||
|
||||
node.attribute("_viewpointsUid").value = node.viewpoints.uid(1)
|
||||
|
||||
def createViewpointsFile_new(self, node):
|
||||
def createViewpointsFile(self, node):
|
||||
if node.viewpoints:
|
||||
intrinsics = node.intrinsics.getPrimitiveValue(exportDefault=True)
|
||||
for intrinsic in intrinsics:
|
||||
intrinsic['principalPoint'] = [intrinsic['principalPoint']['x'], intrinsic['principalPoint']['y']]
|
||||
sfmData = {
|
||||
"version": [1, 0, 0],
|
||||
"views": node.viewpoints.getPrimitiveValue(exportDefault=False),
|
||||
"intrinsics": node.intrinsics.getPrimitiveValue(exportDefault=False),
|
||||
"intrinsics": intrinsics,
|
||||
"featureFolder": "",
|
||||
"matchingFolder": "",
|
||||
}
|
||||
node.viewpointsFile = '{cache}/{nodeType}/{uid0}/viewpoints.json'.format(**node._cmdVars)
|
||||
with open(node.viewpointsFile, 'w') as f:
|
||||
f.write(json.dumps(sfmData, indent=4))
|
||||
# python3: json.dumps(node.viewpoints, f, indent=4)
|
||||
|
||||
def createViewpointsFile(self, node):
|
||||
def createViewpointsFile_old(self, node):
|
||||
"""
|
||||
Temporary compatibility method.
|
||||
"""
|
||||
if node.viewpoints:
|
||||
sfmData = {
|
||||
"resources": [v.get("image", "") for v in node.viewpoints.getPrimitiveValue(exportDefault=False)],
|
||||
"resources": [v.get("path", "") for v in node.viewpoints.getPrimitiveValue(exportDefault=False)],
|
||||
}
|
||||
node.viewpointsFile = '{cache}/{nodeType}/{uid0}/viewpoints.json'.format(**node._cmdVars)
|
||||
with open(node.viewpointsFile, 'w') as f:
|
||||
|
@ -210,7 +233,7 @@ class CameraInit(desc.CommandLineNode):
|
|||
def buildCommandLine(self, chunk):
|
||||
cmd = desc.CommandLineNode.buildCommandLine(self, chunk)
|
||||
if len(chunk.node.viewpoints):
|
||||
cmd += ' --jsonFile ' + chunk.node.viewpointsFile
|
||||
cmd += ' --input ' + chunk.node.viewpointsFile
|
||||
return cmd
|
||||
|
||||
def processChunk(self, chunk):
|
||||
|
|
|
@ -5,6 +5,7 @@ class DepthMap(desc.CommandLineNode):
|
|||
commandLine = 'aliceVision_depthMapEstimation {allParams}'
|
||||
gpu = desc.Level.INTENSIVE
|
||||
parallelization = desc.Parallelization(inputListParamName='viewpoints', blockSize=3)
|
||||
commandLineRange = '--rangeStart {rangeStart} --rangeSize {rangeBlockSize}'
|
||||
|
||||
inputs = [
|
||||
desc.File(
|
||||
|
|
|
@ -5,6 +5,7 @@ class DepthMapFilter(desc.CommandLineNode):
|
|||
commandLine = 'aliceVision_depthMapFiltering {allParams}'
|
||||
gpu = desc.Level.NORMAL
|
||||
parallelization = desc.Parallelization(inputListParamName='viewpoints', blockSize=10)
|
||||
commandLineRange = '--rangeStart {rangeStart} --rangeSize {rangeBlockSize}'
|
||||
|
||||
inputs = [
|
||||
desc.File(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue