forked from raulmur/ORB_SLAM2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request raulmur#3 from monoDriveIO/generate_params
helper script to generate orbslam2 params from camera info
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |