| 109 | |
| 110 | |
| 111 | def vis_3d_skeleton(kpt_3d, kpt_3d_vis, kps_lines, filename=None): |
| 112 | |
| 113 | fig = plt.figure() |
| 114 | ax = fig.add_subplot(111, projection='3d') |
| 115 | |
| 116 | # Convert from plt 0-1 RGBA colors to 0-255 BGR colors for opencv. |
| 117 | cmap = plt.get_cmap('rainbow') |
| 118 | colors = [cmap(i) for i in np.linspace(0, 1, len(kps_lines) + 2)] |
| 119 | colors = [np.array((c[2], c[1], c[0])) for c in colors] |
| 120 | |
| 121 | for l in range(len(kps_lines)): |
| 122 | i1 = kps_lines[l][0] |
| 123 | i2 = kps_lines[l][1] |
| 124 | x = np.array([kpt_3d[i1, 0], kpt_3d[i2, 0]]) |
| 125 | y = np.array([kpt_3d[i1, 1], kpt_3d[i2, 1]]) |
| 126 | z = np.array([kpt_3d[i1, 2], kpt_3d[i2, 2]]) |
| 127 | |
| 128 | if kpt_3d_vis[i1, 0] > 0 and kpt_3d_vis[i2, 0] > 0: |
| 129 | ax.plot(x, z, -y, c=colors[l], linewidth=2) |
| 130 | if kpt_3d_vis[i1, 0] > 0: |
| 131 | ax.scatter(kpt_3d[i1, 0], |
| 132 | kpt_3d[i1, 2], |
| 133 | -kpt_3d[i1, 1], |
| 134 | c=colors[l], |
| 135 | marker='o') |
| 136 | if kpt_3d_vis[i2, 0] > 0: |
| 137 | ax.scatter(kpt_3d[i2, 0], |
| 138 | kpt_3d[i2, 2], |
| 139 | -kpt_3d[i2, 1], |
| 140 | c=colors[l], |
| 141 | marker='o') |
| 142 | |
| 143 | x_r = np.array([0, cfg.input_shape[1]], dtype=np.float32) |
| 144 | y_r = np.array([0, cfg.input_shape[0]], dtype=np.float32) |
| 145 | z_r = np.array([0, 1], dtype=np.float32) |
| 146 | |
| 147 | if filename is None: |
| 148 | ax.set_title('3D vis') |
| 149 | else: |
| 150 | ax.set_title(filename) |
| 151 | |
| 152 | ax.set_xlabel('X Label') |
| 153 | ax.set_ylabel('Z Label') |
| 154 | ax.set_zlabel('Y Label') |
| 155 | ax.legend() |
| 156 | |
| 157 | plt.show() |
| 158 | cv2.waitKey(0) |
| 159 | |
| 160 | |
| 161 | def save_obj(v, f, file_name='output.obj'): |