Skip to content

Commit

Permalink
Merge pull request raulmur#3 from monoDriveIO/generate_params
Browse files Browse the repository at this point in the history
helper script to generate orbslam2 params from camera info
  • Loading branch information
devinaconley committed Jul 20, 2019
2 parents 9d9cbc0 + d489ea6 commit 40d5e8d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ RUN wget http://bitbucket.org/eigen/eigen/get/3.3.7.tar.gz
RUN tar -xzf 3.3.7.tar.gz
RUN mv eigen-eigen-323c052e1731 /usr/local/include/eigen

# python
RUN apt-get install -y python3-pip
RUN pip3 install PyYAML

# orb-slam2
COPY Thirdparty ${BASE_DIR}/orbslam2/Thirdparty
COPY Vocabulary ${BASE_DIR}/orbslam2/Vocabulary
Expand Down
51 changes: 51 additions & 0 deletions python/generate_params_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""
helper script to generate params file from template and camera config
"""

# lib
import json
import yaml
import argparse
import math


def main():
args = parse_arguments()

# load camera config and template
with open(args['camera']) as file:
camera_config = json.load(file)
with open(args['template']) as file:
template_params = yaml.safe_load(file)

# calculate new params
params = template_params.copy()
params['Camera.cx'] = camera_config['stream_dimensions']['x'] / 2.0
params['Camera.cy'] = camera_config['stream_dimensions']['y'] / 2.0
params['Camera.fx'] = (
camera_config['stream_dimensions']['x']
/ (2.0 * math.tan(math.radians(0.5 * camera_config['fov'])))
)
params['Camera.fy'] = params['Camera.fx']

# write update params to output file
with open(args['output'], 'w') as file:
yaml.dump(params, file)


def parse_arguments():
"""
helper function to parse CLI args
:return:
"""
parser = argparse.ArgumentParser()
parser.add_argument('--camera', '-c', help='path to camera config.json', required=True)
parser.add_argument('--template', '-t', help='path to template parameters', required=True)
parser.add_argument('--output', '-o', help='path to generated params file', required=True)

return vars(parser.parse_args())


if __name__ == '__main__':
main()

0 comments on commit 40d5e8d

Please sign in to comment.