Skip to content

Commit

Permalink
script: MvgMvsPipeline.py improvement (cdcseacave#529)
Browse files Browse the repository at this point in the history
- add script directory to PATH in order to launch it from another location
  • Loading branch information
FlachyJoe authored Feb 17, 2020
1 parent 8603471 commit 8875b38
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions MvgMvsPipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@

DEBUG = False

# add current directory to PATH
if sys.platform.startswith('win'):
path_delim = ';'
PATH_DELIM = ';'
else:
path_delim = ':'
os.environ['PATH'] += path_delim + os.getcwd()
PATH_DELIM = ':'

# add this script's directory to PATH
os.environ['PATH'] += PATH_DELIM + os.path.dirname(os.path.abspath(__file__))

# add current directory to PATH
os.environ['PATH'] += PATH_DELIM + os.getcwd()


def whereis(afile):
Expand All @@ -81,15 +85,17 @@ def whereis(afile):
except subprocess.CalledProcessError:
return None


def find(afile):
"""
As whereis look only for executable on linux, this find look for all file type
"""
for d in os.environ['PATH'].split(path_delim):
for d in os.environ['PATH'].split(PATH_DELIM):
if os.path.isfile(os.path.join(d, afile)):
return d
return None


# Try to find openMVG and openMVS binaries in PATH
OPENMVG_BIN = whereis("openMVG_main_SfMInit_ImageListing")
OPENMVS_BIN = whereis("ReconstructMesh")
Expand All @@ -115,11 +121,11 @@ def find(afile):

PRESET_DEFAULT = 'SEQUENTIAL'


# HELPERS for terminal colors
BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8)
NO_EFFECT, BOLD, UNDERLINE, BLINK, INVERSE, HIDDEN = (0, 1, 4, 5, 7, 8)


# from Python cookbook, #475186
def has_colours(stream):
'''
Expand Down Expand Up @@ -161,13 +167,15 @@ def __init__(self):


class AStep:
""" Represents a process step to be run """
def __init__(self, info, cmd, opt):
self.info = info
self.cmd = cmd
self.opt = opt


class StepsStore:
""" List of steps with facilities to configure them """
def __init__(self):
self.steps_data = [
["Intrinsics analysis", # 0
Expand Down Expand Up @@ -245,29 +253,30 @@ def apply_conf(self, conf):
STEPS = StepsStore()

# ARGS
parser = argparse.ArgumentParser(
PARSER = argparse.ArgumentParser(
formatter_class=argparse.RawTextHelpFormatter,
description="Photogrammetry reconstruction with these steps: \r\n" +
"\r\n".join(("\t%i. %s\t %s" % (t, STEPS[t].info, STEPS[t].cmd) for t in range(STEPS.length())))
)
parser.add_argument('input_dir',
PARSER.add_argument('input_dir',
help="the directory wich contains the pictures set.")
parser.add_argument('output_dir',
PARSER.add_argument('output_dir',
help="the directory wich will contain the resulting files.")
parser.add_argument('--steps',
PARSER.add_argument('--steps',
type=int,
nargs="+",
help="steps to process")
parser.add_argument('--preset',
PARSER.add_argument('--preset',
help="steps list preset in \r\n" +
" \r\n".join([k + " = " + str(PRESET[k]) for k in PRESET]) +
" \r\ndefault : " + PRESET_DEFAULT)

group = parser.add_argument_group('Passthrough', description="Option to be passed to command lines (remove - in front of option names)\r\ne.g. --1 p ULTRA to use the ULTRA preset in openMVG_main_ComputeFeatures")
GROUP = PARSER.add_argument_group('Passthrough', description="Option to be passed to command lines (remove - in front of option names)\r\ne.g. --1 p ULTRA to use the ULTRA preset in openMVG_main_ComputeFeatures")
for n in range(STEPS.length()):
group.add_argument('--'+str(n), nargs='+')
GROUP.add_argument('--'+str(n), nargs='+')

PARSER.parse_args(namespace=CONF) # store args in the ConfContainer

parser.parse_args(namespace=CONF) # store args in the ConfContainer

# FOLDERS

Expand All @@ -276,6 +285,7 @@ def mkdir_ine(dirname):
if not os.path.exists(dirname):
os.mkdir(dirname)


# Absolute path for input and ouput dirs
CONF.input_dir = os.path.abspath(CONF.input_dir)
CONF.output_dir = os.path.abspath(CONF.output_dir)
Expand Down

0 comments on commit 8875b38

Please sign in to comment.