-
Notifications
You must be signed in to change notification settings - Fork 1
/
DFMImageTree.py
71 lines (54 loc) · 2.2 KB
/
DFMImageTree.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# instructions for creating new nodes: https://github.com/natowi/meshroom_external_plugins/wiki/2-DevDoc
# has to be exported to pyc file, then placed into /lib/meshroom/nodes/aliceVision
# from meshroom.core import desc
import json
from meshroom.core import desc
# command line node, calls another program through the command line
class DFMImageTree(desc.Node):
inputs = [
desc.File(
name="sfmData",
label="SfMData",
description="SFM data file.",
value=desc.Node.internalFolder,
uid=[0],
),
]
outputs = [
desc.File(
name="ImagePairs",
label="Image Pairs",
description="Path to a file which contains the list of image pairs to match.",
value=desc.Node.internalFolder + "imageMatches.txt",
uid=[0],
)
]
def create_image_pairs(self, imagePairsFile, sfmFile, chunk):
"""
Loads imagePairsFile and creates an array of image pairs to run dfm on.
"""
chunk.logger.info(f"sfm File: {sfmFile}")
with open(sfmFile, 'r', encoding='utf-8', errors='ignore') as f:
sfmData = json.load(f)
imageIds = []
chunk.logger.info('this is an info log2')
chunk.logger.info(f" created the following imageIds: {imageIds}")
for imageData in sfmData["views"]:
imageIds.append(imageData["viewId"])
chunk.logger.info(f" created the following imageIds: {imageIds}")
with open(imagePairsFile, 'w', encoding='utf-8', errors='ignore') as f:
for idx, imageId in enumerate(imageIds):
line = ' '.join(imageIds[idx:])
f.write(line)
f.write('\n')
def processChunk(self, chunk):
try:
chunk.logManager.start('debug')
chunk.logger.info('this is an info log')
self.create_image_pairs(chunk.node.ImagePairs.value, chunk.node.sfmData.value, chunk)
except Exception as e:
chunk.logger.error(e)
raise RuntimeError()
finally:
# required to unlock log file so that it can be deleted if required
chunk.logManager.end()