Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/python3
- import json
- import click
- original_json = """
- {"tracking_to_eye_transform": [
- {
- "distortion": {
- "center_x": 0.08929439470524059,
- "center_y": 0.00249327252794042,
- "coeffs": [
- -0.2241013860926538,
- -0.01584047880631451,
- -0.05288173768290632,
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0
- ],
- "type": "DISTORT_DPOLY3"
- },
- "distortion_blue": {
- "center_x": 0.08929439470524059,
- "center_y": 0.00249327252794042,
- "coeffs": [
- -0.2738619166604556,
- 0.06673015735024002,
- -0.1001613564801299,
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0
- ],
- "type": "DISTORT_DPOLY3"
- },
- "distortion_red": {
- "center_x": 0.08929439470524059,
- "center_y": 0.00249327252794042,
- "coeffs": [
- -0.1904432644159945,
- -0.06706698061328766,
- -0.02527639008136722,
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0
- ],
- "type": "DISTORT_DPOLY3"
- },
- "extrinsics": [
- [
- 1.0,
- 0.0,
- 0.0,
- 0.03109734132885933
- ],
- [
- 0.0,
- 1.0,
- 0.0,
- -2.235174179077148e-08
- ],
- [
- 0.0,
- 0.0,
- 1.0,
- -7.450580596923828e-09
- ]
- ],
- "grow_for_undistort": 0.6000000238418579,
- "intrinsics": [
- [
- 1.175925925925926,
- 0.0,
- -0.08929439634084702
- ],
- [
- 0.0,
- 1.058333333333333,
- 0.002243945375084877
- ],
- [
- 0.0,
- 0.0,
- -1.0
- ]
- ],
- "undistort_r2_cutoff": 1.135009288787842
- },
- {
- "distortion": {
- "center_x": -0.09162746444351921,
- "center_y": -0.008225905729841963,
- "coeffs": [
- -0.2327160050831912,
- -0.003529502378183619,
- -0.05969732837118644,
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0
- ],
- "type": "DISTORT_DPOLY3"
- },
- "distortion_blue": {
- "center_x": -0.09162746444351921,
- "center_y": -0.008225905729841963,
- "coeffs": [
- -0.2842724020525745,
- 0.08443503202657598,
- -0.1103613766404206,
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0
- ],
- "type": "DISTORT_DPOLY3"
- },
- "distortion_red": {
- "center_x": -0.09162746444351921,
- "center_y": -0.008225905729841963,
- "coeffs": [
- -0.1982499310616191,
- -0.05629118550766949,
- -0.03117463416342108,
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0
- ],
- "type": "DISTORT_DPOLY3"
- },
- "extrinsics": [
- [
- 1.0,
- 0.0,
- 0.0,
- -0.03109737858176231
- ],
- [
- 0.0,
- 1.0,
- 0.0,
- -2.235174179077148e-08
- ],
- [
- 0.0,
- 0.0,
- 1.0,
- -7.450580596923828e-09
- ]
- ],
- "grow_for_undistort": 0.6000000238418579,
- "intrinsics": [
- [
- 1.175925925925926,
- 0.0,
- 0.09162746369838715
- ],
- [
- 0.0,
- 1.058333333333333,
- -0.007403315044939518
- ],
- [
- 0.0,
- 0.0,
- -1.0
- ]
- ],
- "undistort_r2_cutoff": 1.127524495124817
- }
- ]}
- """
- @click.group()
- def greet():
- pass
- @greet.command()
- @click.option('--d1', help='coeff 1 adjust', required=False)
- @click.option('--d2', help='coeff 2 adjust', required=False)
- @click.option('--d3', help='coeff 3 adjust', required=False)
- def query(**kwargs):
- original_json_dict = json.loads(original_json)
- if not kwargs['d1']:
- kwargs['d1'] = 0
- if not kwargs['d2']:
- kwargs['d2'] = 0
- if not kwargs['d3']:
- kwargs['d3'] = 0
- print('original')
- for index in [0, 1]:
- eye = original_json_dict['tracking_to_eye_transform'][index]
- for dset in ['distortion', 'distortion_blue', 'distortion_red']:
- theset = eye[dset]['coeffs']
- print(theset)
- print('modified')
- for index in [0, 1]:
- eye = original_json_dict['tracking_to_eye_transform'][index]
- for dset in ['distortion', 'distortion_blue', 'distortion_red']:
- theset = eye[dset]['coeffs']
- theset[0] = theset[0] + float(kwargs['d1'])
- theset[1] = theset[1] + float(kwargs['d2'])
- theset[2] = theset[2] + float(kwargs['d3'])
- print(theset)
- original_json_dict['tracking_to_eye_transform'][index][dset]['coeffs'] = theset
- original_json_out = json.dumps(original_json_dict, indent=4)
- with open('out.txt', 'w') as the_file:
- the_file.write(original_json_out)
- if __name__ == '__main__':
- greet()
Advertisement
Add Comment
Please, Sign In to add comment