【问题标题】:Extract matrix from jSon file从json文件中提取矩阵
【发布时间】:2019-10-13 08:26:38
【问题描述】:

我使用 fSpy 软件:开源静止图像相机匹配 将结果与 Rhino 3d 一起使用,我导出到具有相机位置矩阵的 jSon 文件 我需要使用 Pythonrows 提取到数字列表中 感谢您的帮助

从此:

  "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
      ]
    ]
  }

到:

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

【问题讨论】:

  • 您使用的是 C# 还是 Python?为什么这两个都被标记了?
  • c# 在 Grasshopper 中使用 python (Ghpython)

标签: c# python json matrix rhinoceros


【解决方案1】:

你可以在将json转成python格式后试试这个:

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)

输出:

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

【讨论】:

  • 非常感谢彼得;这非常有帮助,我希望看到其他解决方案从 json 文件中提取相机变换行
  • @seghier 我不知道你的json格式,但是你可以访问https://docs.python.org/3/library/json.html了解如何在python中处理json
猜你喜欢
  • 2021-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-01
  • 1970-01-01
相关资源
最近更新 更多