|
| 1 | +import json |
| 2 | +import numpy as np |
| 3 | +from mpl_toolkits.mplot3d import Axes3D |
| 4 | +import matplotlib.pyplot as plt |
| 5 | +import matplotlib as mpl |
| 6 | + |
| 7 | +# load camera positions |
| 8 | +campos_dict = {} |
| 9 | +for subset in ('all', 'machine_annot', 'human_annot'): |
| 10 | + for split in ('train', 'test', 'val'): |
| 11 | + |
| 12 | + if split == 'val' and subset != 'machine_annot': |
| 13 | + continue |
| 14 | + |
| 15 | + with open('../../data/InterHand2.6M/data/annotations/' + subset + '/InterHand2.6M_' + split + '_camera.json') as f: |
| 16 | + cameras = json.load(f) |
| 17 | + for capture_id in cameras.keys(): |
| 18 | + for cam_id in cameras[capture_id]['campos'].keys(): |
| 19 | + campos = np.array(cameras[capture_id]['campos'][cam_id], dtype=np.float32) |
| 20 | + |
| 21 | + # exact camera positions can be slightly different for each 'capture_id'. |
| 22 | + # however, just overwrite them for the visualization purpose. |
| 23 | + if cam_id not in campos_dict: |
| 24 | + campos_dict[cam_id] = campos |
| 25 | + |
| 26 | +# plot camera positions |
| 27 | +fig = plt.figure() |
| 28 | +ax = fig.add_subplot(111, projection='3d') |
| 29 | + |
| 30 | +# Convert from plt 0-1 RGBA colors to 0-255 BGR colors for opencv. |
| 31 | +cmap = plt.get_cmap('rainbow') |
| 32 | +cam_num = len(campos_dict) |
| 33 | +colors = [cmap(i) for i in np.linspace(0, 1, cam_num)] |
| 34 | +colors = [np.array((c[2], c[1], c[0])) for c in colors] |
| 35 | + |
| 36 | +for i, k in enumerate(campos_dict.keys()): |
| 37 | + ax.scatter(campos_dict[k][0], campos_dict[k][2], -campos_dict[k][1], c=colors[i], marker='o') |
| 38 | + ax.text(campos_dict[k][0], campos_dict[k][2], -campos_dict[k][1], k) |
| 39 | + |
| 40 | +ax.set_xticklabels([]) |
| 41 | +ax.set_yticklabels([]) |
| 42 | +ax.set_zticklabels([]) |
| 43 | +plt.show() |
| 44 | + |
0 commit comments