[ui] Reconstruction: the active sfm node can be a StructureFromMotion or a PanoramaEstimation node

This commit is contained in:
Fabien Castan 2020-06-25 01:10:25 +02:00
parent 9e03f67c9b
commit 49c03bc239
2 changed files with 32 additions and 30 deletions

View file

@ -356,6 +356,32 @@ class ViewpointWrapper(QObject):
return QUrl.fromLocalFile(self._undistortedImagePath)
def parseSfMJsonFile(sfmJsonFile):
"""
Parse the SfM Json file and return views, poses and intrinsics as three dicts with viewId, poseId and intrinsicId as keys.
"""
if not os.path.exists(sfmJsonFile):
return {}, {}, {}
with open(sfmJsonFile) as jsonFile:
report = json.load(jsonFile)
views = dict()
poses = dict()
intrinsics = dict()
for view in report['views']:
views[view['viewId']] = view
for pose in report['poses']:
poses[pose['poseId']] = pose['pose']
for intrinsic in report['intrinsics']:
intrinsics[intrinsic['intrinsicId']] = intrinsic
return views, poses, intrinsics
class Reconstruction(UIGraph):
"""
Specialization of a UIGraph designed to manage a 3D reconstruction.
@ -504,6 +530,9 @@ class Reconstruction(UIGraph):
self.setSfm(self.lastSfmNode())
if not self.sfm:
self.sfm = self.lastNodeOfType("PanoramaEstimation", self._cameraInit, Status.SUCCESS)
# TODO: listen specifically for cameraInit creation/deletion
self._graph.nodes.countChanged.connect(self.updateCameraInits)
@ -763,7 +792,7 @@ class Reconstruction(UIGraph):
recursive: List files in folders recursively.
"""
logging.warning("importImagesFromFolder: " + str(path))
logging.debug("importImagesFromFolder: " + str(path))
filesByType = multiview.findFilesByTypeInFolder(path, recursive)
if filesByType.images:
self.buildIntrinsics(self.cameraInit, filesByType.images)
@ -910,7 +939,7 @@ class Reconstruction(UIGraph):
@Slot(QObject)
def setActiveNodeOfType(self, node):
""" Set node as the active node of its type. """
if node.nodeType == "StructureFromMotion":
if node.nodeType == "StructureFromMotion" or node.nodeType == "PanoramaEstimation":
self.sfm = node
elif node.nodeType == "FeatureExtraction":
self.featureExtraction = node
@ -936,7 +965,7 @@ class Reconstruction(UIGraph):
self._poses = dict()
self._solvedIntrinsics = dict()
else:
self._views, self._poses, self._solvedIntrinsics = self._sfm.nodeDesc.getResults(self._sfm)
self._views, self._poses, self._solvedIntrinsics = parseSfMJsonFile(self._sfm.outputViewsAndPoses.value)
self.sfmReportChanged.emit()
def getSfm(self):