diff --git a/meshroom/nodes/aliceVision/StructureFromMotion.py b/meshroom/nodes/aliceVision/StructureFromMotion.py index 22bcc863..a3724d69 100644 --- a/meshroom/nodes/aliceVision/StructureFromMotion.py +++ b/meshroom/nodes/aliceVision/StructureFromMotion.py @@ -347,30 +347,3 @@ It iterates like that, adding cameras and triangulating new 2D features into 3D uid=[], ), ] - - @staticmethod - def getResults(node): - """ - Parse SfM result and return views, poses and intrinsics as three dicts with viewId, poseId and intrinsicId as keys. - """ - reportFile = node.outputViewsAndPoses.value - if not os.path.exists(reportFile): - return {}, {}, {} - - with open(reportFile) 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 diff --git a/meshroom/ui/reconstruction.py b/meshroom/ui/reconstruction.py index ff37150f..8b9391f3 100755 --- a/meshroom/ui/reconstruction.py +++ b/meshroom/ui/reconstruction.py @@ -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):