0

i use fSpy software : Open source still image camera matching to use the result with Rhino 3d i export to jSon file which have matrix of the camera position i need to extract the rows to a list of numbers with Python Thanks for help

enter image description here

from this :

  "cameraTransform": {
    "rows": [
      [
        -0.7469096503244566,
        -0.0048362499036055774,
        -0.6649079522302825,
        -6.756347957309588
      ],
      [
        -0.6649255299159078,
        0.005255128514812499,
        0.7468911723205343,
        7.333944516331069
      ],
      [
        -0.00011797562067967932,
        0.9999744968303753,
        -0.007140852231397498,
        -4.200072574252649
      ],
      [
        0,
        0,
        0,
        1
      ]
    ]
  }

to :

0   -0.7469096503244566
1   -0.0048362499036055774
2   -0.6649079522302825
3   -6.756347957309588
4   -0.6649255299159078
5    0.005255128514812499
6   0.7468911723205343
7   7.333944516331069
8   -0.00011797562067967932
9   0.9999744968303753
10   -0.007140852231397498
11   -4.200072574252649
12   0
13   0
14   0
15   1
seghier
  • 167
  • 1
  • 2
  • 11

1 Answers1

1

You can try this after convert json to python format:

cameraTransform= {
        "rows": [
          [
            -0.7469096503244566,
            -0.0048362499036055774,
            -0.6649079522302825,
            -6.756347957309588
          ],
          [
            -0.6649255299159078,
            0.005255128514812499,
            0.7468911723205343,
            7.333944516331069
          ],
          [
            -0.00011797562067967932,
            0.9999744968303753,
            -0.007140852231397498,
            -4.200072574252649
          ],
          [
            0,
            0,
            0,
            1
          ]
        ]
      }

from itertools import chain
for idx, value in enumerate(chain(*cameraTransform['rows'])):
    print(idx, value)

Output:

0 -0.7469096503244566
1 -0.0048362499036055774
2 -0.6649079522302825
3 -6.756347957309588
4 -0.6649255299159078
5 0.005255128514812499
6 0.7468911723205343
7 7.333944516331069
8 -0.00011797562067967932
9 0.9999744968303753
10 -0.007140852231397498
11 -4.200072574252649
12 0
13 0
14 0
15 1
Peter
  • 120
  • 1
  • 8
  • Thank you very much Peter; this is very helpful and i hope see other solutions to extract the rows of camera transform from json file – seghier Oct 13 '19 at 08:47
  • 1
    @seghier I don't know your format json, but you can visit `https://docs.python.org/3/library/json.html` to know how to handle json in python – Peter Oct 13 '19 at 09:24