mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-05-03 12:16:51 +02:00
[nodes] Cleanup CameraInit
* remove non user pertinent parameters * revamp old updateInternals into buildIntrinsics method: * works with node's current values + optional new images * does not update the graph, making it thread safe and does not break undo/redo when used from UI * returns updated intrinsics and views instead
This commit is contained in:
parent
0e69d92a25
commit
2a029834db
1 changed files with 22 additions and 74 deletions
|
@ -1,6 +1,4 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
from collections import OrderedDict
|
|
||||||
import json
|
import json
|
||||||
import psutil
|
import psutil
|
||||||
import shutil
|
import shutil
|
||||||
|
@ -8,7 +6,6 @@ import tempfile
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from meshroom.core import desc
|
from meshroom.core import desc
|
||||||
from meshroom.core.graph import GraphModification
|
|
||||||
|
|
||||||
|
|
||||||
Viewpoint = [
|
Viewpoint = [
|
||||||
|
@ -70,51 +67,6 @@ class CameraInit(desc.CommandLineNode):
|
||||||
value=os.environ.get('ALICEVISION_SENSOR_DB', ''),
|
value=os.environ.get('ALICEVISION_SENSOR_DB', ''),
|
||||||
uid=[],
|
uid=[],
|
||||||
),
|
),
|
||||||
desc.IntParam(
|
|
||||||
name='defaultFocalLengthPix',
|
|
||||||
label='Default Focal Length Pix',
|
|
||||||
description='''Focal length in pixels.''',
|
|
||||||
value=-1,
|
|
||||||
range=(-sys.maxsize, sys.maxsize, 1),
|
|
||||||
uid=[0],
|
|
||||||
),
|
|
||||||
desc.IntParam(
|
|
||||||
name='defaultSensorWidth',
|
|
||||||
label='Default Sensor Width',
|
|
||||||
description='''Sensor width in mm.''',
|
|
||||||
value=-1,
|
|
||||||
range=(-sys.maxsize, sys.maxsize, 1),
|
|
||||||
uid=[0],
|
|
||||||
),
|
|
||||||
desc.StringParam(
|
|
||||||
name='defaultIntrinsic',
|
|
||||||
label='Default Intrinsic',
|
|
||||||
description='''Intrinsic K matrix "f;0;ppx;0;f;ppy;0;0;1".''',
|
|
||||||
value='',
|
|
||||||
uid=[0],
|
|
||||||
),
|
|
||||||
desc.ChoiceParam(
|
|
||||||
name='defaultCameraModel',
|
|
||||||
label='Default Camera Model',
|
|
||||||
description='''Camera model type (pinhole, radial1, radial3, brown, fisheye4).''',
|
|
||||||
value='',
|
|
||||||
values=['', 'pinhole', 'radial1', 'radial3', 'brown', 'fisheye4'],
|
|
||||||
exclusive=True,
|
|
||||||
uid=[0],
|
|
||||||
),
|
|
||||||
desc.ChoiceParam(
|
|
||||||
name='groupCameraModel',
|
|
||||||
label='Group Camera Model',
|
|
||||||
description='''* 0: each view have its own camera intrinsic parameters '''
|
|
||||||
'''* 1: view share camera intrinsic parameters based on metadata, '''
|
|
||||||
'''if no metadata each view has its own camera intrinsic parameters '''
|
|
||||||
'''* 2: view share camera intrinsic parameters based on metadata, '''
|
|
||||||
'''if no metadata they are grouped by folder''',
|
|
||||||
value=1,
|
|
||||||
values=[0, 1, 2],
|
|
||||||
exclusive=True,
|
|
||||||
uid=[0],
|
|
||||||
),
|
|
||||||
desc.ChoiceParam(
|
desc.ChoiceParam(
|
||||||
name='verboseLevel',
|
name='verboseLevel',
|
||||||
label='Verbose Level',
|
label='Verbose Level',
|
||||||
|
@ -124,14 +76,6 @@ class CameraInit(desc.CommandLineNode):
|
||||||
exclusive=True,
|
exclusive=True,
|
||||||
uid=[],
|
uid=[],
|
||||||
),
|
),
|
||||||
desc.StringParam(
|
|
||||||
name='_viewpointsUid',
|
|
||||||
label='Internal Intrinsics Uid',
|
|
||||||
description='',
|
|
||||||
value='',
|
|
||||||
uid=[],
|
|
||||||
group='',
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
outputs = [
|
outputs = [
|
||||||
|
@ -144,13 +88,17 @@ class CameraInit(desc.CommandLineNode):
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
def updateInternals(self, node):
|
def buildIntrinsics(self, node, additionalViews=()):
|
||||||
if not node.viewpoints:
|
""" Build intrinsics from node current views and optional additional views
|
||||||
return
|
|
||||||
lastViewpointsUid = node.attribute("_viewpointsUid").value
|
|
||||||
if lastViewpointsUid == node.viewpoints.uid(1):
|
|
||||||
return
|
|
||||||
|
|
||||||
|
Args:
|
||||||
|
node: the CameraInit node instance to build intrinsics for
|
||||||
|
additionalViews: (optional) the new views (list of path to images) to add to the node's viewpoints
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The updated views and intrinsics as two separate lists
|
||||||
|
"""
|
||||||
|
assert isinstance(node.desc, CameraInit)
|
||||||
origCmdVars = node._cmdVars.copy()
|
origCmdVars = node._cmdVars.copy()
|
||||||
# Python3: with tempfile.TemporaryDirectory(prefix="Meshroom_CameraInit") as tmpCache
|
# Python3: with tempfile.TemporaryDirectory(prefix="Meshroom_CameraInit") as tmpCache
|
||||||
tmpCache = tempfile.mkdtemp()
|
tmpCache = tempfile.mkdtemp()
|
||||||
|
@ -162,14 +110,14 @@ class CameraInit(desc.CommandLineNode):
|
||||||
node._cmdVars = localCmdVars
|
node._cmdVars = localCmdVars
|
||||||
try:
|
try:
|
||||||
os.makedirs(os.path.join(tmpCache, node.internalFolder))
|
os.makedirs(os.path.join(tmpCache, node.internalFolder))
|
||||||
self.createViewpointsFile(node)
|
self.createViewpointsFile(node, additionalViews)
|
||||||
cmd = self.buildCommandLine(node.chunks[0])
|
cmd = self.buildCommandLine(node.chunks[0])
|
||||||
# logging.debug(' - commandLine:', cmd)
|
# logging.debug(' - commandLine:', cmd)
|
||||||
subprocess = psutil.Popen(cmd, stdout=None, stderr=None, shell=True)
|
subprocess = psutil.Popen(cmd, stdout=None, stderr=None, shell=True)
|
||||||
stdout, stderr = subprocess.communicate()
|
stdout, stderr = subprocess.communicate()
|
||||||
subprocess.wait()
|
subprocess.wait()
|
||||||
if subprocess.returncode != 0:
|
if subprocess.returncode != 0:
|
||||||
logging.warning('CameraInit: Error on updateInternals of node "{}".'.format(node.name))
|
logging.warning('CameraInit: Error on buildIntrinsics of node "{}".'.format(node.name))
|
||||||
|
|
||||||
# Reload result of aliceVision_cameraInit
|
# Reload result of aliceVision_cameraInit
|
||||||
cameraInitSfM = localCmdVars['outputValue']
|
cameraInitSfM = localCmdVars['outputValue']
|
||||||
|
@ -187,27 +135,27 @@ class CameraInit(desc.CommandLineNode):
|
||||||
viewsKeys = [v.name for v in Viewpoint]
|
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", [])]
|
views = [{k: v for k, v in item.items() if k in viewsKeys} for item in data.get("views", [])]
|
||||||
# print('views:', views)
|
# print('views:', views)
|
||||||
|
return views, intrinsics
|
||||||
with GraphModification(node.graph):
|
|
||||||
node.viewpoints.value = views
|
|
||||||
node.intrinsics.value = intrinsics
|
|
||||||
node.attribute("_viewpointsUid").value = node.viewpoints.uid(1)
|
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.warning('CameraInit: Error on updateInternals of node "{}".'.format(node.name))
|
logging.warning('CameraInit: Error on buildIntrinsics of node "{}".'.format(node.name))
|
||||||
raise
|
raise
|
||||||
finally:
|
finally:
|
||||||
node._cmdVars = origCmdVars
|
node._cmdVars = origCmdVars
|
||||||
shutil.rmtree(tmpCache)
|
shutil.rmtree(tmpCache)
|
||||||
|
|
||||||
def createViewpointsFile(self, node):
|
def createViewpointsFile(self, node, additionalViews=()):
|
||||||
if node.viewpoints:
|
node.viewpointsFile = ""
|
||||||
|
if node.viewpoints or additionalViews:
|
||||||
|
newViews = []
|
||||||
|
for path in additionalViews: # format additional views to match json format
|
||||||
|
newViews.append({"path": path})
|
||||||
intrinsics = node.intrinsics.getPrimitiveValue(exportDefault=True)
|
intrinsics = node.intrinsics.getPrimitiveValue(exportDefault=True)
|
||||||
for intrinsic in intrinsics:
|
for intrinsic in intrinsics:
|
||||||
intrinsic['principalPoint'] = [intrinsic['principalPoint']['x'], intrinsic['principalPoint']['y']]
|
intrinsic['principalPoint'] = [intrinsic['principalPoint']['x'], intrinsic['principalPoint']['y']]
|
||||||
sfmData = {
|
sfmData = {
|
||||||
"version": [1, 0, 0],
|
"version": [1, 0, 0],
|
||||||
"views": node.viewpoints.getPrimitiveValue(exportDefault=False),
|
"views": node.viewpoints.getPrimitiveValue(exportDefault=False) + newViews,
|
||||||
"intrinsics": intrinsics,
|
"intrinsics": intrinsics,
|
||||||
"featureFolder": "",
|
"featureFolder": "",
|
||||||
"matchingFolder": "",
|
"matchingFolder": "",
|
||||||
|
@ -232,7 +180,7 @@ class CameraInit(desc.CommandLineNode):
|
||||||
|
|
||||||
def buildCommandLine(self, chunk):
|
def buildCommandLine(self, chunk):
|
||||||
cmd = desc.CommandLineNode.buildCommandLine(self, chunk)
|
cmd = desc.CommandLineNode.buildCommandLine(self, chunk)
|
||||||
if len(chunk.node.viewpoints):
|
if chunk.node.viewpointsFile:
|
||||||
cmd += ' --input ' + chunk.node.viewpointsFile
|
cmd += ' --input ' + chunk.node.viewpointsFile
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue