Guest User

Untitled

a guest
Apr 19th, 2018
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.64 KB | None | 0 0
  1. #!/usr/local/bin/python3
  2.  
  3. import json
  4. import click
  5.  
  6. original_json = """
  7. {"tracking_to_eye_transform": [
  8. {
  9. "distortion": {
  10. "center_x": 0.08929439470524059,
  11. "center_y": 0.00249327252794042,
  12. "coeffs": [
  13. -0.2241013860926538,
  14. -0.01584047880631451,
  15. -0.05288173768290632,
  16. 0.0,
  17. 0.0,
  18. 0.0,
  19. 0.0,
  20. 0.0
  21. ],
  22. "type": "DISTORT_DPOLY3"
  23. },
  24. "distortion_blue": {
  25. "center_x": 0.08929439470524059,
  26. "center_y": 0.00249327252794042,
  27. "coeffs": [
  28. -0.2738619166604556,
  29. 0.06673015735024002,
  30. -0.1001613564801299,
  31. 0.0,
  32. 0.0,
  33. 0.0,
  34. 0.0,
  35. 0.0
  36. ],
  37. "type": "DISTORT_DPOLY3"
  38. },
  39. "distortion_red": {
  40. "center_x": 0.08929439470524059,
  41. "center_y": 0.00249327252794042,
  42. "coeffs": [
  43. -0.1904432644159945,
  44. -0.06706698061328766,
  45. -0.02527639008136722,
  46. 0.0,
  47. 0.0,
  48. 0.0,
  49. 0.0,
  50. 0.0
  51. ],
  52. "type": "DISTORT_DPOLY3"
  53. },
  54. "extrinsics": [
  55. [
  56. 1.0,
  57. 0.0,
  58. 0.0,
  59. 0.03109734132885933
  60. ],
  61. [
  62. 0.0,
  63. 1.0,
  64. 0.0,
  65. -2.235174179077148e-08
  66. ],
  67. [
  68. 0.0,
  69. 0.0,
  70. 1.0,
  71. -7.450580596923828e-09
  72. ]
  73. ],
  74. "grow_for_undistort": 0.6000000238418579,
  75. "intrinsics": [
  76. [
  77. 1.175925925925926,
  78. 0.0,
  79. -0.08929439634084702
  80. ],
  81. [
  82. 0.0,
  83. 1.058333333333333,
  84. 0.002243945375084877
  85. ],
  86. [
  87. 0.0,
  88. 0.0,
  89. -1.0
  90. ]
  91. ],
  92. "undistort_r2_cutoff": 1.135009288787842
  93. },
  94. {
  95. "distortion": {
  96. "center_x": -0.09162746444351921,
  97. "center_y": -0.008225905729841963,
  98. "coeffs": [
  99. -0.2327160050831912,
  100. -0.003529502378183619,
  101. -0.05969732837118644,
  102. 0.0,
  103. 0.0,
  104. 0.0,
  105. 0.0,
  106. 0.0
  107. ],
  108. "type": "DISTORT_DPOLY3"
  109. },
  110. "distortion_blue": {
  111. "center_x": -0.09162746444351921,
  112. "center_y": -0.008225905729841963,
  113. "coeffs": [
  114. -0.2842724020525745,
  115. 0.08443503202657598,
  116. -0.1103613766404206,
  117. 0.0,
  118. 0.0,
  119. 0.0,
  120. 0.0,
  121. 0.0
  122. ],
  123. "type": "DISTORT_DPOLY3"
  124. },
  125. "distortion_red": {
  126. "center_x": -0.09162746444351921,
  127. "center_y": -0.008225905729841963,
  128. "coeffs": [
  129. -0.1982499310616191,
  130. -0.05629118550766949,
  131. -0.03117463416342108,
  132. 0.0,
  133. 0.0,
  134. 0.0,
  135. 0.0,
  136. 0.0
  137. ],
  138. "type": "DISTORT_DPOLY3"
  139. },
  140. "extrinsics": [
  141. [
  142. 1.0,
  143. 0.0,
  144. 0.0,
  145. -0.03109737858176231
  146. ],
  147. [
  148. 0.0,
  149. 1.0,
  150. 0.0,
  151. -2.235174179077148e-08
  152. ],
  153. [
  154. 0.0,
  155. 0.0,
  156. 1.0,
  157. -7.450580596923828e-09
  158. ]
  159. ],
  160. "grow_for_undistort": 0.6000000238418579,
  161. "intrinsics": [
  162. [
  163. 1.175925925925926,
  164. 0.0,
  165. 0.09162746369838715
  166. ],
  167. [
  168. 0.0,
  169. 1.058333333333333,
  170. -0.007403315044939518
  171. ],
  172. [
  173. 0.0,
  174. 0.0,
  175. -1.0
  176. ]
  177. ],
  178. "undistort_r2_cutoff": 1.127524495124817
  179. }
  180. ]}
  181. """
  182.  
  183. @click.group()
  184. def greet():
  185. pass
  186.  
  187.  
  188. @greet.command()
  189. @click.option('--d1', help='coeff 1 adjust', required=False)
  190. @click.option('--d2', help='coeff 2 adjust', required=False)
  191. @click.option('--d3', help='coeff 3 adjust', required=False)
  192. def query(**kwargs):
  193. original_json_dict = json.loads(original_json)
  194. if not kwargs['d1']:
  195. kwargs['d1'] = 0
  196. if not kwargs['d2']:
  197. kwargs['d2'] = 0
  198. if not kwargs['d3']:
  199. kwargs['d3'] = 0
  200.  
  201. print('original')
  202. for index in [0, 1]:
  203. eye = original_json_dict['tracking_to_eye_transform'][index]
  204. for dset in ['distortion', 'distortion_blue', 'distortion_red']:
  205. theset = eye[dset]['coeffs']
  206. print(theset)
  207.  
  208. print('modified')
  209. for index in [0, 1]:
  210. eye = original_json_dict['tracking_to_eye_transform'][index]
  211. for dset in ['distortion', 'distortion_blue', 'distortion_red']:
  212. theset = eye[dset]['coeffs']
  213. theset[0] = theset[0] + float(kwargs['d1'])
  214. theset[1] = theset[1] + float(kwargs['d2'])
  215. theset[2] = theset[2] + float(kwargs['d3'])
  216. print(theset)
  217. original_json_dict['tracking_to_eye_transform'][index][dset]['coeffs'] = theset
  218.  
  219. original_json_out = json.dumps(original_json_dict, indent=4)
  220.  
  221. with open('out.txt', 'w') as the_file:
  222. the_file.write(original_json_out)
  223.  
  224. if __name__ == '__main__':
  225. greet()
Advertisement
Add Comment
Please, Sign In to add comment