-
Notifications
You must be signed in to change notification settings - Fork 5
/
convert.py
executable file
·60 lines (55 loc) · 1.83 KB
/
convert.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
#!/usr/bin/python
##
# Author: Adam King
# Github: github.com/awkbr549
# Converts the VisualSFM .nvm file type into the OpenSFM .json typ
#
# Some code taken from Caleb Adams' (github.com/piepieninja) original code
#
import sys
import os.path
#argument bool list goes here
#argArray[0] is verbose
from arguments import *
argArray = parseArguments()
inputFile = ""
outputFile = ""
while True:
inputFile = raw_input("What file would you like to read from?\n--> ")
if (not inputFile.endswith(".nvm")):
print "ERROR: Import file type not supported."
elif (not os.path.isfile(inputFile)):
print "ERROR: File does not exist."
else: break
while True:
outputFile = raw_input("What file would you like to write to?\n--> ")
if (not outputFile.endswith(".json")):
print "ERROR: Export file type not supported."
elif (os.path.isfile(outputFile)):
answer = raw_input("WARNING: File already exists. Would you like to overwrite (yes/no)? ")
if (answer == "yes"):
break
else:
break
#Converting from NVM to something else
if inputFile.endswith(".nvm"):
from readNvm import *
nvmObj = readNvm(inputFile)
if argArray[0]: #verbose
from verbose import doNvmVerbose
doNvmVerbose(inputFile, nvmObj)
if outputFile.endswith(".json"):
print "Converting to JSON for OpenSfM requires extra data that cannot be extracted from " + inputFile[inputFile.find('.'):] + " files."
while True:
cameraModelFile = raw_input("Please input the location of the `camera_models.json' file:\n--> ")
if (not os.path.isfile(cameraModelFile)):
print "ERROR: File does not exist."
elif (not cameraModelFile.endswith("camera_models.json")):
print "ERROR: Incorrect file."
else:
break
from nvmToJson import *
jsonObj = convertNvmToJson(outputFile, cameraModelFile, nvmObj)
if argArray[0]: #verbose
from verbose import doJsonVerbose
doJsonVerbose(outputFile, jsonObj)